diff --git a/pkg/util/test/util.go b/pkg/util/test/util.go index 28fcb396cf..99ff3f825e 100644 --- a/pkg/util/test/util.go +++ b/pkg/util/test/util.go @@ -8,7 +8,6 @@ import ( cryptoTls "crypto/tls" "encoding/base64" "fmt" - routev1 "github.com/openshift/api/route/v1" "io" "net" "net/http" @@ -31,6 +30,7 @@ import ( "github.com/libopenstorage/operator/pkg/util" ocp_configv1 "github.com/openshift/api/config/v1" consolev1 "github.com/openshift/api/console/v1" + routev1 "github.com/openshift/api/route/v1" ocp_secv1 "github.com/openshift/api/security/v1" appops "github.com/portworx/sched-ops/k8s/apps" coreops "github.com/portworx/sched-ops/k8s/core" @@ -871,6 +871,38 @@ func ValidateClusterProviderHealth(cluster *corev1.StorageCluster) error { return nil } +// GetOpenshiftVersion gets Openshift version from ClusterVersion object and returns it as a string +func GetOpenshiftVersion() (string, error) { + logrus.Debug("Getting Openshift version from ClusterVersion object..") + clusterVersion, err := openshiftops.Instance().GetClusterVersion("version") + if err != nil { + return "", fmt.Errorf("failed to get Openshift ClusterVersion object, Err: %v", err) + } + + if clusterVersion.Status.Desired.Version == "" { + return "", fmt.Errorf("ClusterVersion object returned empty Openshift version string") + } + logrus.Debugf("Got Openshift version [%s]", clusterVersion.Status.Desired.Version) + return clusterVersion.Status.Desired.Version, nil +} + +// IsOpenshiftCluster checks if its Openshift cluster by seeing if ClusterVersion resource exists +func IsOpenshiftCluster() bool { + clusterVersionKind := "ClusterVersion" + clusterVersionApiVersion := "config.openshift.io/v1" + + gvk := schema.GroupVersionKind{ + Kind: clusterVersionKind, + Version: clusterVersionApiVersion, + } + exists, err := coreops.Instance().ResourceExists(gvk) + if err != nil { + logrus.Error(err) + return false + } + return exists +} + // ValidatePxPodsAreReadyOnGivenNodes takes list of node and validates PX pods are present and ready on these nodes func ValidatePxPodsAreReadyOnGivenNodes(clusterSpec *corev1.StorageCluster, nodeList []v1.Node, timeout, interval time.Duration) error { labelSelector := map[string]string{"name": "portworx"} diff --git a/test/integration_test/basic_test.go b/test/integration_test/basic_test.go index a7451c7b40..452b69a226 100644 --- a/test/integration_test/basic_test.go +++ b/test/integration_test/basic_test.go @@ -35,6 +35,8 @@ const ( var ( pxVer2_9, _ = version.NewVersion("2.9") pxVer2_12, _ = version.NewVersion("2.12") + + ocpVer4_14, _ = version.NewVersion("4.14") ) var testStorageClusterBasicCases = []types.TestCase{ @@ -181,7 +183,21 @@ var testStorageClusterBasicCases = []types.TestCase{ ShouldSkip: func(tc *types.TestCase) bool { skip := ci_utils.PxOperatorVersion.LessThan(ci_utils.PxOperatorVer23_8) if skip { - logrus.Info("Skipping BasicGrafanaRegression since operator version is less than 23.8.x") + logrus.Info("Skipping BasicGrafanaRegression, because PX Operator version is less than 23.8") + } + + if testutil.IsOpenshiftCluster() { + ocpVer, err := testutil.GetOpenshiftVersion() + if err != nil { + logrus.Warnf("Skipping BasicGrafanaRegression, because not able to determine Openshift version, Err: %v", err) + skip = true + } + + ocpVersion, _ := version.NewVersion(ocpVer) + if ocpVersion.GreaterThanOrEqual(ocpVer4_14) { + logrus.Warnf("Skipping BasicGrafanaRegression, because Openshift version is [%s] which is higher than 4.14, PX Prometheus is not supported here and will skip this test", ocpVer) + skip = true + } } return skip }, diff --git a/test/integration_test/utils/storagecluster.go b/test/integration_test/utils/storagecluster.go index 754b6026ad..eaca94c5a6 100644 --- a/test/integration_test/utils/storagecluster.go +++ b/test/integration_test/utils/storagecluster.go @@ -1,24 +1,25 @@ package utils import ( + "fmt" "path" "strings" "testing" - "github.com/libopenstorage/cloudops" - - "github.com/sirupsen/logrus" - "github.com/stretchr/testify/require" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/runtime" - "github.com/hashicorp/go-version" + "github.com/libopenstorage/cloudops" "github.com/libopenstorage/operator/drivers/storage/portworx" corev1 "github.com/libopenstorage/operator/pkg/apis/core/v1" k8sutil "github.com/libopenstorage/operator/pkg/util/k8s" testutil "github.com/libopenstorage/operator/pkg/util/test" + schedopsCore "github.com/portworx/sched-ops/k8s/core" "github.com/portworx/sched-ops/k8s/operator" + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/require" + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) const ( @@ -26,6 +27,11 @@ const ( specDir = "./operator-test" ) +var ( + // Openshift version where we do not support PX Prometheus any more + ocpVer4_14, _ = version.NewVersion("4.14") +) + // CreateStorageClusterTestSpecFunc creates a function that returns test specs for a test case func CreateStorageClusterTestSpecFunc(cluster *corev1.StorageCluster) func(t *testing.T) interface{} { return func(t *testing.T) interface{} { @@ -72,6 +78,48 @@ func ConstructStorageCluster(cluster *corev1.StorageCluster, specGenURL string, envVarList = append(envVarList, ocpEnvVarCreds...) } } + + // Configure Openshift Prometheus if version is 4.14+ + if testutil.IsOpenshiftCluster() { + ocpVer, err := testutil.GetOpenshiftVersion() + if err != nil { + return err + } + ocpVersion, _ := version.NewVersion(ocpVer) + if ocpVersion.GreaterThanOrEqual(ocpVer4_14) { + // Deploy Openshift Prometheus ConfigMap + ocpConfigmap := &v1.ConfigMap{ + ObjectMeta: meta_v1.ObjectMeta{ + Name: "cluster-monitoring-config", + Namespace: "openshift-monitoring", + }, + Data: map[string]string{ + "config.yaml": "enableUserWorkload: true", + }, + } + _, err = schedopsCore.Instance().GetConfigMap(ocpConfigmap.Name, ocpConfigmap.Namespace) + if err != nil { + if errors.IsNotFound(err) { + logrus.Debugf("Creating ConfigMap [%s] in namespace [%s]", ocpConfigmap.Name, ocpConfigmap.Namespace) + _, err = schedopsCore.Instance().CreateConfigMap(ocpConfigmap) + if err != nil { + return fmt.Errorf("failed to create ConfigMap [%s] in namesapce [%s], Err: %v", ocpConfigmap.Name, ocpConfigmap.Namespace, err) + } + logrus.Debugf("Successfully created ConfigMap [%s] in namespace [%s]", ocpConfigmap.Name, ocpConfigmap.Namespace) + } else { + return fmt.Errorf("failed to get ConfigMap [%s] in namespace [%s], Err: %v", ocpConfigmap.Name, ocpConfigmap.Namespace, err) + } + } else { + logrus.Debugf("ConfigMap [%s] already exists in [%s] namespace, will skip creating one", ocpConfigmap.Name, ocpConfigmap.Namespace) + } + + // Do not enable Portworx Prometheus as it is not supported on Openshift 4.14+ + if cluster.Spec.Monitoring != nil && cluster.Spec.Monitoring.Prometheus != nil && cluster.Spec.Monitoring.Prometheus.Enabled { + logrus.Debugf("Disabling PX Prometheus as it is not supported on Openshift [%s] and above", ocpVer) + cluster.Spec.Monitoring.Prometheus.Enabled = false + } + } + } } // Add EKS annotation