Skip to content

feat: add support for gke clusterclass #1442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ test: $(SETUP_ENVTEST) ## Run unit and integration tests
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... $(TEST_ARGS)

# Allow overriding the e2e configurations
GINKGO_FOCUS ?= Workload cluster creation
GINKGO_FOCUS ?= Workload cluster creation|GKE workload cluster creation
GINKGO_SKIP ?= API Version Upgrade
GINKGO_NODES ?= 1
GINKGO_NOCOLOR ?= false
Expand Down
12 changes: 12 additions & 0 deletions cloud/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,15 @@ func (s *ManagedMachinePoolScope) NodePoolLocation() string {
func (s *ManagedMachinePoolScope) NodePoolFullName() string {
return fmt.Sprintf("%s/nodePools/%s", s.NodePoolLocation(), s.NodePoolName())
}

// SetInfrastructureMachineKind sets the infrastructure machine kind in the status if it is not set already, returning
// `true` if the status was updated. This supports MachinePool Machines.
func (s *ManagedMachinePoolScope) SetInfrastructureMachineKind() bool {
if s.GCPManagedMachinePool.Status.InfrastructureMachineKind != infrav1exp.GCPManagedMachinePoolMachineKind {
s.GCPManagedMachinePool.Status.InfrastructureMachineKind = infrav1exp.GCPManagedMachinePoolMachineKind

return true
}

return false
}
30 changes: 29 additions & 1 deletion cloud/scope/managedmachinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ var _ = Describe("GCPManagedMachinePool Scope", func() {
Namespace: namespace,
},
Spec: v1beta1.GCPManagedMachinePoolSpec{
NodePoolName: nodePoolName,
GCPManagedMachinePoolClassSpec: v1beta1.GCPManagedMachinePoolClassSpec{
NodePoolName: nodePoolName,
},
},
}
TestMP = &clusterv1exp.MachinePool{
Expand All @@ -52,6 +54,32 @@ var _ = Describe("GCPManagedMachinePool Scope", func() {
})
})

Context("Test MachinePool InfrastructureMachineKind", func() {
It("should set infrastructure machine kind when empty", func() {
TestGCPMMP.Status = v1beta1.GCPManagedMachinePoolStatus{}
machinePoolScope := ManagedMachinePoolScope{
GCPManagedMachinePool: TestGCPMMP,
}

update := machinePoolScope.SetInfrastructureMachineKind()
Expect(machinePoolScope.GCPManagedMachinePool.Status.InfrastructureMachineKind).To(Equal(v1beta1.GCPManagedMachinePoolMachineKind))
Expect(update).To(BeTrue())
})

It("should not update infrastructure machine kind if already set", func() {
TestGCPMMP.Status = v1beta1.GCPManagedMachinePoolStatus{
InfrastructureMachineKind: v1beta1.GCPManagedMachinePoolMachineKind,
}
machinePoolScope := ManagedMachinePoolScope{
GCPManagedMachinePool: TestGCPMMP,
}

update := machinePoolScope.SetInfrastructureMachineKind()
Expect(machinePoolScope.GCPManagedMachinePool.Status.InfrastructureMachineKind).To(Equal(v1beta1.GCPManagedMachinePoolMachineKind))
Expect(update).To(BeFalse())
})
})

Context("Test ConvertToSdkNodePool", func() {
It("should convert to SDK node pool with default values", func() {
sdkNodePool := ConvertToSdkNodePool(*TestGCPMMP, *TestMP, false, TestClusterName)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ spec:
Possible values: none, logging.googleapis.com/kubernetes (default).
Value is ignored when enableAutopilot = true.
type: string
machineTemplate:
description: |-
MachineTemplate contains information about how machines
should be shaped when creating or updating a control plane.
For the GCPManagedControlPlaneTemplate, this field is used
only to fulfill the CAPI contract.
type: object
master_authorized_networks_config:
description: |-
MasterAuthorizedNetworksConfig represents configuration options for master authorized networks feature of the GKE cluster.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.1
name: gcpmanagedcontrolplanetemplates.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
names:
categories:
- cluster-api
kind: GCPManagedControlPlaneTemplate
listKind: GCPManagedControlPlaneTemplateList
plural: gcpmanagedcontrolplanetemplates
shortNames:
- amcpt
singular: gcpmanagedcontrolplanetemplate
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: GCPManagedControlPlaneTemplate is the Schema for the GCPManagedControlPlaneTemplates
API.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: GCPManagedControlPlaneTemplateSpec defines the desired state
of GCPManagedControlPlaneTemplate.
properties:
template:
description: GCPManagedControlPlaneTemplateResource describes the
data needed to create an GCPManagedCluster from a template.
properties:
spec:
description: GCPManagedControlPlaneTemplateResourceSpec specifies
an GCP managed control plane template resource.
properties:
clusterNetwork:
description: ClusterNetwork define the cluster network.
properties:
pod:
description: Pod defines the range of CIDRBlock list from
where it gets the IP address.
properties:
cidrBlock:
description: |-
CidrBlock is where all pods in the cluster are assigned an IP address from this range. Enter a range
(in CIDR notation) within a network range, a mask, or leave this field blank to use a default range.
This setting is permanent.
type: string
type: object
privateCluster:
description: PrivateCluster defines the private cluster
spec.
properties:
controlPlaneCidrBlock:
description: |-
ControlPlaneCidrBlock is the IP range in CIDR notation to use for the hosted master network. This range must not
overlap with any other ranges in use within the cluster's network. Honored when enabled is true.
type: string
controlPlaneGlobalAccess:
description: ControlPlaneGlobalAccess is whenever
master is accessible globally or not. Honored when
enabled is true.
type: boolean
disableDefaultSNAT:
description: DisableDefaultSNAT disables cluster default
sNAT rules. Honored when enabled is true.
type: boolean
enablePrivateEndpoint:
description: |-
EnablePrivateEndpoint: Whether the master's internal IP
address is used as the cluster endpoint.
type: boolean
enablePrivateNodes:
description: |-
EnablePrivateNodes: Whether nodes have internal IP
addresses only. If enabled, all nodes are given only RFC
1918 private addresses and communicate with the master via
private networking.
type: boolean
type: object
service:
description: Service defines the range of CIDRBlock list
from where it gets the IP address.
properties:
cidrBlock:
description: |-
CidrBlock is where cluster services will be assigned an IP address from this IP address range. Enter a range
(in CIDR notation) within a network range, a mask, or leave this field blank to use a default range.
This setting is permanent.
type: string
type: object
useIPAliases:
description: |-
UseIPAliases is whether alias IPs will be used for pod IPs in the cluster. If false, routes will be used for
pod IPs in the cluster.
type: boolean
type: object
enableAutopilot:
description: EnableAutopilot indicates whether to enable autopilot
for this GKE cluster.
type: boolean
enableIdentityService:
description: EnableIdentityService indicates whether to enable
Identity Service component for this GKE cluster.
type: boolean
location:
description: |-
Location represents the location (region or zone) in which the GKE cluster
will be created.
type: string
loggingService:
description: |-
LoggingService represents configuration of logging service feature of the GKE cluster.
Possible values: none, logging.googleapis.com/kubernetes (default).
Value is ignored when enableAutopilot = true.
type: string
machineTemplate:
description: |-
MachineTemplate contains information about how machines
should be shaped when creating or updating a control plane.
For the GCPManagedControlPlaneTemplate, this field is used
only to fulfill the CAPI contract.
type: object
master_authorized_networks_config:
description: |-
MasterAuthorizedNetworksConfig represents configuration options for master authorized networks feature of the GKE cluster.
This feature is disabled if this field is not specified.
properties:
cidr_blocks:
description: |-
cidr_blocks define up to 50 external networks that could access
Kubernetes master through HTTPS.
items:
description: MasterAuthorizedNetworksConfigCidrBlock
contains an optional name and one CIDR block.
properties:
cidr_block:
description: cidr_block must be specified in CIDR
notation.
pattern: ^(?:[0-9]{1,3}\.){3}[0-9]{1,3}(?:\/([0-9]|[1-2][0-9]|3[0-2]))?$|^([a-fA-F0-9:]+:+)+[a-fA-F0-9]+\/[0-9]{1,3}$
type: string
display_name:
description: display_name is an field for users
to identify CIDR blocks.
type: string
type: object
type: array
gcp_public_cidrs_access_enabled:
description: Whether master is accessible via Google Compute
Engine Public IP addresses.
type: boolean
type: object
monitoringService:
description: |-
MonitoringService represents configuration of monitoring service feature of the GKE cluster.
Possible values: none, monitoring.googleapis.com/kubernetes (default).
Value is ignored when enableAutopilot = true.
type: string
project:
description: Project is the name of the project to deploy
the cluster to.
type: string
releaseChannel:
description: ReleaseChannel represents the release channel
of the GKE cluster.
enum:
- rapid
- regular
- stable
type: string
required:
- location
- project
type: object
required:
- spec
type: object
required:
- template
type: object
type: object
served: true
storage: true
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ spec:
- type
type: object
type: array
infrastructureMachineKind:
description: InfrastructureMachineKind is the kind of the infrastructure
resources behind MachinePool Machines.
type: string
ready:
default: false
description: Ready denotes that the GCPManagedMachinePool has joined
Expand Down
Loading