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

Re-fetch the VM secret userdata if it was changed #211

Merged
merged 1 commit into from
Mar 28, 2023
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
8 changes: 0 additions & 8 deletions controllers/kubevirtmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,6 @@ func (r *KubevirtMachineReconciler) reconcileKubevirtBootstrapSecret(ctx *contex
return errors.New("error retrieving bootstrap data: linked Machine's bootstrap.dataSecretName is nil")
}

// Exit early if exists.
bootstrapDataSecret := &corev1.Secret{}
bootstrapDataSecretKey := client.ObjectKey{Namespace: vmNamespace, Name: *ctx.Machine.Spec.Bootstrap.DataSecretName + "-userdata"}
if err := infraClusterClient.Get(ctx, bootstrapDataSecretKey, bootstrapDataSecret); err == nil {
ctx.BootstrapDataSecret = bootstrapDataSecret
return nil
}

s := &corev1.Secret{}
key := client.ObjectKey{Namespace: ctx.Machine.GetNamespace(), Name: *ctx.Machine.Spec.Bootstrap.DataSecretName}
if err := r.Client.Get(ctx, key, s); err != nil {
Expand Down
30 changes: 30 additions & 0 deletions controllers/kubevirtmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,36 @@ var _ = Describe("reconcile a kubevirt machine", func() {
Expect(err).ToNot(HaveOccurred())
Expect(out).To(Equal(ctrl.Result{RequeueAfter: 20 * time.Second}))
})

It("should fetch the latest bootstrap secret and update the machine context if changed", func() {
kubevirtMachine.Status.Ready = true
bootstrapSecret.Data["value"] = append(bootstrapSecret.Data["value"], []byte(" some change")...)

objects := []client.Object{
cluster,
kubevirtCluster,
machine,
kubevirtMachine,
sshKeySecret,
bootstrapSecret,
bootstrapUserDataSecret,
}

// test that if the source secret has changed, and there is alredy a secret exist, we still copy the source
// to the dest.
// the source is the bootstrap secret, the dest is the bootstrap user data secret

setupClient(kubevirt.DefaultMachineFactory{}, objects)

infraClusterMock.EXPECT().GenerateInfraClusterClient(kubevirtMachine.Spec.InfraClusterSecretRef, kubevirtMachine.Namespace, machineContext.Context).Return(fakeClient, kubevirtMachine.Namespace, nil)

Expect(machineContext.KubevirtMachine.Status.Ready).To(BeTrue())
out, err := kubevirtMachineReconciler.reconcileNormal(machineContext)
Expect(machineContext.KubevirtMachine.Status.Ready).To(BeFalse())
Expect(err).ToNot(HaveOccurred())
Expect(out).To(Equal(ctrl.Result{RequeueAfter: 20 * time.Second}))
Expect(machineContext.BootstrapDataSecret.Data["userdata"]).To(Equal(bootstrapSecret.Data["value"]))
})
})

var _ = Describe("updateNodeProviderID", func() {
Expand Down