@@ -73,8 +73,28 @@ type ControlPlaneBuiltins struct {
73
73
// being orchestrated.
74
74
Version string `json:"version,omitempty"`
75
75
76
+ // Name is the name of the ControlPlane,
77
+ // to which the current template belongs to.
78
+ Name string `json:"name,omitempty"`
79
+
76
80
// Replicas is the value of the replicas field of the ControlPlane object.
77
81
Replicas * int64 `json:"replicas,omitempty"`
82
+
83
+ // MachineTemplate is the value of the .spec.machineTemplate field of the ControlPlane object.
84
+ MachineTemplate * ControlPlaneMachineTemplateBuiltins `json:"machineTemplate,omitempty"`
85
+ }
86
+
87
+ // ControlPlaneMachineTemplateBuiltins is the value of the .spec.machineTemplate field of the ControlPlane object.
88
+ type ControlPlaneMachineTemplateBuiltins struct {
89
+ // InfrastructureRef is the value of the infrastructureRef field of ControlPlane.spec.machineTemplate.
90
+ InfrastructureRef ControlPlaneMachineTemplateInfrastructureRefBuiltins `json:"infrastructureRef,omitempty"`
91
+ }
92
+
93
+ // ControlPlaneMachineTemplateInfrastructureRefBuiltins is the value of the infrastructureRef field of
94
+ // ControlPlane.spec.machineTemplate.
95
+ type ControlPlaneMachineTemplateInfrastructureRefBuiltins struct {
96
+ // Name of the infrastructureRef.
97
+ Name string `json:"name,omitempty"`
78
98
}
79
99
80
100
// MachineDeploymentBuiltins represents builtin MachineDeployment variables.
@@ -102,6 +122,33 @@ type MachineDeploymentBuiltins struct {
102
122
// Replicas is the value of the replicas field of the MachineDeployment,
103
123
// to which the current template belongs to.
104
124
Replicas * int64 `json:"replicas,omitempty"`
125
+
126
+ // Bootstrap is the value of the .spec.template.spec.bootstrap field of the MachineDeployment.
127
+ Bootstrap * MachineDeploymentBootstrapBuiltins `json:"bootstrap,omitempty"`
128
+
129
+ // InfrastructureRef is the value of the .spec.template.spec.bootstrap field of the MachineDeployment.
130
+ InfrastructureRef * MachineDeploymentInfrastructureRefBuiltins `json:"infrastructureRef,omitempty"`
131
+ }
132
+
133
+ // MachineDeploymentBootstrapBuiltins is the value of the .spec.template.spec.bootstrap field
134
+ // of the MachineDeployment.
135
+ type MachineDeploymentBootstrapBuiltins struct {
136
+ // ConfigRef is the value of the .spec.template.spec.bootstrap.configRef field of the MachineDeployment.
137
+ ConfigRef * MachineDeploymentBootstrapConfigRefBuiltins `json:"configRef,omitempty"`
138
+ }
139
+
140
+ // MachineDeploymentBootstrapConfigRefBuiltins is the value of the .spec.template.spec.bootstrap.configRef
141
+ // field of the MachineDeployment.
142
+ type MachineDeploymentBootstrapConfigRefBuiltins struct {
143
+ // Name of the bootstrap.configRef.
144
+ Name string `json:"name,omitempty"`
145
+ }
146
+
147
+ // MachineDeploymentInfrastructureRefBuiltins is the value of the .spec.template.spec.infrastructureRef field
148
+ // of the MachineDeployment.
149
+ type MachineDeploymentInfrastructureRefBuiltins struct {
150
+ // Name of the infrastructureRef.
151
+ Name string `json:"name,omitempty"`
105
152
}
106
153
107
154
// VariableMap is a name/value map of variables.
@@ -139,32 +186,42 @@ func Global(clusterTopology *clusterv1.Topology, cluster *clusterv1.Cluster) (Va
139
186
}
140
187
141
188
// ControlPlane returns variables that apply to templates belonging to the ControlPlane.
142
- func ControlPlane (controlPlaneTopology * clusterv1.ControlPlaneTopology , controlPlane * unstructured.Unstructured ) (VariableMap , error ) {
189
+ func ControlPlane (cpTopology * clusterv1.ControlPlaneTopology , cp , cpInfrastructureMachineTemplate * unstructured.Unstructured ) (VariableMap , error ) {
143
190
variables := VariableMap {}
144
191
145
192
// Construct builtin variable.
146
193
builtin := Builtins {
147
- ControlPlane : & ControlPlaneBuiltins {},
194
+ ControlPlane : & ControlPlaneBuiltins {
195
+ Name : cp .GetName (),
196
+ },
148
197
}
149
198
150
199
// If it is required to manage the number of replicas for the ControlPlane, set the corresponding variable.
151
200
// NOTE: If the Cluster.spec.topology.controlPlane.replicas field is nil, the topology reconciler won't set
152
201
// the replicas field on the ControlPlane. This happens either when the ControlPlane provider does
153
202
// not implement support for this field or the default value of the ControlPlane is used.
154
- if controlPlaneTopology .Replicas != nil {
155
- replicas , err := contract .ControlPlane ().Replicas ().Get (controlPlane )
203
+ if cpTopology .Replicas != nil {
204
+ replicas , err := contract .ControlPlane ().Replicas ().Get (cp )
156
205
if err != nil {
157
206
return nil , errors .Wrap (err , "failed to get spec.replicas from the ControlPlane" )
158
207
}
159
208
builtin .ControlPlane .Replicas = replicas
160
209
}
161
210
162
- version , err := contract .ControlPlane ().Version ().Get (controlPlane )
211
+ version , err := contract .ControlPlane ().Version ().Get (cp )
163
212
if err != nil {
164
213
return nil , errors .Wrap (err , "failed to get spec.version from the ControlPlane" )
165
214
}
166
215
builtin .ControlPlane .Version = * version
167
216
217
+ if cpInfrastructureMachineTemplate != nil {
218
+ builtin .ControlPlane .MachineTemplate = & ControlPlaneMachineTemplateBuiltins {
219
+ InfrastructureRef : ControlPlaneMachineTemplateInfrastructureRefBuiltins {
220
+ Name : cpInfrastructureMachineTemplate .GetName (),
221
+ },
222
+ }
223
+ }
224
+
168
225
if err := setVariable (variables , BuiltinsName , builtin ); err != nil {
169
226
return nil , err
170
227
}
@@ -173,7 +230,7 @@ func ControlPlane(controlPlaneTopology *clusterv1.ControlPlaneTopology, controlP
173
230
}
174
231
175
232
// MachineDeployment returns variables that apply to templates belonging to a MachineDeployment.
176
- func MachineDeployment (mdTopology * clusterv1.MachineDeploymentTopology , md * clusterv1.MachineDeployment ) (VariableMap , error ) {
233
+ func MachineDeployment (mdTopology * clusterv1.MachineDeploymentTopology , md * clusterv1.MachineDeployment , mdBootstrapTemplate , mdInfrastructureMachineTemplate * unstructured. Unstructured ) (VariableMap , error ) {
177
234
variables := VariableMap {}
178
235
179
236
// Add variables overrides for the MachineDeployment.
@@ -196,6 +253,20 @@ func MachineDeployment(mdTopology *clusterv1.MachineDeploymentTopology, md *clus
196
253
builtin .MachineDeployment .Replicas = pointer .Int64 (int64 (* md .Spec .Replicas ))
197
254
}
198
255
256
+ if mdBootstrapTemplate != nil {
257
+ builtin .MachineDeployment .Bootstrap = & MachineDeploymentBootstrapBuiltins {
258
+ ConfigRef : & MachineDeploymentBootstrapConfigRefBuiltins {
259
+ Name : mdBootstrapTemplate .GetName (),
260
+ },
261
+ }
262
+ }
263
+
264
+ if mdInfrastructureMachineTemplate != nil {
265
+ builtin .MachineDeployment .InfrastructureRef = & MachineDeploymentInfrastructureRefBuiltins {
266
+ Name : mdInfrastructureMachineTemplate .GetName (),
267
+ }
268
+ }
269
+
199
270
if err := setVariable (variables , BuiltinsName , builtin ); err != nil {
200
271
return nil , err
201
272
}
0 commit comments