Skip to content

Commit

Permalink
Merge pull request #851 from Danil-Grigorev/rke2-config-filter
Browse files Browse the repository at this point in the history
🌱 Patch RKE2 config only for CP machines
  • Loading branch information
salasberryfin authored Nov 13, 2024
2 parents 32a1e82 + abcaf4d commit 4069641
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit 4069641

Please sign in to comment.