@@ -73,6 +73,13 @@ type talosConfigContext struct {
73
73
Key string
74
74
}
75
75
76
+ func (r * TalosConfigReconciler ) SetupWithManager (mgr ctrl.Manager , options controller.Options ) error {
77
+ return ctrl .NewControllerManagedBy (mgr ).
78
+ WithOptions (options ).
79
+ For (& bootstrapv1alpha2.TalosConfig {}).
80
+ Complete (r )
81
+ }
82
+
76
83
// +kubebuilder:rbac:groups=bootstrap.cluster.x-k8s.io,resources=talosconfigs,verbs=get;list;watch;create;update;patch;delete
77
84
// +kubebuilder:rbac:groups=bootstrap.cluster.x-k8s.io,resources=talosconfigs/status,verbs=get;update;patch
78
85
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters;clusters/status;machines;machines/status,verbs=get;list;watch
@@ -135,7 +142,7 @@ func (r *TalosConfigReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, rerr
135
142
136
143
// Handle deleted machines
137
144
if ! config .ObjectMeta .DeletionTimestamp .IsZero () {
138
- return r .reconcileDelete (ctx , config , cluster . ObjectMeta . Name )
145
+ return r .reconcileDelete (ctx , config )
139
146
}
140
147
141
148
// bail super early if it's already ready
@@ -187,29 +194,14 @@ func (r *TalosConfigReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, rerr
187
194
return ctrl.Result {}, nil
188
195
}
189
196
190
- func (r * TalosConfigReconciler ) reconcileDelete (ctx context.Context , config * bootstrapv1alpha2.TalosConfig , clusterName string ) (ctrl.Result , error ) {
191
-
192
- if config .Spec .GenerateType == "init" {
193
- err := r .deleteInputSecret (ctx , config , clusterName )
194
- if err != nil {
195
- return ctrl.Result {}, err
196
- }
197
- }
198
-
197
+ func (r * TalosConfigReconciler ) reconcileDelete (ctx context.Context , config * bootstrapv1alpha2.TalosConfig ) (ctrl.Result , error ) {
199
198
// Config is deleted so remove the finalizer.
200
199
config .Finalizers = util .Filter (config .Finalizers , bootstrapv1alpha2 .ConfigFinalizer )
201
200
202
201
return ctrl.Result {}, nil
203
202
204
203
}
205
204
206
- func (r * TalosConfigReconciler ) SetupWithManager (mgr ctrl.Manager , options controller.Options ) error {
207
- return ctrl .NewControllerManagedBy (mgr ).
208
- WithOptions (options ).
209
- For (& bootstrapv1alpha2.TalosConfig {}).
210
- Complete (r )
211
- }
212
-
213
205
func genTalosConfigFile (clusterName string , certs * generate.Certs ) (string , error ) {
214
206
talosConfig := & talosConfig {
215
207
Context : clusterName ,
@@ -241,6 +233,14 @@ func (r *TalosConfigReconciler) userConfigs(ctx context.Context, scope *TalosCon
241
233
return retBundle , err
242
234
}
243
235
236
+ // Create the secret with kubernetes certs so a kubeconfig can be generated
237
+ if userConfig .Machine ().Type () == configmachine .TypeInit {
238
+ err = r .writeK8sCASecret (ctx , scope , userConfig .Cluster ().CA ())
239
+ if err != nil {
240
+ return retBundle , err
241
+ }
242
+ }
243
+
244
244
userConfigStr , err := userConfig .String ()
245
245
if err != nil {
246
246
return retBundle , err
@@ -265,17 +265,29 @@ func (r *TalosConfigReconciler) genConfigs(ctx context.Context, scope *TalosConf
265
265
}
266
266
267
267
APIEndpointPort := strconv .Itoa (scope .Cluster .Status .APIEndpoints [0 ].Port )
268
- input , err := generate .NewInput (scope .Cluster .ObjectMeta . Name ,
268
+ input , err := generate .NewInput (scope .Cluster .Name ,
269
269
"https://" + scope .Cluster .Status .APIEndpoints [0 ].Host + ":" + APIEndpointPort ,
270
270
* scope .Machine .Spec .Version ,
271
271
)
272
272
if err != nil {
273
273
return retBundle , err
274
274
}
275
275
276
- inputSecret , err := r .fetchInputSecret (ctx , scope .Config , scope .Cluster .ObjectMeta .Name )
276
+ // Stash our generated input secrets so that we can reuse them for other nodes
277
+ inputSecret , err := r .fetchSecret (ctx , scope .Config , scope .Cluster .Name + "-talos" )
278
+ if machineType == configmachine .TypeInit && k8serrors .IsNotFound (err ) {
279
+ inputSecret , err = r .writeInputSecret (ctx , scope , input )
280
+ if err != nil {
281
+ return retBundle , err
282
+ }
283
+ } else if err != nil {
284
+ return retBundle , err
285
+ }
286
+
287
+ // Create the secret with kubernetes certs so a kubeconfig can be generated
288
+ _ , err = r .fetchSecret (ctx , scope .Config , scope .Cluster .Name + "-ca" )
277
289
if machineType == configmachine .TypeInit && k8serrors .IsNotFound (err ) {
278
- inputSecret , err = r .writeInputSecret (ctx , scope . Config , scope . Cluster . ObjectMeta . Name , input )
290
+ err = r .writeK8sCASecret (ctx , scope , input . Certs . K8s )
279
291
if err != nil {
280
292
return retBundle , err
281
293
}
0 commit comments