Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PTX-22144 Fix tests for autopilot changes on OCP 4.14+ #1421

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion pkg/util/test/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
cryptoTls "crypto/tls"
"encoding/base64"
"fmt"
routev1 "github.com/openshift/api/route/v1"
"io"
"net"
"net/http"
Expand All @@ -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"
Expand Down Expand Up @@ -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"}
Expand Down
18 changes: 17 additions & 1 deletion test/integration_test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
},
Expand Down
64 changes: 56 additions & 8 deletions test/integration_test/utils/storagecluster.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
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 (
// specDir is a directory with all the specs
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{} {
Expand Down Expand Up @@ -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
Expand Down
Loading