Skip to content

Commit 5504fd4

Browse files
authored
Fix etcd cert secrets owner in hosting cluster mode (#1258)
When K0smotronCluster uses spec.kubeconfigRef, etcd leaf certs (server/peer/apiserver-etcd-client) were generated but not persisted in the hosting cluster due to an incorrect OwnerReference. Use the external owner when present (same as the control-plane certs path) to ensure secrets are created/retained and etcd pods can start. Signed-off-by: kahirokunn <okinakahiro@gmail.com>
1 parent ff93cd1 commit 5504fd4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/controller/k0smotron.io/k0smotroncluster_certs.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"sigs.k8s.io/cluster-api/util/secret"
3535

3636
km "github.com/k0sproject/k0smotron/api/k0smotron.io/v1beta1"
37+
kutil "github.com/k0sproject/k0smotron/internal/controller/util"
3738
)
3839

3940
func (scope *kmcScope) ensureEtcdCertificates(ctx context.Context, kmc *km.Cluster) error {
@@ -114,5 +115,10 @@ func (scope *kmcScope) ensureEtcdCertificates(ctx context.Context, kmc *km.Clust
114115
}
115116
}
116117

117-
return etcdCerts.SaveGenerated(ctx, scope.client, util.ObjectKey(kmc), *metav1.NewControllerRef(kmc, km.GroupVersion.WithKind("Cluster")))
118+
owner := *metav1.NewControllerRef(kmc, km.GroupVersion.WithKind("Cluster"))
119+
if scope.externalOwner != nil {
120+
owner = *kutil.GetExternalControllerRef(scope.externalOwner)
121+
}
122+
123+
return etcdCerts.SaveGenerated(ctx, scope.client, util.ObjectKey(kmc), owner)
118124
}

0 commit comments

Comments
 (0)