Skip to content

Commit

Permalink
snapshot controller waits for no VMIs or pods using PVCs
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 dffbfad commit 954dc1f
Show file tree
Hide file tree
Showing 16 changed files with 631 additions and 244 deletions.
8 changes: 4 additions & 4 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -11224,16 +11224,16 @@
"description": "VolumeBackup contains the data neeed to restore a PVC",
"type": "object",
"required": [
"diskName",
"volumeName",
"persistentVolumeClaim"
],
"properties": {
"diskName": {
"type": "string"
},
"persistentVolumeClaim": {
"$ref": "#/definitions/v1.PersistentVolumeClaim"
},
"volumeName": {
"type": "string"
},
"volumeSnapshotName": {
"type": "string"
}
Expand Down
24 changes: 24 additions & 0 deletions cluster-up/cluster/kind-k8s-sriov-1.17.0/csrcreator/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_default_library",
srcs = ["certsecret.go"],
importpath = "kubevirt.io/kubevirt/cluster-up/cluster/kind-k8s-sriov-1.17.0/csrcreator",
visibility = ["//visibility:private"],
deps = [
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/api/certificates/v1beta1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"@com_github_cloudflare_cfssl//csr:go_default_library",
],
)

go_binary(
name = "csrcreator",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module kubevirt.io/kubevirt

go 1.12

require (
github.com/Azure/go-autorest/autorest v0.9.1 // indirect
github.com/Azure/go-autorest/autorest/adal v0.6.0 // indirect
Expand Down
12 changes: 11 additions & 1 deletion pkg/controller/virtinformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ type KubeInformerFactory interface {
// PVC StorageClasses
StorageClass() cache.SharedIndexInformer

// Pod returns an informer for ALL Pods in the system
Pod() cache.SharedIndexInformer

K8SInformerFactory() informers.SharedInformerFactory
}

Expand Down Expand Up @@ -436,7 +439,7 @@ func (f *kubeInformerFactory) PersistentVolumeClaim() cache.SharedIndexInformer
return f.getInformer("persistentVolumeClaimInformer", func() cache.SharedIndexInformer {
restClient := f.clientSet.CoreV1().RESTClient()
lw := cache.NewListWatchFromClient(restClient, "persistentvolumeclaims", k8sv1.NamespaceAll, fields.Everything())
return cache.NewSharedIndexInformer(lw, &k8sv1.PersistentVolumeClaim{}, f.defaultResync, cache.Indexers{})
return cache.NewSharedIndexInformer(lw, &k8sv1.PersistentVolumeClaim{}, f.defaultResync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
})
}

Expand Down Expand Up @@ -763,6 +766,13 @@ func (f *kubeInformerFactory) StorageClass() cache.SharedIndexInformer {
})
}

func (f *kubeInformerFactory) Pod() cache.SharedIndexInformer {
return f.getInformer("podInformer", func() cache.SharedIndexInformer {
lw := cache.NewListWatchFromClient(f.clientSet.CoreV1().RESTClient(), "pods", k8sv1.NamespaceAll, fields.Everything())
return cache.NewSharedIndexInformer(lw, &k8sv1.Pod{}, f.defaultResync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
})
}

// VolumeSnapshotInformer returns an informer for VolumeSnapshots
func VolumeSnapshotInformer(clientSet kubecli.KubevirtClient, resyncPeriod time.Duration) cache.SharedIndexInformer {
restClient := clientSet.KubernetesSnapshotClient().SnapshotV1beta1().RESTClient()
Expand Down
13 changes: 2 additions & 11 deletions pkg/virt-controller/watch/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ go_library(
"migration.go",
"node.go",
"replicaset.go",
"snapshot.go",
"snapshot_base.go",
"util.go",
"vm.go",
"vmi.go",
Expand All @@ -31,6 +29,7 @@ go_library(
"//pkg/virt-controller/services:go_default_library",
"//pkg/virt-controller/watch/drain/disruptionbudget:go_default_library",
"//pkg/virt-controller/watch/drain/evacuation:go_default_library",
"//pkg/virt-controller/watch/snapshot:go_default_library",
"//staging/src/kubevirt.io/client-go/api/v1: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",
Expand All @@ -43,14 +42,13 @@ go_library(
"//vendor/github.com/prometheus/client_golang/prometheus/promhttp:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/storage/v1:go_default_library",
"//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1: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/fields:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
Expand All @@ -72,7 +70,6 @@ go_test(
"migration_test.go",
"node_test.go",
"replicaset_test.go",
"snapshot_test.go",
"vm_test.go",
"vmi_test.go",
"watch_suite_test.go",
Expand All @@ -84,24 +81,18 @@ go_test(
"//pkg/testutils:go_default_library",
"//pkg/virt-controller/services:go_default_library",
"//staging/src/kubevirt.io/client-go/api/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/snapshot/v1alpha1:go_default_library",
"//staging/src/kubevirt.io/client-go/generated/containerized-data-importer/clientset/versioned/fake:go_default_library",
"//staging/src/kubevirt.io/client-go/generated/external-snapshotter/clientset/versioned/fake:go_default_library",
"//staging/src/kubevirt.io/client-go/generated/kubevirt/clientset/versioned/fake:go_default_library",
"//staging/src/kubevirt.io/client-go/generated/network-attachment-definition-client/clientset/versioned/fake:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"//vendor/github.com/emicklei/go-restful:go_default_library",
"//vendor/github.com/go-openapi/errors:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/ginkgo/extensions/table:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/github.com/pborman/uuid:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/storage/v1:go_default_library",
"//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
Expand Down
38 changes: 22 additions & 16 deletions pkg/virt-controller/watch/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"kubevirt.io/kubevirt/pkg/virt-controller/services"
"kubevirt.io/kubevirt/pkg/virt-controller/watch/drain/disruptionbudget"
"kubevirt.io/kubevirt/pkg/virt-controller/watch/drain/evacuation"
"kubevirt.io/kubevirt/pkg/virt-controller/watch/snapshot"
)

const (
Expand Down Expand Up @@ -104,7 +105,7 @@ type VirtControllerApp struct {
templateService services.TemplateService
restClient *clientrest.RESTClient
informerFactory controller.KubeInformerFactory
podInformer cache.SharedIndexInformer
kvPodInformer cache.SharedIndexInformer

nodeInformer cache.SharedIndexInformer
nodeController *NodeController
Expand Down Expand Up @@ -132,10 +133,11 @@ type VirtControllerApp struct {
migrationController *MigrationController
migrationInformer cache.SharedIndexInformer

snapshotController *SnapshotController
snapshotController *snapshot.VMSnapshotController
vmSnapshotInformer cache.SharedIndexInformer
vmSnapshotContentInformer cache.SharedIndexInformer
storageClassInformer cache.SharedIndexInformer
allPodInformer cache.SharedIndexInformer

crdInformer cache.SharedIndexInformer

Expand Down Expand Up @@ -233,7 +235,7 @@ func Execute() {
restful.Add(webService)

app.vmiInformer = app.informerFactory.VMI()
app.podInformer = app.informerFactory.KubeVirtPod()
app.kvPodInformer = app.informerFactory.KubeVirtPod()
app.nodeInformer = app.informerFactory.KubeVirtNode()

app.vmiCache = app.vmiInformer.GetStore()
Expand All @@ -253,6 +255,7 @@ func Execute() {
app.vmSnapshotInformer = app.informerFactory.VirtualMachineSnapshot()
app.vmSnapshotContentInformer = app.informerFactory.VirtualMachineSnapshotContent()
app.storageClassInformer = app.informerFactory.StorageClass()
app.allPodInformer = app.informerFactory.Pod()

if app.hasCDI {
app.dataVolumeInformer = app.informerFactory.DataVolume()
Expand Down Expand Up @@ -407,10 +410,10 @@ func (vca *VirtControllerApp) initCommon() {
vca.launcherSubGid,
)

vca.vmiController = NewVMIController(vca.templateService, vca.vmiInformer, vca.podInformer, vca.persistentVolumeClaimInformer, vca.vmiRecorder, vca.clientSet, vca.dataVolumeInformer)
vca.vmiController = NewVMIController(vca.templateService, vca.vmiInformer, vca.kvPodInformer, vca.persistentVolumeClaimInformer, vca.vmiRecorder, vca.clientSet, vca.dataVolumeInformer)
recorder := vca.getNewRecorder(k8sv1.NamespaceAll, "node-controller")
vca.nodeController = NewNodeController(vca.clientSet, vca.nodeInformer, vca.vmiInformer, recorder)
vca.migrationController = NewMigrationController(vca.templateService, vca.vmiInformer, vca.podInformer, vca.migrationInformer, vca.vmiRecorder, vca.clientSet, vca.clusterConfig)
vca.migrationController = NewMigrationController(vca.templateService, vca.vmiInformer, vca.kvPodInformer, vca.migrationInformer, vca.vmiRecorder, vca.clientSet, vca.clusterConfig)
}

func (vca *VirtControllerApp) initReplicaSet() {
Expand Down Expand Up @@ -455,17 +458,20 @@ func (vca *VirtControllerApp) initEvacuationController() {

func (vca *VirtControllerApp) initSnapshotController() {
recorder := vca.getNewRecorder(k8sv1.NamespaceAll, "snapshot-controller")
vca.snapshotController = NewSnapshotController(
vca.clientSet,
vca.vmSnapshotInformer,
vca.vmSnapshotContentInformer,
vca.vmInformer,
vca.storageClassInformer,
vca.persistentVolumeClaimInformer,
vca.crdInformer,
recorder,
vca.snapshotControllerResyncPeriod,
)
vca.snapshotController = &snapshot.VMSnapshotController{
Client: vca.clientSet,
VMSnapshotInformer: vca.vmSnapshotInformer,
VMSnapshotContentInformer: vca.vmSnapshotContentInformer,
VMInformer: vca.vmInformer,
VMIInformer: vca.vmiInformer,
StorageClassInformer: vca.storageClassInformer,
PVCInformer: vca.persistentVolumeClaimInformer,
CRDInformer: vca.crdInformer,
PodInformer: vca.allPodInformer,
Recorder: recorder,
ResyncPeriod: vca.snapshotControllerResyncPeriod,
}
vca.snapshotController.Init()
}

func (vca *VirtControllerApp) leaderProbe(_ *restful.Request, response *restful.Response) {
Expand Down
66 changes: 66 additions & 0 deletions pkg/virt-controller/watch/snapshot/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = [
"snapshot.go",
"snapshot_base.go",
"util.go",
],
importpath = "kubevirt.io/kubevirt/pkg/virt-controller/watch/snapshot",
visibility = ["//visibility:public"],
deps = [
"//pkg/controller:go_default_library",
"//staging/src/kubevirt.io/client-go/api/v1: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",
"//vendor/github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/storage/v1:go_default_library",
"//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1: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/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
"//vendor/k8s.io/client-go/tools/record:go_default_library",
"//vendor/k8s.io/client-go/util/workqueue:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = [
"snapshot_suite_test.go",
"snapshot_test.go",
],
embed = [":go_default_library"],
deps = [
"//pkg/testutils:go_default_library",
"//staging/src/kubevirt.io/client-go/api/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/snapshot/v1alpha1:go_default_library",
"//staging/src/kubevirt.io/client-go/generated/external-snapshotter/clientset/versioned/fake:go_default_library",
"//staging/src/kubevirt.io/client-go/generated/kubevirt/clientset/versioned/fake:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"//vendor/github.com/golang/mock/gomock:go_default_library",
"//vendor/github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/ginkgo/extensions/table:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/storage/v1:go_default_library",
"//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/fake:go_default_library",
"//vendor/k8s.io/client-go/testing:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
"//vendor/k8s.io/client-go/tools/cache/testing:go_default_library",
"//vendor/k8s.io/client-go/tools/record:go_default_library",
"//vendor/kubevirt.io/containerized-data-importer/pkg/apis/core/v1alpha1:go_default_library",
],
)
Loading

0 comments on commit 954dc1f

Please sign in to comment.