Skip to content

Commit

Permalink
instancetype: Handle VirtualMachineInstancetypeSpecRevision without A…
Browse files Browse the repository at this point in the history
…PIVersion

As set out in issue kubevirt#9261 there have been reports of older
VirtualMachineInstancetypeSpecRevision objects being stored in
ControllerRevisions without APIVersion set. This is likely due to a
known client-go issue [1] stripping TypeMeta from returned objects.

Given the limited support for v1alpha1 and the fact that we moved away
from VirtualMachineInstancetypeSpecRevision to complete objects being
captured in ControllerRevisions by v1alpah2 this change simply works
around this issue by ignoring the value of APIVersion. This should allow
the conversion to complete correctly until we upgrade these
ControllerRevisions in the future.

[1] kubernetes/client-go#541

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
  • Loading branch information
lyarwood committed Apr 6, 2023
1 parent 31a9bc4 commit 36ee327
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
8 changes: 0 additions & 8 deletions pkg/instancetype/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ func decodeOldInstancetypeRevisionObject(data []byte) (*instancetypev1alpha1.Vir
return nil, nil
}

if revision.APIVersion != instancetypev1alpha1.SchemeGroupVersion.String() {
return nil, nil
}

instancetypeSpec := &instancetypev1alpha1.VirtualMachineInstancetypeSpec{}
err = json.Unmarshal(revision.Spec, instancetypeSpec)
if err != nil {
Expand All @@ -71,10 +67,6 @@ func decodeOldPreferenceRevisionObject(data []byte) (*instancetypev1alpha1.Virtu
return nil, nil
}

if revision.APIVersion != instancetypev1alpha1.SchemeGroupVersion.String() {
return nil, nil
}

preferenceSpec := &instancetypev1alpha1.VirtualMachinePreferenceSpec{}
err = json.Unmarshal(revision.Spec, preferenceSpec)
if err != nil {
Expand Down
19 changes: 13 additions & 6 deletions pkg/instancetype/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var _ = Describe("instancetype compatibility", func() {
Context("reading old ControllerRevision", func() {
It("should decode v1alpha1 instancetype from ControllerRevision", func() {
DescribeTable("should decode v1alpha1 instancetype from ControllerRevision", func(apiVersion string) {
instancetypeSpec := v1alpha1.VirtualMachineInstancetypeSpec{
CPU: v1alpha1.CPUInstancetype{
Guest: 4,
Expand All @@ -27,7 +27,7 @@ var _ = Describe("instancetype compatibility", func() {
Expect(err).ToNot(HaveOccurred())

revision := v1alpha1.VirtualMachineInstancetypeSpecRevision{
APIVersion: v1alpha1.SchemeGroupVersion.String(),
APIVersion: apiVersion,
Spec: specBytes,
}

Expand All @@ -38,9 +38,12 @@ var _ = Describe("instancetype compatibility", func() {
Expect(err).ToNot(HaveOccurred())
Expect(decoded).ToNot(BeNil())
Expect(decoded.Spec.CPU).To(Equal(instancetypeSpec.CPU))
})
},
Entry("with APIVersion", v1alpha1.SchemeGroupVersion.String()),
Entry("without APIVersion", ""),
)

It("should decode v1alpha1 preference from ControllerRevision", func() {
DescribeTable("should decode v1alpha1 preference from ControllerRevision", func(apiVersion string) {
preferredTopology := v1alpha1.PreferCores
preferenceSpec := v1alpha1.VirtualMachinePreferenceSpec{
CPU: &v1alpha1.CPUPreferences{
Expand All @@ -52,7 +55,7 @@ var _ = Describe("instancetype compatibility", func() {
Expect(err).ToNot(HaveOccurred())

revision := v1alpha1.VirtualMachinePreferenceSpecRevision{
APIVersion: v1alpha1.SchemeGroupVersion.String(),
APIVersion: apiVersion,
Spec: specBytes,
}

Expand All @@ -63,7 +66,11 @@ var _ = Describe("instancetype compatibility", func() {
Expect(err).ToNot(HaveOccurred())
Expect(decoded).ToNot(BeNil())
Expect(decoded.Spec).To(Equal(preferenceSpec))
})

},
Entry("with APIVersion", v1alpha1.SchemeGroupVersion.String()),
Entry("without APIVersion", ""),
)
})

Context("instancetype conversion", func() {
Expand Down

0 comments on commit 36ee327

Please sign in to comment.