Skip to content

Commit

Permalink
Merge pull request #159 from bertinatto/fix-snapshot-cap
Browse files Browse the repository at this point in the history
OCPBUGS-1904: Only deploy VolumeSnapshotClass when CRD exists
  • Loading branch information
openshift-merge-robot committed Oct 27, 2022
2 parents 27c1d21 + d2be29f commit 6cad875
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -8,7 +8,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.2
github.com/spf13/cobra v1.4.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -400,8 +400,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
26 changes: 26 additions & 0 deletions pkg/operator/starter.go
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/openshift/csi-driver-manila-operator/pkg/controllers/secret"
"github.com/openshift/csi-driver-manila-operator/pkg/util"
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
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 @@ -46,6 +48,12 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
configMapInformer := kubeInformersForNamespaces.InformersFor(util.OperandNamespace).Core().V1().ConfigMaps()
nodeInformer := kubeInformersForNamespaces.InformersFor("").Core().V1().Nodes()

// 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
}

configClient := configclient.NewForConfigOrDie(rest.AddUserAgent(controllerConfig.KubeConfig, operatorName))
configInformers := configinformers.NewSharedInformerFactory(configClient, resync)

Expand Down Expand Up @@ -96,8 +104,26 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
"node_sa.yaml",
"service.yaml",
"cabundle_cm.yaml",
},
).WithConditionalStaticResourcesController(
"ManilaDriverConditionalStaticResourcesController",
kubeClient,
dynamicClient,
kubeInformersForNamespaces,
assets.ReadFile,
[]string{
"volumesnapshotclass.yaml",
},
// 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(
"ManilaDriverCSIConfigObserverController",
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 @@ -256,7 +256,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 6cad875

Please sign in to comment.