ceph: adds scripts and components to support admission controllers
adds deploy.sh script to deploy validatingwebhookconfiguration and create secrets. adds new command ceph admission-controller to start webhook servers. adds validation for various rook custom resources Signed-off-by: Vineet Badrinath <vbadrina@redhat.com>
This commit is contained in:
1 parent
675c9673ca
commit
ce1003aef8
27 files changed
+1088
-19
No files matched your search
@@ -23,6 +23,7 @@ import (
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -95,19 +96,13 @@ func (h *CephInstaller) CreateCephOperator(namespace string) (err error) {
|
||||
h.k8shelper.ChangeHostnames()
|
||||
}
|
||||
|
||||
err = h.k8shelper.CreateNamespace(namespace)
|
||||
err = h.startAdmissionController(namespace)
|
||||
if err != nil {
|
||||
if errors.IsAlreadyExists(err) {
|
||||
logger.Warningf("Namespace %q already exists!!!", namespace)
|
||||
} else {
|
||||
return fmt.Errorf("failed to create namespace %q. %v", namespace, err)
|
||||
}
|
||||
return fmt.Errorf("Failed to start admission controllers: %v", err)
|
||||
}
|
||||
|
||||
if err = h.WipeDisks(namespace, 2); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rookOperator := h.Manifests.GetRookOperator(namespace)
|
||||
_, err = h.k8shelper.KubectlWithStdin(rookOperator, createFromStdinArgs...)
|
||||
if err != nil {
|
||||
@@ -119,6 +114,58 @@ func (h *CephInstaller) CreateCephOperator(namespace string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *CephInstaller) startAdmissionController(namespace string) error {
|
||||
err := h.k8shelper.CreateNamespace(namespace)
|
||||
if err != nil {
|
||||
if errors.IsAlreadyExists(err) {
|
||||
logger.Warningf("Namespace %q already exists!!!", namespace)
|
||||
} else {
|
||||
return fmt.Errorf("failed to create namespace %q. %v", namespace, err)
|
||||
}
|
||||
}
|
||||
currDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find current working directory. %v", err)
|
||||
}
|
||||
rootPath, err := findRookRoot(currDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find rook root. %v", err)
|
||||
}
|
||||
userHome, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find user home directory. %v", err)
|
||||
}
|
||||
err = h.k8shelper.MakeContext().Executor.ExecuteCommandWithEnv([]string{fmt.Sprintf("NAMESPACE=%s", namespace), fmt.Sprintf("HOME=%s", userHome)}, "bash", fmt.Sprintf("%s/tests/scripts/deploy_admission_controller_test.sh", rootPath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func findRookRoot(workingDir string) (string, error) {
|
||||
const folderToFind = "tests"
|
||||
workingDirectory, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to find current working directory. %v", err)
|
||||
}
|
||||
parentPath := workingDirectory
|
||||
userHome, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to find user home directory. %v", err)
|
||||
}
|
||||
for parentPath != userHome {
|
||||
fmt.Printf("parent path = %s\n", parentPath)
|
||||
_, err := os.Stat(path.Join(parentPath, folderToFind))
|
||||
if os.IsNotExist(err) {
|
||||
parentPath = filepath.Dir(parentPath)
|
||||
continue
|
||||
}
|
||||
return parentPath, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("rook root not found above directory %s", workingDir)
|
||||
}
|
||||
|
||||
// CreateRookOperatorViaHelm creates rook operator via Helm chart named local/rook present in local repo
|
||||
func (h *CephInstaller) CreateRookOperatorViaHelm(namespace, chartSettings string) error {
|
||||
// creating clusterrolebinding for kubeadm env.
|
||||
@@ -130,6 +177,11 @@ func (h *CephInstaller) CreateRookOperatorViaHelm(namespace, chartSettings strin
|
||||
return fmt.Errorf("Failed to get Version of helm chart %v, err : %v", helmChartName, err)
|
||||
}
|
||||
|
||||
err = h.startAdmissionController(namespace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to start admission controllers: %v", err)
|
||||
}
|
||||
|
||||
err = h.helmHelper.InstallLocalRookHelmChart(helmChartName, helmDeployName, helmTag, namespace, chartSettings)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to install rook operator via helm, err : %v", err)
|
||||
@@ -139,7 +191,6 @@ func (h *CephInstaller) CreateRookOperatorViaHelm(namespace, chartSettings strin
|
||||
if err = h.WipeDisks(namespace, 2); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -388,7 +439,7 @@ func (h *CephInstaller) GetNodeHostnames() ([]string, error) {
|
||||
|
||||
// InstallRook installs rook on k8s
|
||||
func (h *CephInstaller) InstallRook(namespace, storeType string, usePVC bool, storageClassName string,
|
||||
mon cephv1.MonSpec, startWithAllNodes bool, rbdMirrorWorkers int, skipOSDCreation bool) (bool, error) {
|
||||
mon cephv1.MonSpec, startWithAllNodes bool, rbdMirrorWorkers int, skipOSDCreation bool, rookVersion string) (bool, error) {
|
||||
|
||||
var err error
|
||||
k8sversion := h.k8shelper.GetK8sServerVersion()
|
||||
@@ -410,7 +461,6 @@ func (h *CephInstaller) InstallRook(namespace, storeType string, usePVC bool, st
|
||||
}
|
||||
} else {
|
||||
onamespace = SystemNamespace(namespace)
|
||||
|
||||
err := h.CreateCephOperator(onamespace)
|
||||
if err != nil {
|
||||
logger.Errorf("Rook Operator not installed ,error -> %v", err)
|
||||
@@ -449,6 +499,13 @@ func (h *CephInstaller) InstallRook(namespace, storeType string, usePVC bool, st
|
||||
return false, err
|
||||
}
|
||||
logger.Infof("installed rook operator and cluster : %s on k8s %s", namespace, h.k8sVersion)
|
||||
|
||||
if rookVersion != Version1_2 {
|
||||
if !h.k8shelper.IsPodInExpectedState("rook-ceph-admission-controller", onamespace, "Running") {
|
||||
assert.Fail(h.T(), "admission controller is not running")
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -546,6 +603,7 @@ func (h *CephInstaller) UninstallRookFromMultipleNS(systemNamespace string, name
|
||||
}
|
||||
checkError(h.T(), err, "cannot uninstall rook-operator")
|
||||
|
||||
h.k8shelper.Clientset.AdmissionregistrationV1beta1().ValidatingWebhookConfigurations().Delete("rook-ceph-webhook", nil)
|
||||
h.k8shelper.Clientset.RbacV1beta1().RoleBindings(systemNamespace).Delete("rook-ceph-system", nil)
|
||||
h.k8shelper.Clientset.RbacV1beta1().ClusterRoleBindings().Delete("rook-ceph-global", nil)
|
||||
h.k8shelper.Clientset.RbacV1beta1().ClusterRoleBindings().Delete("rook-ceph-mgr-cluster", nil)
|
||||
|
||||
@@ -1586,6 +1586,35 @@ subjects:
|
||||
name: rook-csi-cephfs-plugin-sa
|
||||
namespace: ` + namespace + `
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: rook-ceph-admission-controller
|
||||
namespace: ` + namespace + `
|
||||
---
|
||||
kind: ClusterRole
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
name: rook-ceph-admission-controller-role
|
||||
rules:
|
||||
- apiGroups: ["ceph.rook.io"]
|
||||
resources: ["*"]
|
||||
verbs: ["get", "watch", "list"]
|
||||
---
|
||||
kind: ClusterRoleBinding
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
name: rook-ceph-admission-controller-rolebinding
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: rook-ceph-admission-controller
|
||||
apiGroup: ""
|
||||
namespace: ` + namespace + `
|
||||
roleRef:
|
||||
kind: ClusterRole
|
||||
name: rook-ceph-admission-controller-role
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
|
||||
@@ -1122,8 +1122,10 @@ func (k8sh *K8sHelper) IsPodInExpectedState(podNamePattern string, namespace str
|
||||
podList, err := k8sh.Clientset.CoreV1().Pods(namespace).List(listOpts)
|
||||
if err == nil {
|
||||
if len(podList.Items) >= 1 {
|
||||
if podList.Items[0].Status.Phase == v1.PodPhase(state) {
|
||||
return true
|
||||
for _, pod := range podList.Items {
|
||||
if pod.Status.Phase == v1.PodPhase(state) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user