Skip to content

Commit 7dde1cb

Browse files
rsmittytalos-bot
authored andcommitted
fix: ensure proper ownership of certs
This PR fixes a bug where the bootstrap provider didn't own the certs it created, they were owned by the cluster instead. This leads to a case where, if control plane machines were cleaned up, the CA secret was still present. I've moved ownership to be the TalosConfig and updated how I set those owners based on what the kubeadm bootstrapper does. I crosschecked what the owner is supposed to be by running this function down: https://github.com/kubernetes-sigs/cluster-api/blob/v0.3.8/bootstrap/kubeadm/controllers/kubeadmconfig_controller.go#L376 Signed-off-by: Spencer Smith <[email protected]>
1 parent 31f99d0 commit 7dde1cb

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

controllers/secrets.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
corev1 "k8s.io/api/core/v1"
2727
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29-
"k8s.io/utils/pointer"
3029
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
3130
"sigs.k8s.io/controller-runtime/pkg/client"
3231
)
@@ -70,12 +69,7 @@ func (r *TalosConfigReconciler) writeInputSecret(ctx context.Context, scope *Tal
7069
clusterv1.ClusterLabelName: scope.Cluster.Name,
7170
},
7271
OwnerReferences: []metav1.OwnerReference{
73-
metav1.OwnerReference{
74-
APIVersion: clusterv1.GroupVersion.String(),
75-
Kind: "Cluster",
76-
Name: scope.Cluster.Name,
77-
UID: scope.Cluster.UID,
78-
},
72+
*metav1.NewControllerRef(scope.Config, bootstrapv1alpha3.GroupVersion.WithKind("TalosConfig")),
7973
},
8074
},
8175
Data: map[string][]byte{
@@ -104,12 +98,7 @@ func (r *TalosConfigReconciler) writeK8sCASecret(ctx context.Context, scope *Tal
10498
clusterv1.ClusterLabelName: scope.Cluster.Name,
10599
},
106100
OwnerReferences: []metav1.OwnerReference{
107-
metav1.OwnerReference{
108-
APIVersion: clusterv1.GroupVersion.String(),
109-
Kind: "Cluster",
110-
Name: scope.Cluster.Name,
111-
UID: scope.Cluster.UID,
112-
},
101+
*metav1.NewControllerRef(scope.Config, bootstrapv1alpha3.GroupVersion.WithKind("TalosConfig")),
113102
},
114103
},
115104
Data: map[string][]byte{
@@ -142,13 +131,7 @@ func (r *TalosConfigReconciler) writeBootstrapData(ctx context.Context, scope *T
142131
clusterv1.ClusterLabelName: scope.Cluster.Name,
143132
},
144133
OwnerReferences: []metav1.OwnerReference{
145-
{
146-
APIVersion: bootstrapv1alpha3.GroupVersion.String(),
147-
Kind: "TalosConfig",
148-
Name: scope.Config.Name,
149-
UID: scope.Config.UID,
150-
Controller: pointer.BoolPtr(true),
151-
},
134+
*metav1.NewControllerRef(scope.Config, bootstrapv1alpha3.GroupVersion.WithKind("TalosConfig")),
152135
},
153136
},
154137
Data: map[string][]byte{

0 commit comments

Comments
 (0)