Skip to content

Commit

Permalink
fix: Allow disabling of common data import crons
Browse files Browse the repository at this point in the history
Some of the common data import crons can be disabled.
Before this commit, the disabled data import crons were
still added to SSP.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
  • Loading branch information
akrejcir authored and kubevirt-bot committed Sep 29, 2024
1 parent a3f8db3 commit 670c4b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions controllers/operands/ssp.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ func isDataImportCronTemplateEnabled(dict hcov1beta1.DataImportCronTemplate) boo

func getCustomDicts(list []hcov1beta1.DataImportCronTemplateStatus, crDicts map[string]hcov1beta1.DataImportCronTemplate) []hcov1beta1.DataImportCronTemplateStatus {
for dictName, crDict := range crDicts {
if !isDataImportCronTemplateEnabled(crDict) {
continue
}

if _, isCommon := dataImportCronTemplateHardCodedMap[dictName]; !isCommon {
list = append(list, hcov1beta1.DataImportCronTemplateStatus{
DataImportCronTemplate: *crDict.DeepCopy(),
Expand Down
23 changes: 23 additions & 0 deletions controllers/operands/ssp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,29 @@ var _ = Describe("SSP Operands", func() {
Expect(goldenImageList).To(ContainElements(*statusImage2Enabled, statusImage3, statusImage4))
})

It("should not add user DIC template if it is disabled", func() {
dataImportCronTemplateHardCodedMap = nil
hco := commontestutils.NewHco()
hco.Spec.FeatureGates.EnableCommonBootImageImport = ptr.To(true)

disabledUserImage := image1.DeepCopy()
disableDict(disabledUserImage)
enabledUserImage := image2.DeepCopy()
enableDict(enabledUserImage)

hco.Spec.DataImportCronTemplates = []hcov1beta1.DataImportCronTemplate{*disabledUserImage, *enabledUserImage}
goldenImageList, err := getDataImportCronTemplates(hco)
Expect(err).ToNot(HaveOccurred())
Expect(goldenImageList).To(HaveLen(1))

statusImageEnabled := hcov1beta1.DataImportCronTemplateStatus{
DataImportCronTemplate: *enabledUserImage,
Status: hcov1beta1.DataImportCronStatus{},
}

Expect(goldenImageList).To(ContainElements(statusImageEnabled))
})

It("Should reject if the CR list contain DIC templates with the same name, when there are also common DIC templates", func() {
dataImportCronTemplateHardCodedMap = map[string]hcov1beta1.DataImportCronTemplate{
image1.Name: image1,
Expand Down

0 comments on commit 670c4b3

Please sign in to comment.