Skip to content

Commit

Permalink
fix apiGroup handling
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Henriksen <[email protected]>
  • Loading branch information
mhenriks committed Sep 10, 2020
1 parent d265577 commit e039789
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/api/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/kubevirt.io/containerized-data-importer/pkg/clone:go_default_library",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"k8s.io/api/admission/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
k8sfield "k8s.io/apimachinery/pkg/util/validation/field"

v1 "kubevirt.io/client-go/api/v1"
Expand Down Expand Up @@ -86,12 +85,7 @@ func (admitter *VMRestoreAdmitter) Admit(ar *v1beta1.AdmissionReview) *v1beta1.A
break
}

gv, err := schema.ParseGroupVersion(*vmRestore.Spec.Target.APIGroup)
if err != nil {
return webhookutils.ToAdmissionResponseError(err)
}

switch gv.Group {
switch *vmRestore.Spec.Target.APIGroup {
case v1.GroupName:
switch vmRestore.Spec.Target.Kind {
case "VirtualMachine":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("Validating VirtualMachineRestore Admitter", func() {
vmSnapshotName = "snapshot"
)

apiGroup := "kubevirt.io/v1alpha3"
apiGroup := "kubevirt.io"

t := true
f := false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"k8s.io/api/admission/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
k8sfield "k8s.io/apimachinery/pkg/util/validation/field"

v1 "kubevirt.io/client-go/api/v1"
Expand Down Expand Up @@ -86,12 +85,7 @@ func (admitter *VMSnapshotAdmitter) Admit(ar *v1beta1.AdmissionReview) *v1beta1.
break
}

gv, err := schema.ParseGroupVersion(*vmSnapshot.Spec.Source.APIGroup)
if err != nil {
return webhookutils.ToAdmissionResponseError(err)
}

switch gv.Group {
switch *vmSnapshot.Spec.Source.APIGroup {
case v1.GroupName:
switch vmSnapshot.Spec.Source.Kind {
case "VirtualMachine":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (

var _ = Describe("Validating VirtualMachineSnapshot Admitter", func() {
vmName := "vm"
apiGroup := "kubevirt.io/v1alpha3"
apiGroup := "kubevirt.io"

config, configMapInformer, _, _ := testutils.NewFakeClusterConfig(&k8sv1.ConfigMap{})

Expand Down
34 changes: 2 additions & 32 deletions pkg/virt-controller/watch/snapshot/snapshot_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,6 @@ type VMSnapshotController struct {
vmStatusUpdater *status.VMStatusUpdater
}

// NewSnapshotController creates a new VMSnapshotController
func NewSnapshotController(
client kubecli.KubevirtClient,
vmSnapshotInformer cache.SharedIndexInformer,
vmSnapshotContentInformer cache.SharedIndexInformer,
vmInformer cache.SharedIndexInformer,
storageClassInformer cache.SharedIndexInformer,
pvcInformer cache.SharedIndexInformer,
crdInformer cache.SharedIndexInformer,
recorder record.EventRecorder,
resyncPeriod time.Duration,
) *VMSnapshotController {

ctrl := &VMSnapshotController{
Client: client,
vmSnapshotQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "snapshot-controller-vmsnapshot"),
vmSnapshotContentQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "snapshot-controller-vmsnapshotcontent"),
crdQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "snapshot-controller-crd"),
VMSnapshotInformer: vmSnapshotInformer,
VMSnapshotContentInformer: vmSnapshotContentInformer,
StorageClassInformer: storageClassInformer,
PVCInformer: pvcInformer,
VMInformer: vmInformer,
CRDInformer: crdInformer,
recorder: recorder,
resyncPeriod: resyncPeriod,
vmStatusUpdater: status.NewVMStatusUpdater(client),
}

return ctrl
}

var supportedCRDVersions = []string{"v1beta1"}

// Init initializes the snapshot controller
Expand Down Expand Up @@ -172,6 +140,8 @@ func (ctrl *VMSnapshotController) Init() {
},
ctrl.ResyncPeriod,
)

ctrl.vmStatusUpdater = status.NewVMStatusUpdater(ctrl.Client)
}

// Run the controller
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = Describe("VirtualMachineSnapshot Tests", func() {
var err error
var virtClient kubecli.KubevirtClient

groupName := "kubevirt.io/v1alpha3"
groupName := "kubevirt.io"

BeforeEach(func() {
virtClient, err = kubecli.GetKubevirtClient()
Expand Down

0 comments on commit e039789

Please sign in to comment.