Skip to content

Commit 3f6ed14

Browse files
authored
Merge pull request #1442 from salasberryfin/gke-clusterclass-support
feat: add support for gke clusterclass
2 parents 9eed3ec + 013bc4c commit 3f6ed14

File tree

47 files changed

+4021
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4021
-310
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ generate-go: $(CONTROLLER_GEN) $(CONVERSION_GEN) ## Runs Go related generate tar
329329
paths=./ \
330330
paths=./... \
331331
paths=./$(EXP_DIR)/api/... \
332+
paths=./$(EXP_DIR)/bootstrap/gke/api/... \
332333
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt
333334
go generate ./...
334335

@@ -338,6 +339,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
338339
paths=./ \
339340
paths=./api/... \
340341
paths=./$(EXP_DIR)/api/... \
342+
paths=./$(EXP_DIR)/bootstrap/gke/api/... \
341343
crd:crdVersions=v1 \
342344
rbac:roleName=manager-role \
343345
output:crd:dir=$(CRD_ROOT) \
@@ -347,6 +349,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
347349
paths=./ \
348350
paths=./controllers/... \
349351
paths=./$(EXP_DIR)/controllers/... \
352+
paths=./$(EXP_DIR)/bootstrap/gke/controllers/... \
350353
output:rbac:dir=$(RBAC_ROOT) \
351354
rbac:roleName=manager-role
352355

@@ -622,5 +625,7 @@ verify-modules: modules
622625
.PHONY: verify-gen
623626
verify-gen: generate
624627
@if !(git diff --quiet HEAD); then \
625-
echo "generated files are out of date, run make generate"; exit 1; \
628+
echo "generated files are out of date, run make generate"; \
629+
git diff HEAD; \
630+
exit 1; \
626631
fi

cloud/scope/managedmachinepool.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,15 @@ func (s *ManagedMachinePoolScope) NodePoolLocation() string {
312312
func (s *ManagedMachinePoolScope) NodePoolFullName() string {
313313
return fmt.Sprintf("%s/nodePools/%s", s.NodePoolLocation(), s.NodePoolName())
314314
}
315+
316+
// SetInfrastructureMachineKind sets the infrastructure machine kind in the status if it is not set already, returning
317+
// `true` if the status was updated. This supports MachinePool Machines.
318+
func (s *ManagedMachinePoolScope) SetInfrastructureMachineKind() bool {
319+
if s.GCPManagedMachinePool.Status.InfrastructureMachineKind != infrav1exp.GCPManagedMachinePoolMachineKind {
320+
s.GCPManagedMachinePool.Status.InfrastructureMachineKind = infrav1exp.GCPManagedMachinePoolMachineKind
321+
322+
return true
323+
}
324+
325+
return false
326+
}

cloud/scope/managedmachinepool_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ var _ = Describe("GCPManagedMachinePool Scope", func() {
3131
Namespace: namespace,
3232
},
3333
Spec: v1beta1.GCPManagedMachinePoolSpec{
34-
NodePoolName: nodePoolName,
34+
GCPManagedMachinePoolClassSpec: v1beta1.GCPManagedMachinePoolClassSpec{
35+
NodePoolName: nodePoolName,
36+
},
3537
},
3638
}
3739
TestMP = &clusterv1exp.MachinePool{
@@ -52,6 +54,32 @@ var _ = Describe("GCPManagedMachinePool Scope", func() {
5254
})
5355
})
5456

57+
Context("Test MachinePool InfrastructureMachineKind", func() {
58+
It("should set infrastructure machine kind when empty", func() {
59+
TestGCPMMP.Status = v1beta1.GCPManagedMachinePoolStatus{}
60+
machinePoolScope := ManagedMachinePoolScope{
61+
GCPManagedMachinePool: TestGCPMMP,
62+
}
63+
64+
update := machinePoolScope.SetInfrastructureMachineKind()
65+
Expect(machinePoolScope.GCPManagedMachinePool.Status.InfrastructureMachineKind).To(Equal(v1beta1.GCPManagedMachinePoolMachineKind))
66+
Expect(update).To(BeTrue())
67+
})
68+
69+
It("should not update infrastructure machine kind if already set", func() {
70+
TestGCPMMP.Status = v1beta1.GCPManagedMachinePoolStatus{
71+
InfrastructureMachineKind: v1beta1.GCPManagedMachinePoolMachineKind,
72+
}
73+
machinePoolScope := ManagedMachinePoolScope{
74+
GCPManagedMachinePool: TestGCPMMP,
75+
}
76+
77+
update := machinePoolScope.SetInfrastructureMachineKind()
78+
Expect(machinePoolScope.GCPManagedMachinePool.Status.InfrastructureMachineKind).To(Equal(v1beta1.GCPManagedMachinePoolMachineKind))
79+
Expect(update).To(BeFalse())
80+
})
81+
})
82+
5583
Context("Test ConvertToSdkNodePool", func() {
5684
It("should convert to SDK node pool with default values", func() {
5785
sdkNodePool := ConvertToSdkNodePool(*TestGCPMMP, *TestMP, false, TestClusterName)
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.17.3
7+
name: gkeconfigs.bootstrap.cluster.x-k8s.io
8+
spec:
9+
group: bootstrap.cluster.x-k8s.io
10+
names:
11+
categories:
12+
- cluster-api
13+
kind: GKEConfig
14+
listKind: GKEConfigList
15+
plural: gkeconfigs
16+
shortNames:
17+
- gkec
18+
singular: gkeconfig
19+
scope: Namespaced
20+
versions:
21+
- additionalPrinterColumns:
22+
- description: Bootstrap configuration is ready
23+
jsonPath: .status.ready
24+
name: Ready
25+
type: string
26+
- description: Name of Secret containing bootstrap data
27+
jsonPath: .status.dataSecretName
28+
name: DataSecretName
29+
type: string
30+
name: v1beta1
31+
schema:
32+
openAPIV3Schema:
33+
description: |-
34+
GKEConfig is the schema for the GCP GKE Bootstrap Configuration.
35+
this is a placeholder used for compliance with the CAPI contract.
36+
properties:
37+
apiVersion:
38+
description: |-
39+
APIVersion defines the versioned schema of this representation of an object.
40+
Servers should convert recognized schemas to the latest internal value, and
41+
may reject unrecognized values.
42+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
43+
type: string
44+
kind:
45+
description: |-
46+
Kind is a string value representing the REST resource this object represents.
47+
Servers may infer this from the endpoint the client submits requests to.
48+
Cannot be updated.
49+
In CamelCase.
50+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
51+
type: string
52+
metadata:
53+
type: object
54+
spec:
55+
description: GKEConfigSpec defines the desired state of GCP GKE Bootstrap
56+
Configuration.
57+
type: object
58+
status:
59+
description: GKEConfigStatus defines the observed state of the GCP GKE
60+
Bootstrap Configuration.
61+
properties:
62+
conditions:
63+
description: Conditions defines current service state of the GKEConfig.
64+
items:
65+
description: Condition defines an observation of a Cluster API resource
66+
operational state.
67+
properties:
68+
lastTransitionTime:
69+
description: |-
70+
lastTransitionTime is the last time the condition transitioned from one status to another.
71+
This should be when the underlying condition changed. If that is not known, then using the time when
72+
the API field changed is acceptable.
73+
format: date-time
74+
type: string
75+
message:
76+
description: |-
77+
message is a human readable message indicating details about the transition.
78+
This field may be empty.
79+
maxLength: 10240
80+
minLength: 1
81+
type: string
82+
reason:
83+
description: |-
84+
reason is the reason for the condition's last transition in CamelCase.
85+
The specific API may choose whether or not this field is considered a guaranteed API.
86+
This field may be empty.
87+
maxLength: 256
88+
minLength: 1
89+
type: string
90+
severity:
91+
description: |-
92+
severity provides an explicit classification of Reason code, so the users or machines can immediately
93+
understand the current situation and act accordingly.
94+
The Severity field MUST be set only when Status=False.
95+
maxLength: 32
96+
type: string
97+
status:
98+
description: status of the condition, one of True, False, Unknown.
99+
type: string
100+
type:
101+
description: |-
102+
type of condition in CamelCase or in foo.example.com/CamelCase.
103+
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
104+
can be useful (see .node.status.conditions), the ability to deconflict is important.
105+
maxLength: 256
106+
minLength: 1
107+
type: string
108+
required:
109+
- lastTransitionTime
110+
- status
111+
- type
112+
type: object
113+
type: array
114+
dataSecretName:
115+
description: DataSecretName is the name of the secret that stores
116+
the bootstrap data script.
117+
type: string
118+
failureMessage:
119+
description: FailureMessage will be set on non-retryable errors
120+
type: string
121+
failureReason:
122+
description: FailureReason will be set on non-retryable errors
123+
type: string
124+
observedGeneration:
125+
description: ObservedGeneration is the latest generation observed
126+
by the controller.
127+
format: int64
128+
type: integer
129+
ready:
130+
description: Ready indicates the BootstrapData secret is ready to
131+
be consumed
132+
type: boolean
133+
type: object
134+
type: object
135+
served: true
136+
storage: true
137+
subresources:
138+
status: {}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.17.3
7+
name: gkeconfigtemplates.bootstrap.cluster.x-k8s.io
8+
spec:
9+
group: bootstrap.cluster.x-k8s.io
10+
names:
11+
categories:
12+
- cluster-api
13+
kind: GKEConfigTemplate
14+
listKind: GKEConfigTemplateList
15+
plural: gkeconfigtemplates
16+
shortNames:
17+
- gkect
18+
singular: gkeconfigtemplate
19+
scope: Namespaced
20+
versions:
21+
- name: v1beta1
22+
schema:
23+
openAPIV3Schema:
24+
description: GKEConfigTemplate is the GCP GKE Bootstrap Configuration Template
25+
API.
26+
properties:
27+
apiVersion:
28+
description: |-
29+
APIVersion defines the versioned schema of this representation of an object.
30+
Servers should convert recognized schemas to the latest internal value, and
31+
may reject unrecognized values.
32+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
33+
type: string
34+
kind:
35+
description: |-
36+
Kind is a string value representing the REST resource this object represents.
37+
Servers may infer this from the endpoint the client submits requests to.
38+
Cannot be updated.
39+
In CamelCase.
40+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
41+
type: string
42+
metadata:
43+
type: object
44+
spec:
45+
description: GKEConfigTemplateSpec defines the desired state of templated
46+
GKEConfig GCP GKE Bootstrap Configuration resources.
47+
properties:
48+
template:
49+
description: GKEConfigTemplateResource defines the Template structure.
50+
properties:
51+
spec:
52+
description: GKEConfigSpec defines the desired state of GCP GKE
53+
Bootstrap Configuration.
54+
type: object
55+
type: object
56+
required:
57+
- template
58+
type: object
59+
type: object
60+
served: true
61+
storage: true

0 commit comments

Comments
 (0)