diff --git a/tests/framework/installer/ceph_installer.go b/tests/framework/installer/ceph_installer.go index e7fed2c15..f59497166 100644 --- a/tests/framework/installer/ceph_installer.go +++ b/tests/framework/installer/ceph_installer.go @@ -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") diff --git a/tests/framework/installer/ceph_manifests.go b/tests/framework/installer/ceph_manifests.go index 60b1ddac7..873e4913a 100644 --- a/tests/framework/installer/ceph_manifests.go +++ b/tests/framework/installer/ceph_manifests.go @@ -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") } diff --git a/tests/framework/installer/ceph_manifests_previous.go b/tests/framework/installer/ceph_manifests_previous.go index 0b675c8ff..c0904a328 100644 --- a/tests/framework/installer/ceph_manifests_previous.go +++ b/tests/framework/installer/ceph_manifests_previous.go @@ -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 diff --git a/tests/framework/installer/ceph_settings.go b/tests/framework/installer/ceph_settings.go index d207d1a33..055c3b6b7 100644 --- a/tests/framework/installer/ceph_settings.go +++ b/tests/framework/installer/ceph_settings.go @@ -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"`) diff --git a/tests/framework/utils/k8s_helper.go b/tests/framework/utils/k8s_helper.go index 207dfa1c0..fa165ca61 100644 --- a/tests/framework/utils/k8s_helper.go +++ b/tests/framework/utils/k8s_helper.go @@ -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) } diff --git a/tests/integration/ceph_upgrade_test.go b/tests/integration/ceph_upgrade_test.go index 6bd9793a8..4d0067101 100644 --- a/tests/integration/ceph_upgrade_test.go +++ b/tests/integration/ceph_upgrade_test.go @@ -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()))