Skip to content

Commit 92f42c4

Browse files
rsmittytalos-bot
authored andcommitted
fix: ensure secrets are deleted when cluster is dropped
This PR fixes a bug where we left cert secrets behind after a cluster was deleted. This led to a case where clusters created with the same name would have issues. Signed-off-by: Spencer Smith <[email protected]>
1 parent 2487307 commit 92f42c4

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

controllers/secrets.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package controllers
1818
import (
1919
"context"
2020

21-
bootstrapv1alpha2 "github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha2"
2221
bootstrapv1alpha3 "github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha3"
2322
"github.com/talos-systems/crypto/x509"
2423
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/generate"
@@ -69,7 +68,7 @@ func (r *TalosConfigReconciler) writeInputSecret(ctx context.Context, scope *Tal
6968
clusterv1.ClusterLabelName: scope.Cluster.Name,
7069
},
7170
OwnerReferences: []metav1.OwnerReference{
72-
*metav1.NewControllerRef(scope.Cluster, bootstrapv1alpha3.GroupVersion.WithKind("Cluster")),
71+
*metav1.NewControllerRef(scope.Cluster, clusterv1.GroupVersion.WithKind("Cluster")),
7372
},
7473
},
7574
Data: map[string][]byte{
@@ -98,7 +97,7 @@ func (r *TalosConfigReconciler) writeK8sCASecret(ctx context.Context, scope *Tal
9897
clusterv1.ClusterLabelName: scope.Cluster.Name,
9998
},
10099
OwnerReferences: []metav1.OwnerReference{
101-
*metav1.NewControllerRef(scope.Cluster, bootstrapv1alpha3.GroupVersion.WithKind("Cluster")),
100+
*metav1.NewControllerRef(scope.Cluster, clusterv1.GroupVersion.WithKind("Cluster")),
102101
},
103102
},
104103
Data: map[string][]byte{
@@ -153,20 +152,3 @@ func (r *TalosConfigReconciler) writeBootstrapData(ctx context.Context, scope *T
153152

154153
return nil
155154
}
156-
157-
func (r *TalosConfigReconciler) deleteSecret(ctx context.Context, config *bootstrapv1alpha2.TalosConfig, secretName string) error {
158-
err := r.Client.Delete(ctx,
159-
&corev1.Secret{
160-
ObjectMeta: metav1.ObjectMeta{
161-
Namespace: config.GetNamespace(),
162-
Name: secretName,
163-
},
164-
},
165-
)
166-
167-
if err != nil && !k8serrors.IsNotFound(err) {
168-
return err
169-
}
170-
171-
return nil
172-
}

0 commit comments

Comments
 (0)