Skip to content

Commit

Permalink
Add minimal flavor functionality
Browse files Browse the repository at this point in the history
Changes:
- Added flavor package with common functionality to get flavor and apply it to VMI.
- Added flavor FlavorMatcher field to VM API, which references a flavor.
- VM validating webhook checks that the flavor exists, and can be applied to VMI without conflicts.
- virt-controller applies the flavor to VMI when a VM is started

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
  • Loading branch information
akrejcir committed Oct 8, 2021
1 parent 5ab7ab3 commit 6dc5484
Show file tree
Hide file tree
Showing 33 changed files with 1,460 additions and 14 deletions.
25 changes: 25 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -11880,6 +11880,27 @@
}
}
},
"v1.FlavorMatcher": {
"description": "FlavorMatcher references a flavor that is used to fill fields in the VMI template.",
"type": "object",
"required": [
"name"
],
"properties": {
"kind": {
"description": "Kind specifies which flavor resource is referenced. Allowed values are: \"VirtualMachineFlavor\" and \"VirtualMachineClusterFlavor\". If not specified, \"VirtualMachineClusterFlavor\" is used by default.",
"type": "string"
},
"name": {
"description": "Name is the name of the VirtualMachineFlavor or VirtualMachineClusterFlavor",
"type": "string"
},
"profile": {
"description": "Profile is the name of a custom profile in the flavor. If left empty, the default profile is used.",
"type": "string"
}
}
},
"v1.FloppyTarget": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -14360,6 +14381,10 @@
"$ref": "#/definitions/v1.DataVolumeTemplateSpec"
}
},
"flavor": {
"description": "FlavorMatcher references a flavor that is used to fill fields in Template",
"$ref": "#/definitions/v1.FlavorMatcher"
},
"runStrategy": {
"description": "Running state indicates the requested running state of the VirtualMachineInstance mutually exclusive with Running",
"type": "string"
Expand Down
52 changes: 52 additions & 0 deletions manifests/generated/operator-csv.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,14 @@ spec:
- get
- list
- watch
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- list
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -598,6 +606,14 @@ spec:
- get
- list
- watch
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- list
- watch
- apiGroups:
- kubevirt.io
resources:
Expand Down Expand Up @@ -722,6 +738,20 @@ spec:
- list
- watch
- deletecollection
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- get
- delete
- create
- update
- patch
- list
- watch
- deletecollection
- apiGroups:
- subresources.kubevirt.io
resources:
Expand Down Expand Up @@ -781,6 +811,19 @@ spec:
- patch
- list
- watch
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- get
- delete
- create
- update
- patch
- list
- watch
- apiGroups:
- kubevirt.io
resources:
Expand Down Expand Up @@ -818,6 +861,15 @@ spec:
- get
- list
- watch
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- get
- list
- watch
- apiGroups:
- authentication.k8s.io
resources:
Expand Down
52 changes: 52 additions & 0 deletions manifests/generated/rbac-operator.authorization.k8s.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ rules:
- get
- list
- watch
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- list
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -500,6 +508,14 @@ rules:
- get
- list
- watch
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- list
- watch
- apiGroups:
- kubevirt.io
resources:
Expand Down Expand Up @@ -624,6 +640,20 @@ rules:
- list
- watch
- deletecollection
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- get
- delete
- create
- update
- patch
- list
- watch
- deletecollection
- apiGroups:
- subresources.kubevirt.io
resources:
Expand Down Expand Up @@ -683,6 +713,19 @@ rules:
- patch
- list
- watch
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- get
- delete
- create
- update
- patch
- list
- watch
- apiGroups:
- kubevirt.io
resources:
Expand Down Expand Up @@ -720,6 +763,15 @@ rules:
- get
- list
- watch
- apiGroups:
- flavor.kubevirt.io
resources:
- virtualmachineflavors
- virtualmachineclusterflavors
verbs:
- get
- list
- watch
- apiGroups:
- authentication.k8s.io
resources:
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
"//pkg/testutils:go_default_library",
"//staging/src/github.com/golang/glog:go_default_library",
"//staging/src/kubevirt.io/client-go/api/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/flavor/v1alpha1:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/snapshot/v1alpha1:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
Expand Down
21 changes: 21 additions & 0 deletions pkg/controller/virtinformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
aggregatorclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"

kubev1 "kubevirt.io/client-go/api/v1"
flavorv1 "kubevirt.io/client-go/apis/flavor/v1alpha1"
snapshotv1 "kubevirt.io/client-go/apis/snapshot/v1alpha1"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/client-go/log"
Expand Down Expand Up @@ -110,6 +111,12 @@ type KubeInformerFactory interface {
// Watches VirtualMachineRestore objects
VirtualMachineRestore() cache.SharedIndexInformer

// Watches VirtualMachineFlavor objects
VirtualMachineFlavor() cache.SharedIndexInformer

// Watches VirtualMachineClusterFlavor objects
VirtualMachineClusterFlavor() cache.SharedIndexInformer

// Watches for k8s extensions api configmap
ApiAuthConfigMap() cache.SharedIndexInformer

Expand Down Expand Up @@ -496,6 +503,20 @@ func (f *kubeInformerFactory) VirtualMachineRestore() cache.SharedIndexInformer
})
}

func (f *kubeInformerFactory) VirtualMachineFlavor() cache.SharedIndexInformer {
return f.getInformer("vmFlavorInformer", func() cache.SharedIndexInformer {
lw := cache.NewListWatchFromClient(f.clientSet.GeneratedKubeVirtClient().FlavorV1alpha1().RESTClient(), "virtualmachineflavors", k8sv1.NamespaceAll, fields.Everything())
return cache.NewSharedIndexInformer(lw, &flavorv1.VirtualMachineFlavor{}, f.defaultResync, cache.Indexers{})
})
}

func (f *kubeInformerFactory) VirtualMachineClusterFlavor() cache.SharedIndexInformer {
return f.getInformer("vmClusterFlavorInformer", func() cache.SharedIndexInformer {
lw := cache.NewListWatchFromClient(f.clientSet.GeneratedKubeVirtClient().FlavorV1alpha1().RESTClient(), "virtualmachineclusterflavors", k8sv1.NamespaceAll, fields.Everything())
return cache.NewSharedIndexInformer(lw, &flavorv1.VirtualMachineClusterFlavor{}, f.defaultResync, cache.Indexers{})
})
}

func (f *kubeInformerFactory) DataVolume() cache.SharedIndexInformer {
return f.getInformer("dataVolumeInformer", func() cache.SharedIndexInformer {
lw := cache.NewListWatchFromClient(f.clientSet.CdiClient().CdiV1beta1().RESTClient(), "datavolumes", k8sv1.NamespaceAll, fields.Everything())
Expand Down
36 changes: 36 additions & 0 deletions pkg/flavor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["flavor.go"],
importpath = "kubevirt.io/kubevirt/pkg/flavor",
visibility = ["//visibility:public"],
deps = [
"//staging/src/kubevirt.io/client-go/api/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/flavor/v1alpha1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = [
"flavor_suite_test.go",
"flavor_test.go",
],
deps = [
":go_default_library",
"//pkg/testutils:go_default_library",
"//staging/src/kubevirt.io/client-go/api/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/flavor/v1alpha1:go_default_library",
"//staging/src/kubevirt.io/client-go/testutils:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
],
)
Loading

0 comments on commit 6dc5484

Please sign in to comment.