tests: enable csi operator for go test suites

Create the CSI operator in the go integration test suites
to test the new CSI operator scenarios. For the upgrade
test suite, enable the CSI operator after the upgrade
to verify the working cluster after it is enabled.

Signed-off-by: subhamkrai <srai@redhat.com>
This commit is contained in:
Travis Nielsen authored and subhamkrai committed 2025-03-19 21:02:05 +05:30
1 parent e5f1d9f589
commit c7e5a4c236
6 files changed
+76 -2

No files matched your search

@@ -146,6 +146,11 @@ func (h *CephInstaller) CreateCephOperator() (err error) {
}
logger.Infof("Rook operator started")
if err := h.InstallCSIOperator(); err != nil {
return err
}
return nil
}
@@ -467,6 +472,45 @@ func (h *CephInstaller) GetNodeHostnames() ([]string, error) {
return names, nil
}
func (h *CephInstaller) InstallCSIOperator() error {
if h.settings.RookVersion == Version1_15 {
logger.Infof("Skipping the CSI operator installation for previous version of Rook")
return nil
}
logger.Infof("Starting the CSI operator")
_, err := h.k8shelper.KubectlWithStdin(h.Manifests.GetCSIOperator(), createFromStdinArgs...)
if err != nil {
return errors.Wrap(err, "failed to create csi-operator")
}
if !h.k8shelper.IsPodInExpectedStateWithLabel("control-plane=ceph-csi-op-controller-manager", h.settings.OperatorNamespace, "Running") {
logger.Error("csi-operator is not running")
h.k8shelper.GetLogsFromNamespace(h.settings.OperatorNamespace, "test-setup", utils.TestEnvName())
logger.Error("csi-operator is not Running, abort!")
return err
}
logger.Infof("CSI operator started")
return nil
}
func (h *CephInstaller) SetOperatorSetting(key, value string) error {
configmap := "rook-ceph-operator-config"
logger.Infof("applying configmap %q setting: %q -> %q", configmap, key, value)
ctx := context.TODO()
cm, err := h.k8shelper.Clientset.CoreV1().ConfigMaps(h.settings.OperatorNamespace).Get(ctx, configmap, metav1.GetOptions{})
if err != nil {
return errors.Wrapf(err, "error reading configmap %q", configmap)
}
cm.Data[key] = value
_, err = h.k8shelper.Clientset.CoreV1().ConfigMaps(h.settings.OperatorNamespace).Update(ctx, cm, metav1.UpdateOptions{})
if err != nil {
return errors.Wrapf(err, "failed to update configmap %q", configmap)
}
return nil
}
func (h *CephInstaller) installRookOperator() (bool, error) {
var err error
@@ -752,6 +796,14 @@ func (h *CephInstaller) UninstallRookFromMultipleNS(manifests ...CephManifests)
} else {
logger.Infof("done deleting all the resources in the operator manifest")
}
logger.Info("Removing the CSI operator")
_, err = h.k8shelper.KubectlWithStdin(h.Manifests.GetCSIOperator(), deleteFromStdinArgs...)
if err != nil {
logger.Errorf("failed to remove CSI operator. %v", err)
} else {
logger.Infof("done deleting the CSI operator")
}
}
logger.Info("removing the CRDs")
@@ -30,6 +30,7 @@ type CephManifests interface {
Settings() *TestCephSettings
GetCRDs(k8shelper *utils.K8sHelper) string
GetCSINFSRBAC() string
GetCSIOperator() string
GetOperator() string
GetCommon() string
GetCommonExternal() string
@@ -99,6 +100,11 @@ func (m *CephManifestsMaster) GetOperator() string {
return m.settings.replaceOperatorSettings(manifest)
}
func (m *CephManifestsMaster) GetCSIOperator() string {
manifest := m.settings.readManifest("csi-operator.yaml")
return m.settings.replaceCSIOperatorSettings(m.settings.OperatorNamespace, manifest)
}
func (m *CephManifestsMaster) GetCommonExternal() string {
return m.settings.readManifest("common-external.yaml")
}
@@ -45,6 +45,10 @@ func (m *CephManifestsPreviousVersion) GetCSINFSRBAC() string {
return m.settings.readManifestFromGitHub("/csi/nfs/rbac.yaml")
}
func (m *CephManifestsPreviousVersion) GetCSIOperator() string {
return "not-supported"
}
// GetRookOperator returns rook Operator manifest
func (m *CephManifestsPreviousVersion) GetOperator() string {
var manifest string
@@ -80,6 +80,11 @@ func (s *TestCephSettings) readManifestFromGitHubWithClusterNamespace(filename,
return replaceNamespaces(filename, manifest, s.OperatorNamespace, clusterNamespace)
}
func (s *TestCephSettings) replaceCSIOperatorSettings(csiNamespace, manifest string) string {
manifest = strings.ReplaceAll(manifest, `namespace: rook-ceph`, `namespace: `+csiNamespace)
return manifest
}
func (s *TestCephSettings) replaceOperatorSettings(manifest string) string {
manifest = strings.ReplaceAll(manifest, `ROOK_LOG_LEVEL: "INFO"`, `ROOK_LOG_LEVEL: "DEBUG"`)
manifest = strings.ReplaceAll(manifest, `# CSI_LOG_LEVEL: "0"`, `CSI_LOG_LEVEL: "5"`)
+6 -2
View File
@@ -1057,7 +1057,11 @@ func (k8sh *K8sHelper) GetPV(name string) (*v1.PersistentVolume, error) {
// IsPodInExpectedState waits for 90s for a pod to be an expected state
// If the pod is in expected state within 90s true is returned, if not false
func (k8sh *K8sHelper) IsPodInExpectedState(podNamePattern string, namespace string, state string) bool {
listOpts := metav1.ListOptions{LabelSelector: "app=" + podNamePattern}
return k8sh.IsPodInExpectedStateWithLabel("app="+podNamePattern, namespace, state)
}
func (k8sh *K8sHelper) IsPodInExpectedStateWithLabel(label, namespace, state string) bool {
listOpts := metav1.ListOptions{LabelSelector: label}
ctx := context.TODO()
for i := 0; i < RetryLoop; i++ {
podList, err := k8sh.Clientset.CoreV1().Pods(namespace).List(ctx, listOpts)
@@ -1069,7 +1073,7 @@ func (k8sh *K8sHelper) IsPodInExpectedState(podNamePattern string, namespace str
}
}
logger.Infof("waiting for pod with label app=%s in namespace %q to be in state %q...", podNamePattern, namespace, state)
logger.Infof("waiting for pod with label %s in namespace %q to be in state %q...", label, namespace, state)
time.Sleep(RetryInterval * time.Second)
}
+3
View File
@@ -452,6 +452,9 @@ func (s *UpgradeSuite) upgradeToMaster() {
return
}
require.NoError(s.T(), s.installer.InstallCSIOperator())
require.NoError(s.T(), s.installer.SetOperatorSetting("ROOK_USE_CSI_OPERATOR", "false"))
require.NoError(s.T(), s.k8sh.ResourceOperation("apply", s.installer.Manifests.GetCRDs(s.k8sh)))
require.NoError(s.T(), s.k8sh.ResourceOperation("apply", s.installer.Manifests.GetCommon()))