Skip to content

Commit

Permalink
Merge pull request kubevirt#4374 from mhenriks/volumesnapshot-error
Browse files Browse the repository at this point in the history
Ignore VolumeSnapshot error status
  • Loading branch information
kubevirt-bot authored Oct 21, 2020
2 parents f478dfc + 0bcd2f7 commit 5102772
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 99 deletions.
10 changes: 2 additions & 8 deletions pkg/virt-controller/watch/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (ctrl *VMSnapshotController) updateVMSnapshotContent(content *snapshotv1.Vi
if contentCpy.Status == nil {
contentCpy.Status = &snapshotv1.VirtualMachineSnapshotContentStatus{}
}
contentCpy.Status.Error = nil

if len(deletedSnapshots) > 0 {
ready = false
Expand All @@ -252,10 +253,6 @@ func (ctrl *VMSnapshotController) updateVMSnapshotContent(content *snapshotv1.Vi
for _, vss := range volueSnapshotStatus {
if vss.ReadyToUse == nil || !*vss.ReadyToUse {
ready = false
}

if vss.Error != nil {
errorMessage = "VolumeSnapshot in error state"
break
}
}
Expand All @@ -265,10 +262,7 @@ func (ctrl *VMSnapshotController) updateVMSnapshotContent(content *snapshotv1.Vi
contentCpy.Status.CreationTime = currentTime()
}

if errorMessage != "" &&
(contentCpy.Status.Error == nil ||
contentCpy.Status.Error.Message == nil ||
*contentCpy.Status.Error.Message != errorMessage) {
if errorMessage != "" {
contentCpy.Status.Error = &snapshotv1.Error{
Time: currentTime(),
Message: &errorMessage,
Expand Down
33 changes: 16 additions & 17 deletions pkg/virt-controller/watch/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

vsv1beta1 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
Expand Down Expand Up @@ -785,17 +785,13 @@ var _ = Describe("Snapshot controlleer", func() {
controller.processVMSnapshotContentWorkItem()
})

It("should update VirtualMachineSnapshotContent on error", func() {
message := "VolumeSnapshot in error state"
DescribeTable("should update VirtualMachineSnapshotContent on error", func(rtu bool, ct *metav1.Time) {
vmSnapshotContent := createVMSnapshotContent()
updatedContent := vmSnapshotContent.DeepCopy()
updatedContent.ResourceVersion = "1"
updatedContent.Status = &snapshotv1.VirtualMachineSnapshotContentStatus{
ReadyToUse: &f,
Error: &snapshotv1.Error{
Message: &message,
Time: timeFunc(),
},
ReadyToUse: &rtu,
CreationTime: ct,
}

vmSnapshotContentSource.Add(vmSnapshotContent)
Expand All @@ -804,8 +800,8 @@ var _ = Describe("Snapshot controlleer", func() {
volumeSnapshots := createVolumeSnapshots(vmSnapshotContent)
for i := range volumeSnapshots {
message := "bad error"
volumeSnapshots[i].Status.ReadyToUse = &f
volumeSnapshots[i].Status.CreationTime = nil
volumeSnapshots[i].Status.ReadyToUse = &rtu
volumeSnapshots[i].Status.CreationTime = ct
volumeSnapshots[i].Status.Error = &vsv1beta1.VolumeSnapshotError{
Message: &message,
Time: timeFunc(),
Expand All @@ -822,7 +818,10 @@ var _ = Describe("Snapshot controlleer", func() {
}

controller.processVMSnapshotContentWorkItem()
})
},
Entry("not ready", false, nil),
Entry("ready", true, timeFunc()),
)

It("should update VirtualMachineSnapshotContent when VolumeSnapshot deleted", func() {
vmSnapshotContent := createVMSnapshotContent()
Expand Down Expand Up @@ -857,7 +856,7 @@ var _ = Describe("Snapshot controlleer", func() {
testutils.ExpectEvent(recorder, "VolumeSnapshotMissing")
})

table.DescribeTable("should delete informer", func(crdName string) {
DescribeTable("should delete informer", func(crdName string) {
crd := &extv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
Expand All @@ -878,8 +877,8 @@ var _ = Describe("Snapshot controlleer", func() {
Expect(controller.dynamicInformerMap[crdName].stopCh).Should(BeNil())
Expect(controller.dynamicInformerMap[crdName].informer).Should(BeNil())
},
table.Entry("for VolumeSnapshot", volumeSnapshotCRD),
table.Entry("for VolumeSnapshotClass", volumeSnapshotClassCRD),
Entry("for VolumeSnapshot", volumeSnapshotCRD),
Entry("for VolumeSnapshotClass", volumeSnapshotClassCRD),
)

It("should update volume snapshot status for each volume", func() {
Expand Down Expand Up @@ -1201,7 +1200,7 @@ var _ = Describe("Snapshot controlleer", func() {
}
})

table.DescribeTable("should create informer", func(crdName string) {
DescribeTable("should create informer", func(crdName string) {
crd := &extv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
Expand All @@ -1221,8 +1220,8 @@ var _ = Describe("Snapshot controlleer", func() {
Expect(controller.dynamicInformerMap[crdName].stopCh).ShouldNot(BeNil())
Expect(controller.dynamicInformerMap[crdName].informer).ShouldNot(BeNil())
},
table.Entry("for VolumeSnapshot", volumeSnapshotCRD),
table.Entry("for VolumeSnapshotClass", volumeSnapshotClassCRD),
Entry("for VolumeSnapshot", volumeSnapshotCRD),
Entry("for VolumeSnapshotClass", volumeSnapshotClassCRD),
)
})
})
Expand Down
1 change: 1 addition & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ go_test(
"//vendor/github.com/evanphx/json-patch:go_default_library",
"//vendor/github.com/google/goexpect:go_default_library",
"//vendor/github.com/gorilla/websocket:go_default_library",
"//vendor/github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1:go_default_library",
"//vendor/github.com/mitchellh/go-vnc:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/ginkgo/config:go_default_library",
Expand Down
Loading

0 comments on commit 5102772

Please sign in to comment.