Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Patch RKE2 config only for CP machines #851

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions exp/etcdrestore/webhooks/rke2config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func (r *RKE2ConfigWebhook) Default(ctx context.Context, obj runtime.Object) err
return apierrors.NewBadRequest(fmt.Sprintf("expected a RKE2Config but got a %T", obj))
}

// Deploy agent only on CP machines
if _, found := rke2Config.Labels[clusterv1.MachineControlPlaneLabel]; !found {
return nil
}

if rke2Config.Annotations == nil {
rke2Config.Annotations = map[string]string{}
}
Expand Down
9 changes: 8 additions & 1 deletion exp/etcdrestore/webhooks/rke2config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ var _ = Describe("RKE2ConfigWebhook tests", func() {
UID: "test-uid",
Namespace: ns.Name,
Labels: map[string]string{
clusterv1.ClusterNameLabel: "rke2",
clusterv1.ClusterNameLabel: "rke2",
clusterv1.MachineControlPlaneLabel: "",
},
},
Spec: bootstrapv1.RKE2ConfigSpec{
Expand All @@ -87,6 +88,12 @@ var _ = Describe("RKE2ConfigWebhook tests", func() {
Expect(apierrors.IsBadRequest(err)).To(BeTrue())
})

It("Should skip defaulting for non CP machines", func() {
delete(rke2Config.Labels, clusterv1.MachineControlPlaneLabel)
err := r.Default(ctx, rke2Config)
Expect(err).ToNot(HaveOccurred())
})

It("Should create secret plan resources without error", func() {
err := r.createSecretPlanResources(ctx, rke2Config)
Expect(err).NotTo(HaveOccurred())
Expand Down
Loading