Skip to content

Commit

Permalink
Merge pull request #1033 from akrejcir/fix-clear-url
Browse files Browse the repository at this point in the history
fix: common-instancetypes: Clear URL when deploying from bundle
  • Loading branch information
kubevirt-bot authored Aug 7, 2024
2 parents 9f35324 + cb41085 commit eeb1ecc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/operands/common-instancetypes/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ func (c *CommonInstancetypes) reconcileFromURL(request *common.Request) ([]commo

func (c *CommonInstancetypes) reconcileFromBundle(request *common.Request) ([]common.ReconcileResult, error) {
request.Logger.Info("Reconciling common-instancetypes from internal bundle")

// We need to clear the resourceURL, otherwise when switching between using and not using URL,
// the operator would not deploy resources from the URL.
c.resourceURL = ""

var err error
c.virtualMachineClusterInstancetypes, c.virtualMachineClusterPreferences, err = c.fetchResourcesFromBundle()
if err != nil {
Expand Down
50 changes: 50 additions & 0 deletions internal/operands/common-instancetypes/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,56 @@ var _ = Describe("Common-Instancetypes operand", func() {
assertResoucesDoNotExist(request, originalInstancetypes, originalPreferences)
})

It("should clear URL cache when switching between internal bundle and URL", func() {
By("creating resources from URL")

mockResMap, instancetypesFromURL, preferencesFromURL, err := newMockResources(2, 2)
Expect(err).ToNot(HaveOccurred())

operand.KustomizeRunFunc = func(_ filesys.FileSystem, _ string) (resmap.ResMap, error) {
return mockResMap, nil
}

const testURL = "https://example.org/foo?ref=1"

//nolint:staticcheck
request.Instance.Spec.CommonInstancetypes = &ssp.CommonInstancetypes{
URL: ptr.To(testURL),
}

_, err = operand.Reconcile(&request)
Expect(err).ToNot(HaveOccurred())
assertResoucesExist(request, instancetypesFromURL, preferencesFromURL)

By("Creating resources from internal bundle")

instancetypesFromBundle, err := FetchBundleResource[instancetypev1beta1.VirtualMachineClusterInstancetype](instancetypePath)
Expect(err).ToNot(HaveOccurred())
Expect(instancetypesFromBundle).ToNot(BeEmpty())

preferencesFromBundle, err := FetchBundleResource[instancetypev1beta1.VirtualMachineClusterPreference](preferencePath)
Expect(err).ToNot(HaveOccurred())
Expect(preferencesFromBundle).ToNot(BeEmpty())

//nolint:staticcheck
request.Instance.Spec.CommonInstancetypes.URL = nil

_, err = operand.Reconcile(&request)
Expect(err).ToNot(HaveOccurred())
assertResoucesExist(request, instancetypesFromBundle, preferencesFromBundle)

By("creating resources from the same URL again")

//nolint:staticcheck
request.Instance.Spec.CommonInstancetypes = &ssp.CommonInstancetypes{
URL: ptr.To(testURL),
}

_, err = operand.Reconcile(&request)
Expect(err).ToNot(HaveOccurred())
assertResoucesExist(request, instancetypesFromURL, preferencesFromURL)
})

It("should not cleanup any user resources when reconciling from a URL", func() {
instancetype := newVirtualMachineClusterInstancetype("user-instancetype")
Expect(request.Client.Create(request.Context, instancetype, &client.CreateOptions{})).To(Succeed())
Expand Down

0 comments on commit eeb1ecc

Please sign in to comment.