Skip to content

Commit

Permalink
fix: Allow disabling of common data import crons (#3105) (#3133)
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>
(cherry picked from commit 0be29b7)

Co-authored-by: Andrej Krejcir <akrejcir@redhat.com>
  • Loading branch information
kubevirt-bot and akrejcir authored Oct 9, 2024
1 parent 3969fc7 commit 14d448b
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 @@ -276,6 +276,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 @@ -718,6 +718,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 = 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 14d448b

Please sign in to comment.