@@ -85,7 +85,7 @@ func (r *KubeadmConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
85
85
Complete (r )
86
86
}
87
87
88
- // Reconcile TODO
88
+ // Reconcile handles KubeadmConfig events
89
89
func (r * KubeadmConfigReconciler ) Reconcile (req ctrl.Request ) (_ ctrl.Result , rerr error ) {
90
90
ctx := context .Background ()
91
91
log := r .Log .WithValues ("kubeadmconfig" , req .NamespacedName )
@@ -380,7 +380,7 @@ func (r *KubeadmConfigReconciler) ClusterToKubeadmConfigs(o handler.MapObject) [
380
380
return result
381
381
}
382
382
383
- // reconcileDiscovery ensure that config.JoinConfiguration.Discovery is properly set for the joining node.
383
+ // reconcileDiscovery ensures that config.JoinConfiguration.Discovery is properly set for the joining node.
384
384
// The implementation func respect user provided discovery configurations, but in case some of them are missing, a valid BootstrapToken object
385
385
// is automatically injected into config.JoinConfiguration.Discovery.
386
386
// This allows to simplify configuration UX, by providing the option to delegate to CABPK the configuration of kubeadm join discovery.
@@ -398,8 +398,8 @@ func (r *KubeadmConfigReconciler) reconcileDiscovery(cluster *clusterv1.Cluster,
398
398
}
399
399
400
400
// if BootstrapToken already contains an APIServerEndpoint, respect it; otherwise inject the APIServerEndpoint endpoint defined in cluster status
401
- //TODO(fp) might be we want to validate user provided APIServerEndpoint and warn/error if it doesn't match the api endpoint defined at cluster level
402
401
apiServerEndpoint := config .Spec .JoinConfiguration .Discovery .BootstrapToken .APIServerEndpoint
402
+ needValidateAPIEndpoints := true
403
403
if apiServerEndpoint == "" {
404
404
if len (cluster .Status .APIEndpoints ) == 0 {
405
405
return errors .Wrap (& capierrors.RequeueAfterError {RequeueAfter : 10 * time .Second }, "Waiting for Cluster Controller to set cluster.Status.APIEndpoints" )
@@ -409,6 +409,21 @@ func (r *KubeadmConfigReconciler) reconcileDiscovery(cluster *clusterv1.Cluster,
409
409
apiServerEndpoint = fmt .Sprintf ("%s:%d" , cluster .Status .APIEndpoints [0 ].Host , cluster .Status .APIEndpoints [0 ].Port )
410
410
config .Spec .JoinConfiguration .Discovery .BootstrapToken .APIServerEndpoint = apiServerEndpoint
411
411
log .Info ("Altering JoinConfiguration.Discovery.BootstrapToken" , "APIServerEndpoint" , apiServerEndpoint )
412
+ needValidateAPIEndpoints = false
413
+ }
414
+ // validate user provided APIServerEndpoint matches the api endpoint defined at cluster level
415
+ if needValidateAPIEndpoints {
416
+ found := false
417
+ for _ , APIEndpoint := range cluster .Status .APIEndpoints {
418
+ if apiServerEndpoint == fmt .Sprintf ("%s:%d" , APIEndpoint .Host , APIEndpoint .Port ) {
419
+ found = true
420
+ break
421
+ }
422
+ }
423
+ if ! found {
424
+ err := errors .Errorf ("the provided APIServerEndpoint %v does not match any api endpoint defined at cluster %v" , apiServerEndpoint , cluster .Status .APIEndpoints )
425
+ log .Error (err , "found mismatched configuration" )
426
+ }
412
427
}
413
428
414
429
// if BootstrapToken already contains a token, respect it; otherwise create a new bootstrap token for the node to join
0 commit comments