Skip to content

Commit

Permalink
[release-v1.55] Annotate DIC-created DV for immediate binding (#2656)
Browse files Browse the repository at this point in the history
Manual backport of #2650

If the storage class binding mode is WaitForFirstConsumer, and the
annotation was not explicitly added to the DIC DV template, the created
DV will get stuck in WFFC phase.

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
  • Loading branch information
arnongilboa committed Mar 23, 2023
1 parent b0b2f73 commit 615be26
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/dataimportcron-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ func (r *DataImportCronReconciler) newSourceDataVolume(cron *cdiv1.DataImportCro
dv.Name = dataVolumeName
dv.Namespace = cron.Namespace
r.setDataImportCronResourceLabels(cron, dv)
passCronAnnotationToDv(cron, dv, AnnImmediateBinding)
AddAnnotation(dv, AnnImmediateBinding, "true")
passCronAnnotationToDv(cron, dv, AnnPodRetainAfterCompletion)
return dv
}
Expand Down
13 changes: 4 additions & 9 deletions pkg/controller/dataimportcron-controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ var _ = Describe("All DataImportCron Tests", func() {
reconciler = createDataImportCronReconciler(cron)
verifyConditions("Before DesiredDigest is set", false, false, false, noImport, noDigest, "")

if cron.Annotations == nil {
cron.Annotations = make(map[string]string)
}
cron.Annotations[AnnSourceDesiredDigest] = testDigest
AddAnnotation(cron, AnnSourceDesiredDigest, testDigest)
err := reconciler.client.Update(context.TODO(), cron)
Expect(err).ToNot(HaveOccurred())
dataSource = &cdiv1.DataSource{}
Expand All @@ -338,6 +335,7 @@ var _ = Describe("All DataImportCron Tests", func() {
err = reconciler.client.Get(context.TODO(), dvKey(dvName), dv)
Expect(err).ToNot(HaveOccurred())
Expect(*dv.Spec.Source.Registry.URL).To(Equal(testRegistryURL + "@" + testDigest))
Expect(dv.Annotations[AnnImmediateBinding]).To(Equal("true"))

dv.Status.Phase = cdiv1.ImportScheduled
err = reconciler.client.Update(context.TODO(), dv)
Expand Down Expand Up @@ -405,14 +403,10 @@ var _ = Describe("All DataImportCron Tests", func() {
Expect(err).ToNot(HaveOccurred())
}

if cron.Annotations == nil {
cron.Annotations = make(map[string]string)
}

pvc := &corev1.PersistentVolumeClaim{}
lastTs := ""
verifyDigestUpdate := func(idx int) {
cron.Annotations[AnnSourceDesiredDigest] = digests[idx]
AddAnnotation(cron, AnnSourceDesiredDigest, digests[idx])
err := reconciler.client.Update(context.TODO(), cron)
Expect(err).ToNot(HaveOccurred())
dataSource = &cdiv1.DataSource{}
Expand Down Expand Up @@ -574,6 +568,7 @@ var _ = Describe("All DataImportCron Tests", func() {
err = reconciler.client.Get(context.TODO(), dvKey(dvName), dv)
Expect(err).ToNot(HaveOccurred())
Expect(*dv.Spec.Source.Registry.URL).To(Equal("docker://" + testDockerRef))
Expect(dv.Annotations[AnnImmediateBinding]).To(Equal("true"))
dv.Status.Phase = cdiv1.Succeeded
dv.Status.Conditions = updateReadyCondition(dv.Status.Conditions, corev1.ConditionTrue, "", "")
err = reconciler.client.Update(context.TODO(), dv)
Expand Down
2 changes: 1 addition & 1 deletion tests/import_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ var _ = Describe("Import Proxy tests", func() {

By(fmt.Sprintf("Create new DataImportCron %s, url %s", cronName, *reg.URL))
dic := utils.NewDataImportCron(cronName, "5Gi", scheduleEveryMinute, dataSourceName, 1, reg)
dic.Annotations[controller.AnnPodRetainAfterCompletion] = "true"
controller.AddAnnotation(dic, controller.AnnPodRetainAfterCompletion, "true")
retentionPolicy := cdiv1.DataImportCronRetainNone
dic.Spec.RetentionPolicy = &retentionPolicy

Expand Down
4 changes: 0 additions & 4 deletions tests/utils/dataimportcron.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
"kubevirt.io/containerized-data-importer/pkg/controller"
)

// NewDataImportCron initializes a DataImportCron struct
func NewDataImportCron(name, size, schedule, dataSource string, importsToKeep int32, source cdiv1.DataVolumeSourceRegistry) *cdiv1.DataImportCron {
return &cdiv1.DataImportCron{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Annotations: map[string]string{
controller.AnnImmediateBinding: "true",
},
},
Spec: cdiv1.DataImportCronSpec{
Template: cdiv1.DataVolume{
Expand Down

0 comments on commit 615be26

Please sign in to comment.