-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate control-plane quorum only on OpenShift
Assert if cluster was installed on OpenShift, since only there a quorum PDB exists, otherwise we have nothing to assert
- Loading branch information
Showing
5 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package utils | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/discovery" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
// IsOpenshiftSupported will be set to true in case the operator was installed on OpenShift cluster | ||
var IsOpenshiftSupported bool | ||
|
||
// ValidateIsOpenshift returns true if the cluster has the openshift config group | ||
func ValidateIsOpenshift(config *rest.Config) error { | ||
dc, err := discovery.NewDiscoveryClientForConfig(config) | ||
if err != nil { | ||
return err | ||
} | ||
apiGroups, err := dc.ServerGroups() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
kind := schema.GroupVersionKind{Group: "config.openshift.io", Version: "v1", Kind: "ClusterVersion"} | ||
for _, apiGroup := range apiGroups.Groups { | ||
for _, supportedVersion := range apiGroup.Versions { | ||
if supportedVersion.GroupVersion == kind.GroupVersion().String() { | ||
IsOpenshiftSupported = true | ||
return nil | ||
} | ||
} | ||
} | ||
return nil | ||
} |