Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #59 from bertinatto/fix-snapshot-cap-backport-412
[release-4.12] OCPBUGS-3425: Only deploy VolumeSnapshotClass if CRD exists
  • Loading branch information
openshift-merge-robot committed Nov 9, 2022
2 parents a0861f0 + 7a56853 commit e4ed4ee
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 34 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -6,7 +6,7 @@ require (
github.com/openshift/api v0.0.0-20220919112502-5eaf4250c423
github.com/openshift/build-machinery-go v0.0.0-20220913142420-e25cf57ea46d
github.com/openshift/client-go v0.0.0-20220915152853-9dfefb19db2e
github.com/openshift/library-go v0.0.0-20220915130036-73d5a4a82865
github.com/openshift/library-go v0.0.0-20221021005159-d93563844063
github.com/prometheus/client_golang v1.12.1
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -395,8 +395,8 @@ github.com/openshift/build-machinery-go v0.0.0-20220913142420-e25cf57ea46d h1:RR
github.com/openshift/build-machinery-go v0.0.0-20220913142420-e25cf57ea46d/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/client-go v0.0.0-20220915152853-9dfefb19db2e h1:ab+BJg7h50pi2/rbMkDSXfYx8w80HLmr7NBs8H1hEvU=
github.com/openshift/client-go v0.0.0-20220915152853-9dfefb19db2e/go.mod h1:e+TTiBDGWB3O3p3iAzl054x3cZDWhrZ5+jxJRCdEFkA=
github.com/openshift/library-go v0.0.0-20220915130036-73d5a4a82865 h1:x7KWaYzkD2KQ3rha9u7OVAfjZpSFTmJRSHb4CHc+CwM=
github.com/openshift/library-go v0.0.0-20220915130036-73d5a4a82865/go.mod h1:KPBAXGaq7pPmA+1wUVtKr5Axg3R68IomWDkzaOxIhxM=
github.com/openshift/library-go v0.0.0-20221021005159-d93563844063 h1:Mn2LKR04FBEiXk1g2r6cB98G7M3sCUp58qb89Uz5kcE=
github.com/openshift/library-go v0.0.0-20221021005159-d93563844063/go.mod h1:KPBAXGaq7pPmA+1wUVtKr5Axg3R68IomWDkzaOxIhxM=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
Expand Down
28 changes: 27 additions & 1 deletion pkg/operator/starter.go
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/openshift/azure-disk-csi-driver-operator/pkg/azurestackhub"

apiextclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic"
kubeclient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -50,6 +52,12 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
configClient := configclient.NewForConfigOrDie(rest.AddUserAgent(controllerConfig.KubeConfig, operatorName))
configInformers := configinformers.NewSharedInformerFactory(configClient, 20*time.Minute)

// Create apiextension client. This is used to verify is a VolumeSnapshotClass CRD exists.
apiExtClient, err := apiextclient.NewForConfig(rest.AddUserAgent(controllerConfig.KubeConfig, operatorName))
if err != nil {
return err
}

// Create GenericOperatorclient. This is used by the library-go controllers created down below
gvr := opv1.SchemeGroupVersion.WithResource("clustercsidrivers")
operatorClient, dynamicInformers, err := goc.NewClusterScopedOperatorClientWithConfigName(controllerConfig.KubeConfig, gvr, "disk.csi.azure.com")
Expand Down Expand Up @@ -98,7 +106,6 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
kubeInformersForNamespaces,
assets.ReadFile,
[]string{
volumeSnapshotPath,
"controller_sa.yaml",
"controller_pdb.yaml",
"node_sa.yaml",
Expand All @@ -121,6 +128,25 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
"rbac/prometheus_role.yaml",
"rbac/prometheus_rolebinding.yaml",
},
).WithConditionalStaticResourcesController(
"AzureDiskDriverConditionalStaticResourcesController",
kubeClient,
dynamicClient,
kubeInformersForNamespaces,
assets.ReadFile,
[]string{
volumeSnapshotPath,
},
// Only install when CRD exists.
func() bool {
name := "volumesnapshotclasses.snapshot.storage.k8s.io"
_, err := apiExtClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), name, metav1.GetOptions{})
return err == nil
},
// Don't ever remove.
func() bool {
return false
},
).WithCSIConfigObserverController(
"AzureDiskDriverCSIConfigObserverController",
configInformers,
Expand Down
56 changes: 37 additions & 19 deletions vendor/github.com/openshift/library-go/pkg/config/serving/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 55 additions & 8 deletions vendor/github.com/openshift/library-go/pkg/crypto/crypto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -245,7 +245,7 @@ github.com/openshift/client-go/operator/informers/externalversions/operator/v1
github.com/openshift/client-go/operator/informers/externalversions/operator/v1alpha1
github.com/openshift/client-go/operator/listers/operator/v1
github.com/openshift/client-go/operator/listers/operator/v1alpha1
# github.com/openshift/library-go v0.0.0-20220915130036-73d5a4a82865
# github.com/openshift/library-go v0.0.0-20221021005159-d93563844063
## explicit; go 1.18
github.com/openshift/library-go/pkg/authorization/hardcodedauthorizer
github.com/openshift/library-go/pkg/config/client
Expand Down

0 comments on commit e4ed4ee

Please sign in to comment.