Skip to content

Commit ec4511c

Browse files
authored
PLT-1330 CMEK, SA & CIDRs (#36)
1 parent 2ae2d8b commit ec4511c

10 files changed

+243
-2
lines changed

CHANGELOG.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
## 1.6.1-0.3.0 (upcoming)
44

5-
* [PLT-327] After creating a GKE cluster, it takes ~20 minutes for its status to be READY
6-
* [PLT-911] Disable external endpoint
5+
* [PLT-1330] CMEK - Service accounts & Secondary CIDR ranges adaption to R4.7
76

87
## Previous development
98

9+
## 1.6.1-0.2.1 (2024-12-05)
10+
11+
* [PLT-1313] Support Secondary CIDR ranges
12+
* [PLT-1246] CMEK Support
13+
1014
## 1.6.1-0.2.0 (2024-10-11)
1115

16+
* [PLT-965] Disable managed Monitoring and Logging
1217
* [PLT-806] Add GKE Private cluster support
1318
* [PLT-563] Fix autoscaling issues
1419
* [PLT-326] First approach to manage taints addition, update and deletion on GKE
20+
* [PLT-327] After creating a GKE cluster, it takes ~20 minutes for its status to be READY
21+
* [PLT-911] Disable external endpoint
1522

1623
### Branched to branch-1.6.1-0.1 (2024-08-22)
1724

cloud/scope/managedmachinepool.go

+6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ func ConvertToSdkNodePool(nodePool infrav1exp.GCPManagedMachinePool, machinePool
218218
if nodePool.Spec.LinuxNodeConfig != nil {
219219
sdkNodePool.Config.LinuxNodeConfig = infrav1exp.ConvertToSdkLinuxNodeConfig(nodePool.Spec.LinuxNodeConfig)
220220
}
221+
if nodePool.Spec.BootDiskKmsKey != "" {
222+
sdkNodePool.Config.BootDiskKmsKey = nodePool.Spec.BootDiskKmsKey
223+
}
221224
if nodePool.Spec.Management != nil {
222225
sdkNodePool.Management = &containerpb.NodeManagement{
223226
AutoRepair: nodePool.Spec.Management.AutoRepair,
@@ -241,6 +244,9 @@ func ConvertToSdkNodePool(nodePool infrav1exp.GCPManagedMachinePool, machinePool
241244
if nodePool.Spec.DiskSizeGB != nil {
242245
sdkNodePool.Config.DiskSizeGb = int32(*nodePool.Spec.DiskSizeGB)
243246
}
247+
if nodePool.Spec.BootDiskKmsKey != "" {
248+
sdkNodePool.Config.BootDiskKmsKey = nodePool.Spec.BootDiskKmsKey
249+
}
244250
if len(nodePool.Spec.NodeNetwork.Tags) != 0 {
245251
sdkNodePool.Config.Tags = nodePool.Spec.NodeNetwork.Tags
246252
}

cloud/services/container/clusters/reconcile.go

+9
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error {
300300
}
301301
}
302302

303+
// Add IPAllocationPolicy for CIDR support
304+
if s.scope.GCPManagedControlPlane.Spec.ClusterIpv4Cidr != nil {
305+
cluster.ClusterIpv4Cidr = *s.scope.GCPManagedControlPlane.Spec.ClusterIpv4Cidr
306+
}
307+
308+
if s.scope.GCPManagedControlPlane.Spec.IPAllocationPolicy != nil {
309+
cluster.IpAllocationPolicy = infrav1exp.ConvertToSdkIPAllocationPolicy(s.scope.GCPManagedControlPlane.Spec.IPAllocationPolicy)
310+
}
311+
303312
// If the cluster is autopilot, we don't need to specify node pools.
304313
if !s.scope.IsAutopilotCluster() {
305314
cluster.NodePools = scope.ConvertToSdkNodePools(nodePools, machinePools, isRegional, cluster.Name)

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

+44
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ spec:
6262
spec:
6363
description: GCPManagedControlPlaneSpec defines the desired state of GCPManagedControlPlane.
6464
properties:
65+
clusterIpv4Cidr:
66+
description: |-
67+
ClusterIpv4Cidr is the IP address range of the container pods in the GKE cluster, in
68+
[CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)
69+
notation (e.g. `10.96.0.0/14`).
70+
If not specified then one will be automatically chosen.
71+
If this field is specified then IPAllocationPolicy.ClusterIpv4CidrBlock should be left blank.
72+
type: string
6573
clusterName:
6674
description: |-
6775
ClusterName allows you to specify the name of the GKE cluster.
@@ -118,6 +126,42 @@ spec:
118126
- host
119127
- port
120128
type: object
129+
ipAllocationPolicy:
130+
description: |-
131+
IPAllocationPolicy represents configuration options for GKE cluster IP allocation.
132+
If not specified then GKE default values will be used.
133+
properties:
134+
clusterIpv4CidrBlock:
135+
description: |-
136+
ClusterIpv4CidrBlock represents the IP address range for the GKE cluster pod IPs. If this field is set, then
137+
GCPManagedControlPlaneSpec.ClusterIpv4Cidr must be left blank.
138+
This field is only applicable when use_ip_aliases is set to true.
139+
If not specified the range will be chosen with the default size.
140+
type: string
141+
clusterSecondaryRangeName:
142+
description: |-
143+
ClusterSecondaryRangeName represents the name of the secondary range to be used for the GKE cluster CIDR block.
144+
The range will be used for pod IP addresses and must be an existing secondary range associated with the cluster subnetwork.
145+
This field is only applicable when use_ip_aliases is set to true.
146+
type: string
147+
servicesIpv4CidrBlock:
148+
description: |-
149+
ServicesIpv4CidrBlock represents the IP address range for services IPs in the GKE cluster.
150+
This field is only applicable when use_ip_aliases is set to true.
151+
If not specified the range will be chosen with the default size.
152+
type: string
153+
servicesSecondaryRangeName:
154+
description: |-
155+
ServicesSecondaryRangeName represents the name of the secondary range to be used for the services CIDR block.
156+
The range will be used for service ClusterIPs and must be an existing secondary range associated with the cluster subnetwork.
157+
This field is only applicable when use_ip_aliases is set to true.
158+
type: string
159+
useIPAliases:
160+
description: |-
161+
UseIPAliases represents whether alias IPs will be used for pod IPs in the cluster.
162+
If unspecified will default to false.
163+
type: boolean
164+
type: object
121165
location:
122166
description: |-
123167
Location represents the location (region or zone) in which the GKE cluster

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

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ spec:
5858
AdditionalLabels is an optional set of tags to add to GCP resources managed by the GCP provider, in addition to the
5959
ones added by default.
6060
type: object
61+
bootDiskKmsKey:
62+
description: BootDiskKmsKey is the name of the key used to encrypt
63+
the boot disk.
64+
type: string
6165
diskSizeGB:
6266
description: |-
6367
DiskSizeGB is size of the disk attached to each node,

exp/api/v1beta1/gcpmanagedcontrolplane_types.go

+40
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ type GCPManagedControlPlaneSpec struct {
8989
// Location represents the location (region or zone) in which the GKE cluster
9090
// will be created.
9191
Location string `json:"location"`
92+
// ClusterIpv4Cidr is the IP address range of the container pods in the GKE cluster, in
93+
// [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)
94+
// notation (e.g. `10.96.0.0/14`).
95+
// If not specified then one will be automatically chosen.
96+
// If this field is specified then IPAllocationPolicy.ClusterIpv4CidrBlock should be left blank.
97+
// +optional
98+
ClusterIpv4Cidr *string `json:"clusterIpv4Cidr,omitempty"`
99+
// IPAllocationPolicy represents configuration options for GKE cluster IP allocation.
100+
// If not specified then GKE default values will be used.
101+
// +optional
102+
IPAllocationPolicy *IPAllocationPolicy `json:"ipAllocationPolicy,omitempty"`
92103
// EnableAutopilot indicates whether to enable autopilot for this GKE cluster.
93104
// +optional
94105
EnableAutopilot bool `json:"enableAutopilot"`
@@ -173,6 +184,35 @@ const (
173184
Stable ReleaseChannel = "stable"
174185
)
175186

187+
// IPAllocationPolicy represents configuration options for GKE cluster IP allocation.
188+
type IPAllocationPolicy struct {
189+
// UseIPAliases represents whether alias IPs will be used for pod IPs in the cluster.
190+
// If unspecified will default to false.
191+
// +optional
192+
UseIPAliases *bool `json:"useIPAliases,omitempty"`
193+
// ClusterSecondaryRangeName represents the name of the secondary range to be used for the GKE cluster CIDR block.
194+
// The range will be used for pod IP addresses and must be an existing secondary range associated with the cluster subnetwork.
195+
// This field is only applicable when use_ip_aliases is set to true.
196+
// +optional
197+
ClusterSecondaryRangeName *string `json:"clusterSecondaryRangeName,omitempty"`
198+
// ServicesSecondaryRangeName represents the name of the secondary range to be used for the services CIDR block.
199+
// The range will be used for service ClusterIPs and must be an existing secondary range associated with the cluster subnetwork.
200+
// This field is only applicable when use_ip_aliases is set to true.
201+
// +optional
202+
ServicesSecondaryRangeName *string `json:"servicesSecondaryRangeName,omitempty"`
203+
// ClusterIpv4CidrBlock represents the IP address range for the GKE cluster pod IPs. If this field is set, then
204+
// GCPManagedControlPlaneSpec.ClusterIpv4Cidr must be left blank.
205+
// This field is only applicable when use_ip_aliases is set to true.
206+
// If not specified the range will be chosen with the default size.
207+
// +optional
208+
ClusterIpv4CidrBlock *string `json:"clusterIpv4CidrBlock,omitempty"`
209+
// ServicesIpv4CidrBlock represents the IP address range for services IPs in the GKE cluster.
210+
// This field is only applicable when use_ip_aliases is set to true.
211+
// If not specified the range will be chosen with the default size.
212+
// +optional
213+
ServicesIpv4CidrBlock *string `json:"servicesIpv4CidrBlock,omitempty"`
214+
}
215+
176216
// MasterAuthorizedNetworksConfig contains configuration options for the master authorized networks feature.
177217
// Enabled master authorized networks will disallow all external traffic to access
178218
// Kubernetes master through HTTPS except traffic from the given CIDR blocks,

exp/api/v1beta1/gcpmanagedcontrolplane_webhook.go

+61
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
apierrors "k8s.io/apimachinery/pkg/api/errors"
2626
"k8s.io/apimachinery/pkg/util/validation/field"
27+
"k8s.io/utils/pointer"
2728

2829
"github.com/pkg/errors"
2930
"k8s.io/apimachinery/pkg/runtime"
@@ -123,6 +124,15 @@ func (r *GCPManagedControlPlane) ValidateUpdate(oldRaw runtime.Object) (admissio
123124
)
124125
}
125126

127+
// Add IPAllocationPolicy for CIDR support (PLT-1246)
128+
129+
if !cmp.Equal(r.Spec.ClusterIpv4Cidr, old.Spec.ClusterIpv4Cidr) {
130+
allErrs = append(allErrs,
131+
field.Invalid(field.NewPath("spec", "ClusterIpv4Cidr"),
132+
pointer.StringDeref(r.Spec.ClusterIpv4Cidr, ""), "field is immutable"),
133+
)
134+
}
135+
126136
if !cmp.Equal(r.Spec.EnableAutopilot, old.Spec.EnableAutopilot) {
127137
allErrs = append(allErrs,
128138
field.Invalid(field.NewPath("spec", "EnableAutopilot"),
@@ -167,3 +177,54 @@ func generateGKEName(resourceName, namespace string, maxLength int) (string, err
167177

168178
return fmt.Sprintf("%s%s", resourcePrefix, hashedName), nil
169179
}
180+
181+
// Add IPAllocationPolicy for CIDR support (PLT-1246)
182+
183+
func validateIPAllocationPolicy(spec GCPManagedControlPlaneSpec) field.ErrorList {
184+
var allErrs field.ErrorList
185+
186+
if spec.IPAllocationPolicy == nil {
187+
return allErrs
188+
}
189+
190+
path := field.NewPath("spec", "IPAllocationPolicy")
191+
192+
isUseIPAliases := pointer.BoolDeref(spec.IPAllocationPolicy.UseIPAliases, false)
193+
if spec.IPAllocationPolicy.ClusterSecondaryRangeName != nil && !isUseIPAliases {
194+
allErrs = append(allErrs,
195+
field.Invalid(path.Child("ClusterSecondaryRangeName"),
196+
spec.IPAllocationPolicy.ClusterSecondaryRangeName,
197+
"field cannot be set unless UseIPAliases is set to true"),
198+
)
199+
}
200+
if spec.IPAllocationPolicy.ServicesSecondaryRangeName != nil && !isUseIPAliases {
201+
allErrs = append(allErrs,
202+
field.Invalid(path.Child("ServicesSecondaryRangeName"),
203+
spec.IPAllocationPolicy.ServicesSecondaryRangeName,
204+
"field cannot be set unless UseIPAliases is set to true"),
205+
)
206+
}
207+
if spec.IPAllocationPolicy.ServicesIpv4CidrBlock != nil && !isUseIPAliases {
208+
allErrs = append(allErrs,
209+
field.Invalid(path.Child("ServicesIpv4CidrBlock"),
210+
spec.IPAllocationPolicy.ServicesIpv4CidrBlock,
211+
"field cannot be set unless UseIPAliases is set to true"),
212+
)
213+
}
214+
if spec.IPAllocationPolicy.ClusterIpv4CidrBlock != nil && !isUseIPAliases {
215+
allErrs = append(allErrs,
216+
field.Invalid(path.Child("ClusterIpv4CidrBlock"),
217+
spec.IPAllocationPolicy.ClusterIpv4CidrBlock,
218+
"field cannot be set unless UseIPAliases is set to true"),
219+
)
220+
}
221+
if spec.IPAllocationPolicy.ClusterIpv4CidrBlock != nil && spec.ClusterIpv4Cidr != nil {
222+
allErrs = append(allErrs,
223+
field.Invalid(path.Child("ClusterIpv4CidrBlock"),
224+
spec.IPAllocationPolicy.ClusterIpv4CidrBlock,
225+
"only one of spec.ClusterIpv4Cidr and spec.IPAllocationPolicy.ClusterIpv4CidrBlock can be set"),
226+
)
227+
}
228+
229+
return allErrs
230+
}

exp/api/v1beta1/gcpmanagedmachinepool_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ type GCPManagedMachinePoolSpec struct {
114114
// machine pool
115115
// +optional
116116
ProviderIDList []string `json:"providerIDList,omitempty"`
117+
// BootDiskKmsKey is the name of the key used to encrypt the boot disk.
118+
BootDiskKmsKey string `json:"bootDiskKmsKey,omitempty"`
117119
}
118120

119121
// NodeNetworkConfig encapsulates node network configurations.

exp/api/v1beta1/types.go

+18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"strings"
2121

2222
"cloud.google.com/go/container/apiv1/containerpb"
23+
"k8s.io/utils/pointer"
2324
)
2425

2526
// TaintEffect is the effect for a Kubernetes taint.
@@ -144,3 +145,20 @@ func ConvertToSdkLinuxNodeConfig(linuxNodeConfig *LinuxNodeConfig) *containerpb.
144145
}
145146
return &sdkLinuxNodeConfig
146147
}
148+
149+
// Add IPAllocationPolicy for CIDR support (PLT-1246)
150+
151+
// ConvertToSdkIPAllocationPolicy converts the CAPG IPAllocationPolicy to a containerpb IPAllocationPolicy.
152+
func ConvertToSdkIPAllocationPolicy(policy *IPAllocationPolicy) *containerpb.IPAllocationPolicy {
153+
if policy == nil {
154+
return nil
155+
}
156+
157+
return &containerpb.IPAllocationPolicy{
158+
UseIpAliases: pointer.BoolDeref(policy.UseIPAliases, false),
159+
ClusterSecondaryRangeName: pointer.StringDeref(policy.ClusterSecondaryRangeName, ""),
160+
ServicesSecondaryRangeName: pointer.StringDeref(policy.ServicesSecondaryRangeName, ""),
161+
ClusterIpv4CidrBlock: pointer.StringDeref(policy.ClusterIpv4CidrBlock, ""),
162+
ServicesIpv4CidrBlock: pointer.StringDeref(policy.ServicesIpv4CidrBlock, ""),
163+
}
164+
}

exp/api/v1beta1/zz_generated.deepcopy.go

+50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)