@@ -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,7 +398,6 @@ 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
403
402
if apiServerEndpoint == "" {
404
403
if len (cluster .Status .APIEndpoints ) == 0 {
@@ -410,6 +409,10 @@ func (r *KubeadmConfigReconciler) reconcileDiscovery(cluster *clusterv1.Cluster,
410
409
config .Spec .JoinConfiguration .Discovery .BootstrapToken .APIServerEndpoint = apiServerEndpoint
411
410
log .Info ("Altering JoinConfiguration.Discovery.BootstrapToken" , "APIServerEndpoint" , apiServerEndpoint )
412
411
}
412
+ // validate user provided APIServerEndpoint matches the api endpoint defined at cluster level
413
+ if err := validateAPIEndpoints (apiServerEndpoint , cluster .Status .APIEndpoints ); err != nil {
414
+ log .Error (err , "found invalid APIServerEndpoint configuration" )
415
+ }
413
416
414
417
// if BootstrapToken already contains a token, respect it; otherwise create a new bootstrap token for the node to join
415
418
if config .Spec .JoinConfiguration .Discovery .BootstrapToken .Token == "" {
@@ -562,3 +565,17 @@ func (r *KubeadmConfigReconciler) createClusterCertificates(ctx context.Context,
562
565
563
566
return certificates , nil
564
567
}
568
+
569
+ func validateAPIEndpoints (endpoint string , endpoints []clusterv1.APIEndpoint ) error {
570
+ found := false
571
+ for _ , v := range endpoints {
572
+ if endpoint == fmt .Sprintf ("%s:%d" , v .Host , v .Port ) {
573
+ found = true
574
+ break
575
+ }
576
+ }
577
+ if ! found {
578
+ return errors .Errorf ("provided APIServerEndpoint %v does not match any api endpoint defined at cluster %v" , endpoint , endpoints )
579
+ }
580
+ return nil
581
+ }
0 commit comments