Skip to content

Commit

Permalink
Merge pull request #164 from bertinatto/fix-csisnapshot-capability
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 18, 2022
2 parents 7eae336 + b7f7d82 commit 5064b35
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 35 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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-20221017091500-9aea380195f4
github.com/prometheus/client_golang v1.12.1
github.com/spf13/cobra v1.4.0
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
Expand All @@ -23,6 +23,8 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

require k8s.io/apiextensions-apiserver v0.25.0

require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
Expand Down Expand Up @@ -97,7 +99,6 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.25.0 // indirect
k8s.io/apiserver v0.25.0 // indirect
k8s.io/kube-aggregator v0.25.0 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
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-20221017091500-9aea380195f4 h1:4P+w+CZsPS423+31zAQ814+tkrueIdBQLdWXdjrmu20=
github.com/openshift/library-go v0.0.0-20221017091500-9aea380195f4/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
27 changes: 26 additions & 1 deletion pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/openshift/library-go/pkg/operator/events"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apiextclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic"
kubeclient "k8s.io/client-go/kubernetes"
corev1listers "k8s.io/client-go/listers/core/v1"
Expand Down Expand Up @@ -58,6 +60,11 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
nodeInformer := kubeInformersForNamespaces.InformersFor("").Core().V1().Nodes()
configMapInformer := kubeInformersForNamespaces.InformersFor(defaultNamespace).Core().V1().ConfigMaps()

apiExtClient, err := apiextclient.NewForConfig(rest.AddUserAgent(controllerConfig.KubeConfig, operatorName))
if err != nil {
return err
}

// Create config clientset and informer. This is used to get the cluster ID
configClient := configclient.NewForConfigOrDie(rest.AddUserAgent(controllerConfig.KubeConfig, operatorName))
configInformers := configinformers.NewSharedInformerFactory(configClient, 20*time.Minute)
Expand Down Expand Up @@ -94,7 +101,6 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
assets.ReadFile,
[]string{
"storageclass_gp2.yaml",
"volumesnapshotclass.yaml",
"csidriver.yaml",
"controller_sa.yaml",
"controller_pdb.yaml",
Expand All @@ -117,6 +123,25 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
"rbac/kube_rbac_proxy_role.yaml",
"rbac/kube_rbac_proxy_binding.yaml",
},
).WithConditionalStaticResourcesController(
"AWSEBSDriverConditionalStaticResourcesController",
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(
"AWSEBSDriverCSIConfigObserverController",
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
Original file line number Diff line number Diff line change
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-20221017091500-9aea380195f4
## 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 5064b35

Please sign in to comment.