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

Merged
Merged
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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ generate-go: $(CONTROLLER_GEN) $(CONVERSION_GEN) ## Runs Go related generate tar
paths=./ \
paths=./... \
paths=./$(EXP_DIR)/api/... \
paths=./$(EXP_DIR)/bootstrap/gke/api/... \
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt
go generate ./...

Expand All @@ -338,6 +339,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
paths=./ \
paths=./api/... \
paths=./$(EXP_DIR)/api/... \
paths=./$(EXP_DIR)/bootstrap/gke/api/... \
crd:crdVersions=v1 \
rbac:roleName=manager-role \
output:crd:dir=$(CRD_ROOT) \
Expand All @@ -347,6 +349,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
paths=./ \
paths=./controllers/... \
paths=./$(EXP_DIR)/controllers/... \
paths=./$(EXP_DIR)/bootstrap/gke/controllers/... \
output:rbac:dir=$(RBAC_ROOT) \
rbac:roleName=manager-role

Expand Down Expand Up @@ -622,5 +625,7 @@ verify-modules: modules
.PHONY: verify-gen
verify-gen: generate
@if !(git diff --quiet HEAD); then \
echo "generated files are out of date, run make generate"; exit 1; \
echo "generated files are out of date, run make generate"; \
git diff HEAD; \
exit 1; \
fi
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
138 changes: 138 additions & 0 deletions config/crd/bases/bootstrap.cluster.x-k8s.io_gkeconfigs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.3
name: gkeconfigs.bootstrap.cluster.x-k8s.io
spec:
group: bootstrap.cluster.x-k8s.io
names:
categories:
- cluster-api
kind: GKEConfig
listKind: GKEConfigList
plural: gkeconfigs
shortNames:
- gkec
singular: gkeconfig
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: Bootstrap configuration is ready
jsonPath: .status.ready
name: Ready
type: string
- description: Name of Secret containing bootstrap data
jsonPath: .status.dataSecretName
name: DataSecretName
type: string
name: v1beta1
schema:
openAPIV3Schema:
description: |-
GKEConfig is the schema for the GCP GKE Bootstrap Configuration.
this is a placeholder used for compliance with the CAPI contract.
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: GKEConfigSpec defines the desired state of GCP GKE Bootstrap
Configuration.
type: object
status:
description: GKEConfigStatus defines the observed state of the GCP GKE
Bootstrap Configuration.
properties:
conditions:
description: Conditions defines current service state of the GKEConfig.
items:
description: Condition defines an observation of a Cluster API resource
operational state.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when
the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This field may be empty.
maxLength: 10240
minLength: 1
type: string
reason:
description: |-
reason is the reason for the condition's last transition in CamelCase.
The specific API may choose whether or not this field is considered a guaranteed API.
This field may be empty.
maxLength: 256
minLength: 1
type: string
severity:
description: |-
severity provides an explicit classification of Reason code, so the users or machines can immediately
understand the current situation and act accordingly.
The Severity field MUST be set only when Status=False.
maxLength: 32
type: string
status:
description: status of the condition, one of True, False, Unknown.
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
can be useful (see .node.status.conditions), the ability to deconflict is important.
maxLength: 256
minLength: 1
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
dataSecretName:
description: DataSecretName is the name of the secret that stores
the bootstrap data script.
type: string
failureMessage:
description: FailureMessage will be set on non-retryable errors
type: string
failureReason:
description: FailureReason will be set on non-retryable errors
type: string
observedGeneration:
description: ObservedGeneration is the latest generation observed
by the controller.
format: int64
type: integer
ready:
description: Ready indicates the BootstrapData secret is ready to
be consumed
type: boolean
type: object
type: object
served: true
storage: true
subresources:
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.3
name: gkeconfigtemplates.bootstrap.cluster.x-k8s.io
spec:
group: bootstrap.cluster.x-k8s.io
names:
categories:
- cluster-api
kind: GKEConfigTemplate
listKind: GKEConfigTemplateList
plural: gkeconfigtemplates
shortNames:
- gkect
singular: gkeconfigtemplate
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: GKEConfigTemplate is the GCP GKE Bootstrap Configuration Template
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: GKEConfigTemplateSpec defines the desired state of templated
GKEConfig GCP GKE Bootstrap Configuration resources.
properties:
template:
description: GKEConfigTemplateResource defines the Template structure.
properties:
spec:
description: GKEConfigSpec defines the desired state of GCP GKE
Bootstrap Configuration.
type: object
type: object
required:
- template
type: object
type: object
served: true
storage: true
Loading