Skip to content

Commit e4629ab

Browse files
authored
🌱 Enable integration tests of RuntimeExtensions (#10330)
* Export ClusterClass controller Reconcile * Export BuiltinVariables and variable util funcs * Export webhooks.Cluster DefaultAndValidateVariables method Signed-off-by: Stefan Büringer buringerst@vmware.com * Export desired state computation * Export scope for desired state computation * Add integration test to test extension * Address review comments * Regenerate openapi.go * Move desired/scope to scope * Address review comments --------- Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent 5baca0f commit e4629ab

Some content is hidden

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

56 files changed

+2324
-716
lines changed

cmd/clusterctl/client/cluster/topology.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ func reconcileClusterClass(ctx context.Context, apiReader client.Reader, class c
516516

517517
clusterClassReconciler := &clusterclasscontroller.Reconciler{
518518
Client: reconcilerClient,
519-
APIReader: reconcilerClient,
520519
UnstructuredCachingClient: reconcilerClient,
521520
}
522521

controllers/alias.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,11 @@ func (r *MachineSetTopologyReconciler) SetupWithManager(ctx context.Context, mgr
212212

213213
// ClusterClassReconciler reconciles the ClusterClass object.
214214
type ClusterClassReconciler struct {
215-
Client client.Client
216-
APIReader client.Reader
215+
// internalReconciler is used to store the reconciler after SetupWithManager
216+
// so that the Reconcile function can work.
217+
internalReconciler *clusterclasscontroller.Reconciler
218+
219+
Client client.Client
217220

218221
// RuntimeClient is a client for calling runtime extensions.
219222
RuntimeClient runtimeclient.Client
@@ -227,11 +230,20 @@ type ClusterClassReconciler struct {
227230
}
228231

229232
func (r *ClusterClassReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
230-
return (&clusterclasscontroller.Reconciler{
233+
r.internalReconciler = &clusterclasscontroller.Reconciler{
231234
Client: r.Client,
232-
APIReader: r.APIReader,
233235
RuntimeClient: r.RuntimeClient,
234236
UnstructuredCachingClient: r.UnstructuredCachingClient,
235237
WatchFilterValue: r.WatchFilterValue,
236-
}).SetupWithManager(ctx, mgr, options)
238+
}
239+
return r.internalReconciler.SetupWithManager(ctx, mgr, options)
240+
}
241+
242+
// Reconcile can be used to reconcile a ClusterClass.
243+
// Before it can be used, all fields of the ClusterClassReconciler have to be set
244+
// and SetupWithManager has to be called.
245+
// This method can be used when testing the behavior of the desired state computation of
246+
// the Cluster topology controller (because that requires a reconciled ClusterClass).
247+
func (r *ClusterClassReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
248+
return r.internalReconciler.Reconcile(ctx, req)
237249
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
// BuiltinsName is the name of the builtin variable.
20+
const BuiltinsName = "builtin"
21+
22+
// Builtins represents builtin variables exposed through patches.
23+
type Builtins struct {
24+
Cluster *ClusterBuiltins `json:"cluster,omitempty"`
25+
ControlPlane *ControlPlaneBuiltins `json:"controlPlane,omitempty"`
26+
MachineDeployment *MachineDeploymentBuiltins `json:"machineDeployment,omitempty"`
27+
MachinePool *MachinePoolBuiltins `json:"machinePool,omitempty"`
28+
}
29+
30+
// ClusterBuiltins represents builtin cluster variables.
31+
type ClusterBuiltins struct {
32+
// Name is the name of the cluster.
33+
Name string `json:"name,omitempty"`
34+
35+
// Namespace is the namespace of the cluster.
36+
Namespace string `json:"namespace,omitempty"`
37+
38+
// Topology represents the cluster topology variables.
39+
Topology *ClusterTopologyBuiltins `json:"topology,omitempty"`
40+
41+
// Network represents the cluster network variables.
42+
Network *ClusterNetworkBuiltins `json:"network,omitempty"`
43+
}
44+
45+
// ClusterTopologyBuiltins represents builtin cluster topology variables.
46+
type ClusterTopologyBuiltins struct {
47+
// Version is the Kubernetes version of the Cluster.
48+
// NOTE: Please note that this version might temporarily differ from the version
49+
// of the ControlPlane or workers while an upgrade process is being orchestrated.
50+
Version string `json:"version,omitempty"`
51+
52+
// Class is the name of the ClusterClass of the Cluster.
53+
Class string `json:"class,omitempty"`
54+
}
55+
56+
// ClusterNetworkBuiltins represents builtin cluster network variables.
57+
type ClusterNetworkBuiltins struct {
58+
// ServiceDomain is the domain name for services.
59+
ServiceDomain *string `json:"serviceDomain,omitempty"`
60+
// Services is the network ranges from which service VIPs are allocated.
61+
Services []string `json:"services,omitempty"`
62+
// Pods is the network ranges from which Pod networks are allocated.
63+
Pods []string `json:"pods,omitempty"`
64+
// IPFamily is the IPFamily the Cluster is operating in. One of Invalid, IPv4, IPv6, DualStack.
65+
// Note: IPFamily is not a concept in Kubernetes. It was originally introduced in CAPI for CAPD.
66+
// IPFamily may be dropped in a future release. More details at https://github.com/kubernetes-sigs/cluster-api/issues/7521
67+
IPFamily string `json:"ipFamily,omitempty"`
68+
}
69+
70+
// ControlPlaneBuiltins represents builtin ControlPlane variables.
71+
// NOTE: These variables are only set for templates belonging to the ControlPlane object.
72+
type ControlPlaneBuiltins struct {
73+
// Version is the Kubernetes version of the ControlPlane object.
74+
// NOTE: Please note that this version is the version we are currently reconciling towards.
75+
// It can differ from the current version of the ControlPlane while an upgrade process is
76+
// being orchestrated.
77+
Version string `json:"version,omitempty"`
78+
79+
// Name is the name of the ControlPlane,
80+
// to which the current template belongs to.
81+
Name string `json:"name,omitempty"`
82+
83+
// Replicas is the value of the replicas field of the ControlPlane object.
84+
Replicas *int64 `json:"replicas,omitempty"`
85+
86+
// MachineTemplate is the value of the .spec.machineTemplate field of the ControlPlane object.
87+
MachineTemplate *ControlPlaneMachineTemplateBuiltins `json:"machineTemplate,omitempty"`
88+
}
89+
90+
// ControlPlaneMachineTemplateBuiltins is the value of the .spec.machineTemplate field of the ControlPlane object.
91+
type ControlPlaneMachineTemplateBuiltins struct {
92+
// InfrastructureRef is the value of the infrastructureRef field of ControlPlane.spec.machineTemplate.
93+
InfrastructureRef ControlPlaneMachineTemplateInfrastructureRefBuiltins `json:"infrastructureRef,omitempty"`
94+
}
95+
96+
// ControlPlaneMachineTemplateInfrastructureRefBuiltins is the value of the infrastructureRef field of
97+
// ControlPlane.spec.machineTemplate.
98+
type ControlPlaneMachineTemplateInfrastructureRefBuiltins struct {
99+
// Name of the infrastructureRef.
100+
Name string `json:"name,omitempty"`
101+
}
102+
103+
// MachineDeploymentBuiltins represents builtin MachineDeployment variables.
104+
// NOTE: These variables are only set for templates belonging to a MachineDeployment.
105+
type MachineDeploymentBuiltins struct {
106+
// Version is the Kubernetes version of the MachineDeployment,
107+
// to which the current template belongs to.
108+
// NOTE: Please note that this version is the version we are currently reconciling towards.
109+
// It can differ from the current version of the MachineDeployment machines while an upgrade process is
110+
// being orchestrated.
111+
Version string `json:"version,omitempty"`
112+
113+
// Class is the class name of the MachineDeployment,
114+
// to which the current template belongs to.
115+
Class string `json:"class,omitempty"`
116+
117+
// Name is the name of the MachineDeployment,
118+
// to which the current template belongs to.
119+
Name string `json:"name,omitempty"`
120+
121+
// TopologyName is the topology name of the MachineDeployment,
122+
// to which the current template belongs to.
123+
TopologyName string `json:"topologyName,omitempty"`
124+
125+
// Replicas is the value of the replicas field of the MachineDeployment,
126+
// to which the current template belongs to.
127+
Replicas *int64 `json:"replicas,omitempty"`
128+
129+
// Bootstrap is the value of the .spec.template.spec.bootstrap field of the MachineDeployment.
130+
Bootstrap *MachineBootstrapBuiltins `json:"bootstrap,omitempty"`
131+
132+
// InfrastructureRef is the value of the .spec.template.spec.infrastructureRef field of the MachineDeployment.
133+
InfrastructureRef *MachineInfrastructureRefBuiltins `json:"infrastructureRef,omitempty"`
134+
}
135+
136+
// MachinePoolBuiltins represents builtin MachinePool variables.
137+
// NOTE: These variables are only set for templates belonging to a MachinePool.
138+
type MachinePoolBuiltins struct {
139+
// Version is the Kubernetes version of the MachinePool,
140+
// to which the current template belongs to.
141+
// NOTE: Please note that this version is the version we are currently reconciling towards.
142+
// It can differ from the current version of the MachinePool machines while an upgrade process is
143+
// being orchestrated.
144+
Version string `json:"version,omitempty"`
145+
146+
// Class is the class name of the MachinePool,
147+
// to which the current template belongs to.
148+
Class string `json:"class,omitempty"`
149+
150+
// Name is the name of the MachinePool,
151+
// to which the current template belongs to.
152+
Name string `json:"name,omitempty"`
153+
154+
// TopologyName is the topology name of the MachinePool,
155+
// to which the current template belongs to.
156+
TopologyName string `json:"topologyName,omitempty"`
157+
158+
// Replicas is the value of the replicas field of the MachinePool,
159+
// to which the current template belongs to.
160+
Replicas *int64 `json:"replicas,omitempty"`
161+
162+
// Bootstrap is the value of the .spec.template.spec.bootstrap field of the MachinePool.
163+
Bootstrap *MachineBootstrapBuiltins `json:"bootstrap,omitempty"`
164+
165+
// InfrastructureRef is the value of the .spec.template.spec.infrastructureRef field of the MachinePool.
166+
InfrastructureRef *MachineInfrastructureRefBuiltins `json:"infrastructureRef,omitempty"`
167+
}
168+
169+
// MachineBootstrapBuiltins is the value of the .spec.template.spec.bootstrap field
170+
// of the MachineDeployment or MachinePool.
171+
type MachineBootstrapBuiltins struct {
172+
// ConfigRef is the value of the .spec.template.spec.bootstrap.configRef field of the MachineDeployment.
173+
ConfigRef *MachineBootstrapConfigRefBuiltins `json:"configRef,omitempty"`
174+
}
175+
176+
// MachineBootstrapConfigRefBuiltins is the value of the .spec.template.spec.bootstrap.configRef
177+
// field of the MachineDeployment or MachinePool.
178+
type MachineBootstrapConfigRefBuiltins struct {
179+
// Name of the bootstrap.configRef.
180+
Name string `json:"name,omitempty"`
181+
}
182+
183+
// MachineInfrastructureRefBuiltins is the value of the .spec.template.spec.infrastructureRef field
184+
// of the MachineDeployment or MachinePool.
185+
type MachineInfrastructureRefBuiltins struct {
186+
// Name of the infrastructureRef.
187+
Name string `json:"name,omitempty"`
188+
}

0 commit comments

Comments
 (0)