Skip to content

Commit

Permalink
Annotate DIC-created DV for immediate binding (#2650)
Browse files Browse the repository at this point in the history
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 22, 2023
1 parent 7f0f2c9 commit fc7f855
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 @@ -943,7 +943,7 @@ func (r *DataImportCronReconciler) newSourceDataVolume(cron *cdiv1.DataImportCro
dv.Name = dataVolumeName
dv.Namespace = cron.Namespace
r.setDataImportCronResourceLabels(cron, dv)
passCronAnnotationToDv(cron, dv, cc.AnnImmediateBinding)
cc.AddAnnotation(dv, cc.AnnImmediateBinding, "true")
passCronAnnotationToDv(cron, dv, cc.AnnPodRetainAfterCompletion)

passCronLabelToDv(cron, dv, cc.LabelDefaultInstancetype)
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 @@ -319,10 +319,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
cc.AddAnnotation(cron, AnnSourceDesiredDigest, testDigest)
err := reconciler.client.Update(context.TODO(), cron)
Expect(err).ToNot(HaveOccurred())
dataSource = &cdiv1.DataSource{}
Expand All @@ -340,6 +337,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[cc.AnnImmediateBinding]).To(Equal("true"))

dv.Status.Phase = cdiv1.ImportScheduled
err = reconciler.client.Update(context.TODO(), dv)
Expand Down Expand Up @@ -407,14 +405,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]
cc.AddAnnotation(cron, AnnSourceDesiredDigest, digests[idx])
err := reconciler.client.Update(context.TODO(), cron)
Expect(err).ToNot(HaveOccurred())
dataSource = &cdiv1.DataSource{}
Expand Down Expand Up @@ -576,6 +570,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[cc.AnnImmediateBinding]).To(Equal("true"))
dv.Status.Phase = cdiv1.Succeeded
dv.Status.Conditions = cdv.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"
controller "kubevirt.io/containerized-data-importer/pkg/controller/common"
)

// 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 fc7f855

Please sign in to comment.