@@ -226,7 +226,7 @@ func (r *HetznerClusterReconciler) reconcileNormal(ctx context.Context, clusterS
226226 // target cluster is ready
227227 conditions .MarkTrue (hetznerCluster , infrav1 .TargetClusterReadyCondition )
228228
229- result , err = reconcileWorkloadClusterSecret (ctx , clusterScope )
229+ result , err = reconcileWorkloadClusterSecrets (ctx , clusterScope )
230230 if err != nil {
231231 reterr := fmt .Errorf ("failed to reconcile target secret: %w" , err )
232232 conditions .MarkFalse (
@@ -472,10 +472,12 @@ func hcloudTokenErrorResult(
472472 return res , nil
473473}
474474
475- // reconcileWorkloadClusterSecret ensures that the workload-cluster has the secret needed by the ccm. The
476- // name of the secret is read from HetznerCluster.Spec.HetznerSecret.Name. Creating the secret gets
477- // skipped, if HetznerCluster.Spec.SkipCreatingHetznerSecretInWorkloadCluster is set.
478- func reconcileWorkloadClusterSecret (ctx context.Context , clusterScope * scope.ClusterScope ) (res reconcile.Result , reterr error ) {
475+ // reconcileWorkloadClusterSecrets ensures that the workload-cluster has the secret needed by the
476+ // ccm. The name of the secret is read from HetznerCluster.Spec.HetznerSecret.Name. If
477+ // HetznerSecret.Name is "hcloud", then only one secret gets created in the wl-cluster. If not, two
478+ // secrets are created in the wl-cluster. This ensures compatiblity between CCMs. Creating the
479+ // secret gets skipped, if HetznerCluster.Spec.SkipCreatingHetznerSecretInWorkloadCluster is set.
480+ func reconcileWorkloadClusterSecrets (ctx context.Context , clusterScope * scope.ClusterScope ) (res reconcile.Result , reterr error ) {
479481 if clusterScope .HetznerCluster .Spec .SkipCreatingHetznerSecretInWorkloadCluster {
480482 // If the secret should not be created in the workload cluster, we just return.
481483 // This means the ccm is running outside of the workload cluster (or getting the secret differently).
@@ -514,15 +516,33 @@ func reconcileWorkloadClusterSecret(ctx context.Context, clusterScope *scope.Clu
514516 return reconcile.Result {}, fmt .Errorf ("failed to get client: %w" , err )
515517 }
516518
519+ // To ensure compatibilty with both CCMs, create always a secret with name "hcloud" in the
520+ // wl-cluster.
521+ names := []string {clusterScope .HetznerCluster .Spec .HetznerSecret .Name }
522+ if clusterScope .HetznerCluster .Spec .HetznerSecret .Name != "hcloud" {
523+ names = append (names , "hcloud" )
524+ }
525+
526+ for _ , name := range names {
527+ err = reconcileOneWorkloadClusterSecret (ctx , clusterScope , wlClient , name )
528+ if err != nil {
529+ return reconcile.Result {}, fmt .Errorf ("failed to reconcile wl-cluster secret %q: %w" ,
530+ name , err )
531+ }
532+ }
533+ return reconcile.Result {}, nil
534+ }
535+
536+ func reconcileOneWorkloadClusterSecret (ctx context.Context , clusterScope * scope.ClusterScope , wlClient client.Client , name string ) error {
517537 wlSecret := & corev1.Secret {
518538 ObjectMeta : metav1.ObjectMeta {
519- Name : clusterScope . HetznerCluster . Spec . HetznerSecret . Name ,
539+ Name : name ,
520540 Namespace : metav1 .NamespaceSystem ,
521541 },
522542 }
523543
524544 // Make sure secret exists and has the expected values
525- _ , err = controllerutil .CreateOrUpdate (ctx , wlClient , wlSecret , func () error {
545+ _ , err : = controllerutil .CreateOrUpdate (ctx , wlClient , wlSecret , func () error {
526546 mgtSecretName := types.NamespacedName {
527547 Namespace : clusterScope .HetznerCluster .Namespace ,
528548 Name : clusterScope .HetznerCluster .Spec .HetznerSecret .Name ,
@@ -576,10 +596,10 @@ func reconcileWorkloadClusterSecret(ctx context.Context, clusterScope *scope.Clu
576596 return nil
577597 })
578598 if err != nil {
579- return reconcile. Result {}, fmt .Errorf ("failed to create or update secret: %w" , err )
599+ return fmt .Errorf ("failed to create or update secret: %w" , err )
580600 }
581601
582- return res , nil
602+ return nil
583603}
584604
585605func (r * HetznerClusterReconciler ) reconcileTargetClusterManager (ctx context.Context , clusterScope * scope.ClusterScope ) (res reconcile.Result , err error ) {
0 commit comments