Skip to content

Commit 9b62d6a

Browse files
committed
CORS-4230: Add SkipFirewallRuleCreation
api: Add API changes to SkipFirewallRuleCreation. When true, the firewall rules will not be created. When this is the case, the firewall rules should exist prior to creating the network. This will allow ServiceAccounts to skip the rules: compute.firewalls.create cloud: Update the services and interfaces. The firewall service will no longer create firewall rules when the skip firewall rule creation is enabled OR when it is a shared vpc.
1 parent 5e0eb53 commit 9b62d6a

10 files changed

+44
-2
lines changed

api/v1beta1/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ type NetworkSpec struct {
137137
// +optional
138138
HostProject *string `json:"hostProject,omitempty"`
139139

140+
// SkipFirewallRuleCreation should be set to true when no firewall rules should be
141+
// created by the provider.
142+
SkipFirewallRuleCreation *bool `json:"skipFirewallRuleCreation,omitempty"`
143+
140144
// Mtu: Maximum Transmission Unit in bytes. The minimum value for this field is
141145
// 1300 and the maximum value is 8896. The suggested value is 1500, which is
142146
// the default MTU used on the Internet, or 8896 if you want to use Jumbo

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type ClusterGetter interface {
5858
NetworkName() string
5959
NetworkProject() string
6060
IsSharedVpc() bool
61+
SkipFirewallRuleCreation() bool
6162
Network() *infrav1.Network
6263
AdditionalLabels() infrav1.Labels
6364
FailureDomains() clusterv1.FailureDomains

cloud/scope/cluster.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ func (s *ClusterScope) NetworkProject() string {
106106
return ptr.Deref(s.GCPCluster.Spec.Network.HostProject, s.Project())
107107
}
108108

109+
// SkipFirewallRuleCreation returns whether the spec indicates that firewall rules
110+
// should be created or not.
111+
func (s *ClusterScope) SkipFirewallRuleCreation() bool {
112+
return ptr.Deref(s.GCPCluster.Spec.Network.SkipFirewallRuleCreation, false) || s.IsSharedVpc()
113+
}
114+
109115
// IsSharedVpc returns true If sharedVPC used else , returns false.
110116
func (s *ClusterScope) IsSharedVpc() bool {
111117
return s.NetworkProject() != s.Project()

cloud/scope/managedcluster.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ func (s *ManagedClusterScope) NetworkProject() string {
129129
return ptr.Deref(s.GCPManagedCluster.Spec.Network.HostProject, s.Project())
130130
}
131131

132+
// SkipFirewallRuleCreation returns whether the spec indicates that firewall rules
133+
// should be created or not.
134+
func (s *ManagedClusterScope) SkipFirewallRuleCreation() bool {
135+
return ptr.Deref(s.GCPManagedCluster.Spec.Network.SkipFirewallRuleCreation, false) || s.IsSharedVpc()
136+
}
137+
132138
// IsSharedVpc returns true If sharedVPC used else , returns false.
133139
func (s *ManagedClusterScope) IsSharedVpc() bool {
134140
return s.NetworkProject() != s.Project()

cloud/services/compute/firewalls/reconcile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
// Reconcile reconcile cluster firewall compoenents.
2929
func (s *Service) Reconcile(ctx context.Context) error {
3030
log := log.FromContext(ctx)
31-
if s.scope.IsSharedVpc() {
32-
log.V(2).Info("Shared VPC enabled. Ignore Reconciling firewall resources")
31+
if s.scope.SkipFirewallRuleCreation() {
32+
log.V(2).Info("Ignore Reconciling firewall resources")
3333
return nil
3434
}
3535
log.Info("Reconciling firewall resources")

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpclusters.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ spec:
203203
name:
204204
description: Name is the name of the network to be used.
205205
type: string
206+
skipFirewallRuleCreation:
207+
description: |-
208+
SkipFirewallRuleCreation should be set to true when no firewall rules should be
209+
created by the provider.
210+
type: boolean
206211
subnets:
207212
description: Subnets configuration.
208213
items:

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpclustertemplates.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ spec:
222222
name:
223223
description: Name is the name of the network to be used.
224224
type: string
225+
skipFirewallRuleCreation:
226+
description: |-
227+
SkipFirewallRuleCreation should be set to true when no firewall rules should be
228+
created by the provider.
229+
type: boolean
225230
subnets:
226231
description: Subnets configuration.
227232
items:

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedclusters.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ spec:
199199
name:
200200
description: Name is the name of the network to be used.
201201
type: string
202+
skipFirewallRuleCreation:
203+
description: |-
204+
SkipFirewallRuleCreation should be set to true when no firewall rules should be
205+
created by the provider.
206+
type: boolean
202207
subnets:
203208
description: Subnets configuration.
204209
items:

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedclustertemplates.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ spec:
193193
name:
194194
description: Name is the name of the network to be used.
195195
type: string
196+
skipFirewallRuleCreation:
197+
description: |-
198+
SkipFirewallRuleCreation should be set to true when no firewall rules should be
199+
created by the provider.
200+
type: boolean
196201
subnets:
197202
description: Subnets configuration.
198203
items:

0 commit comments

Comments
 (0)