Skip to content

Commit 1eb50ed

Browse files
authored
Merge pull request #1186 from akshay196-rafay/gcpmanagedcontrolplane-additional-fields
Support additional GCPManagedControlPlane fields
2 parents 6055ba9 + 822ae06 commit 1eb50ed

File tree

5 files changed

+297
-4
lines changed

5 files changed

+297
-4
lines changed

cloud/services/container/clusters/reconcile.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error {
251251

252252
isRegional := shared.IsRegional(s.scope.Region())
253253
cluster := &containerpb.Cluster{
254-
Name: s.scope.ClusterName(),
255-
Network: *s.scope.GCPManagedCluster.Spec.Network.Name,
256-
Subnetwork: s.getSubnetNameInClusterRegion(),
254+
Name: s.scope.ClusterName(),
255+
Description: s.scope.GCPManagedControlPlane.Spec.Description,
256+
Network: *s.scope.GCPManagedCluster.Spec.Network.Name,
257+
Subnetwork: s.getSubnetNameInClusterRegion(),
257258
Autopilot: &containerpb.Autopilot{
258259
Enabled: s.scope.GCPManagedControlPlane.Spec.EnableAutopilot,
259260
},
@@ -265,6 +266,34 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error {
265266
if s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion != nil {
266267
cluster.InitialClusterVersion = convertToSdkMasterVersion(*s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion)
267268
}
269+
if s.scope.GCPManagedControlPlane.Spec.ClusterNetwork != nil {
270+
cn := s.scope.GCPManagedControlPlane.Spec.ClusterNetwork
271+
if cn.UseIPAliases {
272+
cluster.IpAllocationPolicy = &containerpb.IPAllocationPolicy{}
273+
cluster.IpAllocationPolicy.UseIpAliases = cn.UseIPAliases
274+
}
275+
if cn.PrivateCluster != nil {
276+
cluster.PrivateClusterConfig = &containerpb.PrivateClusterConfig{}
277+
cluster.PrivateClusterConfig.EnablePrivateEndpoint = cn.PrivateCluster.EnablePrivateEndpoint
278+
if cn.PrivateCluster.EnablePrivateEndpoint {
279+
cluster.MasterAuthorizedNetworksConfig = &containerpb.MasterAuthorizedNetworksConfig{
280+
Enabled: true,
281+
}
282+
}
283+
cluster.PrivateClusterConfig.EnablePrivateNodes = cn.PrivateCluster.EnablePrivateNodes
284+
285+
cluster.PrivateClusterConfig.MasterIpv4CidrBlock = cn.PrivateCluster.ControlPlaneCidrBlock
286+
cluster.PrivateClusterConfig.MasterGlobalAccessConfig = &containerpb.PrivateClusterMasterGlobalAccessConfig{
287+
Enabled: cn.PrivateCluster.ControlPlaneGlobalAccess,
288+
}
289+
290+
cluster.NetworkConfig = &containerpb.NetworkConfig{
291+
DefaultSnatStatus: &containerpb.DefaultSnatStatus{
292+
Disabled: cn.PrivateCluster.DisableDefaultSNAT,
293+
},
294+
}
295+
}
296+
}
268297
if !s.scope.IsAutopilotCluster() {
269298
cluster.NodePools = scope.ConvertToSdkNodePools(nodePools, machinePools, isRegional, cluster.GetName())
270299
}

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,75 @@ spec:
6868
If you don't specify a name then a default name will be created
6969
based on the namespace and name of the managed control plane.
7070
type: string
71+
clusterNetwork:
72+
description: ClusterNetwork define the cluster network.
73+
properties:
74+
pod:
75+
description: Pod defines the range of CIDRBlock list from where
76+
it gets the IP address.
77+
properties:
78+
cidrBlock:
79+
description: |-
80+
CidrBlock is where all pods in the cluster are assigned an IP address from this range. Enter a range
81+
(in CIDR notation) within a network range, a mask, or leave this field blank to use a default range.
82+
This setting is permanent.
83+
type: string
84+
type: object
85+
privateCluster:
86+
description: PrivateCluster defines the private cluster spec.
87+
properties:
88+
controlPlaneCidrBlock:
89+
description: |-
90+
ControlPlaneCidrBlock is the IP range in CIDR notation to use for the hosted master network. This range must not
91+
overlap with any other ranges in use within the cluster's network. Honored when enabled is true.
92+
type: string
93+
controlPlaneGlobalAccess:
94+
description: ControlPlaneGlobalAccess is whenever master is
95+
accessible globally or not. Honored when enabled is true.
96+
type: boolean
97+
disableDefaultSNAT:
98+
description: DisableDefaultSNAT disables cluster default sNAT
99+
rules. Honored when enabled is true.
100+
type: boolean
101+
enablePrivateEndpoint:
102+
description: |-
103+
EnablePrivateEndpoint: Whether the master's internal IP
104+
address is used as the cluster endpoint.
105+
type: boolean
106+
enablePrivateNodes:
107+
description: |-
108+
EnablePrivateNodes: Whether nodes have internal IP
109+
addresses only. If enabled, all nodes are given only RFC
110+
1918 private addresses and communicate with the master via
111+
private networking.
112+
type: boolean
113+
type: object
114+
service:
115+
description: Service defines the range of CIDRBlock list from
116+
where it gets the IP address.
117+
properties:
118+
cidrBlock:
119+
description: |-
120+
CidrBlock is where cluster services will be assigned an IP address from this IP address range. Enter a range
121+
(in CIDR notation) within a network range, a mask, or leave this field blank to use a default range.
122+
This setting is permanent.
123+
type: string
124+
type: object
125+
useIPAliases:
126+
description: |-
127+
UseIPAliases is whether alias IPs will be used for pod IPs in the cluster. If false, routes will be used for
128+
pod IPs in the cluster.
129+
type: boolean
130+
type: object
71131
controlPlaneVersion:
72132
description: |-
73133
ControlPlaneVersion represents the control plane version of the GKE cluster.
74134
If not specified, the default version currently supported by GKE will be
75135
used.
76136
type: string
137+
description:
138+
description: Description describe the cluster.
139+
type: string
77140
enableAutopilot:
78141
description: EnableAutopilot indicates whether to enable autopilot
79142
for this GKE cluster.

exp/api/v1beta1/gcpmanagedcontrolplane_types.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,104 @@ const (
2727
ManagedControlPlaneFinalizer = "gcpmanagedcontrolplane.infrastructure.cluster.x-k8s.io"
2828
)
2929

30+
// PrivateCluster defines a private Cluster.
31+
type PrivateCluster struct {
32+
// EnablePrivateEndpoint: Whether the master's internal IP
33+
// address is used as the cluster endpoint.
34+
// +optional
35+
EnablePrivateEndpoint bool `json:"enablePrivateEndpoint,omitempty"`
36+
37+
// EnablePrivateNodes: Whether nodes have internal IP
38+
// addresses only. If enabled, all nodes are given only RFC
39+
// 1918 private addresses and communicate with the master via
40+
// private networking.
41+
// +optional
42+
EnablePrivateNodes bool `json:"enablePrivateNodes,omitempty"`
43+
44+
// ControlPlaneCidrBlock is the IP range in CIDR notation to use for the hosted master network. This range must not
45+
// overlap with any other ranges in use within the cluster's network. Honored when enabled is true.
46+
// +optional
47+
ControlPlaneCidrBlock string `json:"controlPlaneCidrBlock,omitempty"`
48+
49+
// ControlPlaneGlobalAccess is whenever master is accessible globally or not. Honored when enabled is true.
50+
// +optional
51+
ControlPlaneGlobalAccess bool `json:"controlPlaneGlobalAccess,omitempty"`
52+
53+
// DisableDefaultSNAT disables cluster default sNAT rules. Honored when enabled is true.
54+
// +optional
55+
DisableDefaultSNAT bool `json:"disableDefaultSNAT,omitempty"`
56+
}
57+
58+
// ClusterNetworkPod the range of CIDRBlock list from where it gets the IP address.
59+
type ClusterNetworkPod struct {
60+
// CidrBlock is where all pods in the cluster are assigned an IP address from this range. Enter a range
61+
// (in CIDR notation) within a network range, a mask, or leave this field blank to use a default range.
62+
// This setting is permanent.
63+
// +optional
64+
CidrBlock string `json:"cidrBlock,omitempty"`
65+
}
66+
67+
// ClusterNetworkService defines the range of CIDRBlock list from where it gets the IP address.
68+
type ClusterNetworkService struct {
69+
// CidrBlock is where cluster services will be assigned an IP address from this IP address range. Enter a range
70+
// (in CIDR notation) within a network range, a mask, or leave this field blank to use a default range.
71+
// This setting is permanent.
72+
// +optional
73+
CidrBlock string `json:"cidrBlock,omitempty"`
74+
}
75+
76+
// ClusterNetwork define the cluster network.
77+
type ClusterNetwork struct {
78+
// PrivateCluster defines the private cluster spec.
79+
// +optional
80+
PrivateCluster *PrivateCluster `json:"privateCluster,omitempty"`
81+
82+
// UseIPAliases is whether alias IPs will be used for pod IPs in the cluster. If false, routes will be used for
83+
// pod IPs in the cluster.
84+
// +optional
85+
UseIPAliases bool `json:"useIPAliases,omitempty"`
86+
87+
// Pod defines the range of CIDRBlock list from where it gets the IP address.
88+
// +optional
89+
Pod *ClusterNetworkPod `json:"pod,omitempty"`
90+
91+
// Service defines the range of CIDRBlock list from where it gets the IP address.
92+
// +optional
93+
Service *ClusterNetworkService `json:"service,omitempty"`
94+
}
95+
96+
// WorkloadIdentityConfig allows workloads in your GKE clusters to impersonate Identity and Access Management (IAM)
97+
// service accounts to access Google Cloud services.
98+
type WorkloadIdentityConfig struct {
99+
// WorkloadPool is the workload pool to attach all Kubernetes service accounts to Google Cloud services.
100+
// Only relevant when enabled is true
101+
// +kubebuilder:validation:Required
102+
WorkloadPool string `json:"workloadPool,omitempty"`
103+
}
104+
105+
// AuthenticatorGroupConfig is RBAC security group for use with Google security groups in Kubernetes RBAC.
106+
type AuthenticatorGroupConfig struct {
107+
// SecurityGroups is the name of the security group-of-groups to be used.
108+
// +kubebuilder:validation:Required
109+
SecurityGroups string `json:"securityGroups,omitempty"`
110+
}
111+
30112
// GCPManagedControlPlaneSpec defines the desired state of GCPManagedControlPlane.
31113
type GCPManagedControlPlaneSpec struct {
32114
// ClusterName allows you to specify the name of the GKE cluster.
33115
// If you don't specify a name then a default name will be created
34116
// based on the namespace and name of the managed control plane.
35117
// +optional
36118
ClusterName string `json:"clusterName,omitempty"`
119+
120+
// Description describe the cluster.
121+
// +optional
122+
Description string `json:"description,omitempty"`
123+
124+
// ClusterNetwork define the cluster network.
125+
// +optional
126+
ClusterNetwork *ClusterNetwork `json:"clusterNetwork,omitempty"`
127+
37128
// Project is the name of the project to deploy the cluster to.
38129
Project string `json:"project"`
39130
// Location represents the location (region or zone) in which the GKE cluster

exp/api/v1beta1/zz_generated.deepcopy.go

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

hack/tools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module sigs.k8s.io/cluster-api-provider-gcp/hack/tools
22

3-
go 1.21.10
3+
go 1.21
44

55
replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.7.3
66

0 commit comments

Comments
 (0)