Skip to content

Commit

Permalink
Merge pull request #606 from kubevirt-bot/cherry-pick-595-to-release-…
Browse files Browse the repository at this point in the history
…v0.18

[release-v0.18] Don't override autoupdated datasources that point to a snapshot instead of PVC
  • Loading branch information
kubevirt-bot authored Jun 28, 2023
2 parents 571ae69 + 607dac4 commit 68e566b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ vet:
# Update vendor modules
.PHONY: vendor
vendor:
go mod vendor
go mod tidy
go mod vendor

# Validate that this repository does not contain offensive language
.PHONY: validate-no-offensive-lang
Expand Down
3 changes: 2 additions & 1 deletion hack/kubevirtci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function kubevirtci::up() {
KUBECONFIG=$(kubevirtci::kubeconfig)
export KUBECONFIG
echo "adding kubevirtci registry to cdi-insecure-registries"
${_kubectl} patch configmap cdi-insecure-registries -n cdi --type merge -p '{"data":{"kubevirtci": "registry:5000"}}'
${_kubectl} get cdis --output='name' --ignore-not-found \
| xargs -r ${_kubectl} patch --type merge -p '{"spec": {"config": {"insecureRegistries": ["registry:5000"]}}}'
echo "installing kubevirt..."
LATEST=$(curl -L https://storage.googleapis.com/kubevirt-prow/devel/release/kubevirt/kubevirt/stable.txt)
${_kubectl} apply -f "https://github.com/kubevirt/kubevirt/releases/download/${LATEST}/kubevirt-operator.yaml"
Expand Down
2 changes: 1 addition & 1 deletion internal/operands/data-sources/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func reconcileDataSource(dsInfo dataSourceInfo, request *common.Request) (common

foundDs := foundRes.(*cdiv1beta1.DataSource)
newDs := newRes.(*cdiv1beta1.DataSource)
if !dsInfo.autoUpdateEnabled || foundDs.Spec.Source.PVC == nil {
if !dsInfo.autoUpdateEnabled || (foundDs.Spec.Source.PVC == nil && foundDs.Spec.Source.Snapshot == nil) {
foundDs.Spec.Source.PVC = newDs.Spec.Source.PVC
}
}).
Expand Down
31 changes: 31 additions & 0 deletions internal/operands/data-sources/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,37 @@ var _ = Describe("Data-Sources operand", func() {
Expect(request.Client.Get(request.Context, client.ObjectKeyFromObject(&testDataSources[0]), ds)).To(Succeed())
Expect(ds.Spec).To(Equal(testDataSources[0].Spec))
})

It("should not restore DataSource if DataImportCron prefers snapshots sources", func() {
_, err := operand.Reconcile(&request)
Expect(err).ToNot(HaveOccurred())

cron := cronTemplate.AsDataImportCron()
cron.Namespace = internal.GoldenImagesNamespace
ExpectResourceExists(&cron, request)

// Update DataSource to simulate CDI
ds := &cdiv1beta1.DataSource{}
Expect(request.Client.Get(request.Context, client.ObjectKeyFromObject(&testDataSources[0]), ds)).To(Succeed())
ds.Spec.Source.PVC = nil
ds.Spec.Source.Snapshot = &cdiv1beta1.DataVolumeSourceSnapshot{
Namespace: "test",
Name: "test",
}
Expect(request.Client.Update(request.Context, ds)).To(Succeed())

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

// Test that DataSource was not changed
Expect(request.Client.Get(request.Context, client.ObjectKeyFromObject(&testDataSources[0]), ds)).To(Succeed())
Expect(ds.Spec.Source).To(Equal(cdiv1beta1.DataSourceSource{
Snapshot: &cdiv1beta1.DataVolumeSourceSnapshot{
Namespace: "test",
Name: "test",
},
}))
})
})

Context("with existing PVC", func() {
Expand Down

0 comments on commit 68e566b

Please sign in to comment.