Skip to content

Commit

Permalink
fix: ensure talosconfigs are created w/o controller=true in ownerref
Browse files Browse the repository at this point in the history
This PR fixes a bug we were seeing where the ownerref that was getting
created by the taloscontrolplane was using a helper function and that
function set the controller: true in the ownerref. This keeps CAPI from
adding its own Machine ownerref to a given talosconfig because it
expects to be the controller for it.

Signed-off-by: Spencer Smith <[email protected]>
  • Loading branch information
rsmitty authored and talos-bot committed Sep 23, 2020
1 parent e80ade0 commit 8f13198
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions controllers/taloscontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/utils/pointer"
capiv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
"sigs.k8s.io/cluster-api/controllers/external"
Expand Down Expand Up @@ -386,13 +387,19 @@ func (r *TalosControlPlaneReconciler) bootControlPlane(ctx context.Context, clus
}

func (r *TalosControlPlaneReconciler) generateTalosConfig(ctx context.Context, tcp *controlplanev1.TalosControlPlane, cluster *capiv1.Cluster, spec *cabptv1.TalosConfigSpec) (*corev1.ObjectReference, error) {
owner := metav1.OwnerReference{
APIVersion: controlplanev1.GroupVersion.String(),
Kind: "TalosControlPlane",
Name: tcp.Name,
UID: tcp.UID,
BlockOwnerDeletion: pointer.BoolPtr(true),
}

bootstrapConfig := &cabptv1.TalosConfig{
ObjectMeta: metav1.ObjectMeta{
Name: names.SimpleNameGenerator.GenerateName(tcp.Name + "-"),
Namespace: tcp.Namespace,
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(tcp, controlplanev1.GroupVersion.WithKind("TalosControlPlane")),
},
Name: names.SimpleNameGenerator.GenerateName(tcp.Name + "-"),
Namespace: tcp.Namespace,
OwnerReferences: []metav1.OwnerReference{owner},
},
Spec: *spec,
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
k8s.io/apimachinery v0.17.2
k8s.io/apiserver v0.17.2
k8s.io/client-go v0.17.2
k8s.io/utils v0.0.0-20200229041039-0a110f9eb7ab
sigs.k8s.io/cluster-api v0.3.5
sigs.k8s.io/controller-runtime v0.5.3
)

0 comments on commit 8f13198

Please sign in to comment.