@@ -25,6 +25,8 @@ type Clients struct {
2525var (
2626 // IsOpenshift is true if environment is Openshift, it is false if environment is Kubernetes
2727 IsOpenshift = isOpenshift ()
28+ // IsCSIEnabled is true if environment has CSI provider installed, otherwise false
29+ IsCSIInstalled = isCSIInstalled ()
2830)
2931
3032// GetClients returns a `Clients` object containing both openshift and kubernetes clients with an openshift identifier
@@ -52,9 +54,11 @@ func GetClients() Clients {
5254
5355 var csiClient * csiclient.Clientset
5456
55- csiClient , err = GetCSIClient ()
56- if err != nil {
57- logrus .Warnf ("Unable to create CSI client error = %v" , err )
57+ if IsCSIInstalled {
58+ csiClient , err = GetCSIClient ()
59+ if err != nil {
60+ logrus .Warnf ("Unable to create CSI client error = %v" , err )
61+ }
5862 }
5963
6064 return Clients {
@@ -73,6 +77,20 @@ func GetArgoRolloutClient() (*argorollout.Clientset, error) {
7377 return argorollout .NewForConfig (config )
7478}
7579
80+ func isCSIInstalled () bool {
81+ client , err := GetKubernetesClient ()
82+ if err != nil {
83+ logrus .Fatalf ("Unable to create Kubernetes client error = %v" , err )
84+ }
85+ _ , err = client .RESTClient ().Get ().AbsPath ("/apis/secrets-store.csi.x-k8s.io/v1" ).Do (context .TODO ()).Raw ()
86+ if err == nil {
87+ logrus .Info ("CSI provider is installed" )
88+ return true
89+ }
90+ logrus .Info ("CSI provider is not installed" )
91+ return false
92+ }
93+
7694func GetCSIClient () (* csiclient.Clientset , error ) {
7795 config , err := getConfig ()
7896 if err != nil {
0 commit comments