cockroachdb: integration tests and scripts
Signed-off-by: Jared Watts <jbw976@gmail.com>
This commit is contained in:
14 files changed
+735
-73
No files matched your search
Vendored
+1
-1
@@ -64,7 +64,7 @@ pipeline {
|
||||
}
|
||||
steps{
|
||||
sh 'cat _output/version | xargs tests/scripts/makeTestImages.sh save amd64'
|
||||
stash name: 'repo-amd64',includes: 'ceph-amd64.tar,build/common.sh,_output/tests/linux_amd64/,_output/charts/,tests/scripts/'
|
||||
stash name: 'repo-amd64',includes: 'ceph-amd64.tar,cockroachdb-amd64.tar,build/common.sh,_output/tests/linux_amd64/,_output/charts/,tests/scripts/'
|
||||
script{
|
||||
def data = [
|
||||
"aws_1.7.x": "v1.7.11",
|
||||
|
||||
@@ -64,9 +64,8 @@ spec:
|
||||
}
|
||||
|
||||
logger.Infof("Make sure rook-ceph-mds pod is running")
|
||||
running, err := f.k8sh.WaitForLabeledPodToRun(fmt.Sprintf("rook_file_system=%s", name), namespace)
|
||||
err := f.k8sh.WaitForLabeledPodToRun(fmt.Sprintf("rook_file_system=%s", name), namespace)
|
||||
assert.Nil(f.k8sh.T(), err)
|
||||
assert.True(f.k8sh.T(), running)
|
||||
|
||||
assert.True(f.k8sh.T(), f.k8sh.CheckPodCountAndState("rook-ceph-mds", namespace, 2, "Running"),
|
||||
"Make sure there are two rook-ceph-mds pods present in Running state")
|
||||
|
||||
@@ -66,8 +66,8 @@ spec:
|
||||
return err
|
||||
}
|
||||
|
||||
running, err := ro.k8sh.WaitForLabeledPodToRun(fmt.Sprintf("rook_object_store=%s", storeName), namespace)
|
||||
if !running || err != nil {
|
||||
err := ro.k8sh.WaitForLabeledPodToRun(fmt.Sprintf("rook_object_store=%s", storeName), namespace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("rgw did not start via crd. %+v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
Copyright 2018 The Rook Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package installer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func (h *InstallHelper) InstallCockroachDB(systemNamespace, namespace string, count int) error {
|
||||
h.k8shelper.CreateAnonSystemClusterBinding()
|
||||
|
||||
// install hostpath provisioner if there isn't already a default storage class
|
||||
defaultExists, err := h.k8shelper.IsDefaultStorageClassPresent()
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !defaultExists {
|
||||
if err := h.InstallHostPathProvisioner(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
logger.Info("skipping install of host path provisioner because a default storage class already exists")
|
||||
}
|
||||
|
||||
// install cockroachdb operator
|
||||
if err := h.CreateCockroachDBOperator(systemNamespace); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// install cockroachdb cluster instance
|
||||
if err := h.CreateCockroachDBCluster(namespace, count); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *InstallHelper) CreateCockroachDBOperator(namespace string) error {
|
||||
logger.Infof("starting cockroachDB operator")
|
||||
|
||||
logger.Info("creating cockroachDB CRDs")
|
||||
if _, err := h.k8shelper.KubectlWithStdin(h.installData.GetCockroachDBCRDs(), createFromStdinArgs...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cockroachDBOperator := h.installData.GetCockroachDBOperator(namespace)
|
||||
_, err := h.k8shelper.KubectlWithStdin(cockroachDBOperator, createFromStdinArgs...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create rook-cockroachdb-operator pod: %+v ", err)
|
||||
}
|
||||
|
||||
if !h.k8shelper.IsCRDPresent(cockroachDBCRD) {
|
||||
return fmt.Errorf("failed to find cockroachdb CRD %s", cockroachDBCRD)
|
||||
}
|
||||
|
||||
if !h.k8shelper.IsPodInExpectedState("rook-cockroachdb-operator", namespace, "Running") {
|
||||
return fmt.Errorf("rook-cockroachdb-operator is not running, aborting")
|
||||
}
|
||||
|
||||
logger.Infof("cockroachdb operator started")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *InstallHelper) CreateCockroachDBCluster(namespace string, count int) error {
|
||||
if err := h.k8shelper.CreateNamespace(namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Infof("starting cockroachdb cluster with kubectl and yaml")
|
||||
cockroachDBCluster := h.installData.GetCockroachDBCluster(namespace, count)
|
||||
if _, err := h.k8shelper.KubectlWithStdin(cockroachDBCluster, createFromStdinArgs...); err != nil {
|
||||
return fmt.Errorf("Failed to create cockroachdb cluster: %+v ", err)
|
||||
}
|
||||
|
||||
if err := h.k8shelper.WaitForPodCount("app=rook-cockroachdb", namespace, count); err != nil {
|
||||
logger.Errorf("cockroachdb cluster pods in namespace %s not found", namespace)
|
||||
return err
|
||||
}
|
||||
|
||||
err := h.k8shelper.WaitForLabeledPodToRun("app=rook-cockroachdb", namespace)
|
||||
if err != nil {
|
||||
logger.Errorf("cockroachdb cluster pods in namespace %s are not running", namespace)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Infof("cockroachdb cluster started")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *InstallHelper) UninstallCockroachDB(systemNamespace, namespace string) {
|
||||
logger.Infof("uninstalling cockroachdb from namespace %s", namespace)
|
||||
|
||||
_, err := h.k8shelper.DeleteResource("-n", namespace, "cluster.cockroachdb.rook.io", namespace)
|
||||
h.checkError(err, fmt.Sprintf("cannot remove cluster %s", namespace))
|
||||
|
||||
crdCheckerFunc := func() error {
|
||||
_, err := h.k8shelper.RookClientset.CockroachdbV1alpha1().Clusters(namespace).Get(namespace, metav1.GetOptions{})
|
||||
return err
|
||||
}
|
||||
err = h.waitForCustomResourceDeletion(namespace, crdCheckerFunc)
|
||||
h.checkError(err, fmt.Sprintf("failed to wait for crd %s deletion", namespace))
|
||||
|
||||
_, err = h.k8shelper.DeleteResource("namespace", namespace)
|
||||
h.checkError(err, fmt.Sprintf("cannot delete namespace %s", namespace))
|
||||
|
||||
logger.Infof("removing the operator from namespace %s", systemNamespace)
|
||||
_, err = h.k8shelper.DeleteResource("crd", "clusters.cockroachdb.rook.io")
|
||||
h.checkError(err, "cannot delete CRDs")
|
||||
|
||||
cockroachDBOperator := h.installData.GetCockroachDBOperator(systemNamespace)
|
||||
_, err = h.k8shelper.KubectlWithStdin(cockroachDBOperator, deleteFromStdinArgs...)
|
||||
h.checkError(err, "cannot uninstall rook-cockroachdb-operator")
|
||||
|
||||
err = h.UninstallHostPathProvisioner()
|
||||
h.checkError(err, "cannot uninstall hostpath provisioner")
|
||||
|
||||
h.k8shelper.Clientset.RbacV1beta1().ClusterRoleBindings().Delete("anon-user-access", nil)
|
||||
logger.Infof("done removing the operator from namespace %s", systemNamespace)
|
||||
}
|
||||
|
||||
func (h *InstallHelper) GatherAllCockroachDBLogs(systemNamespace, namespace, testName string) {
|
||||
logger.Infof("Gathering all logs from cockroachdb cluster %s", namespace)
|
||||
h.k8shelper.GetRookLogs("rook-cockroachdb-operator", h.Env.HostType, systemNamespace, testName)
|
||||
h.k8shelper.GetRookLogs("rook-cockroachdb", h.Env.HostType, namespace, testName)
|
||||
}
|
||||
|
||||
func (i *InstallData) GetCockroachDBCRDs() string {
|
||||
return `apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: clusters.cockroachdb.rook.io
|
||||
spec:
|
||||
group: cockroachdb.rook.io
|
||||
names:
|
||||
kind: Cluster
|
||||
listKind: ClusterList
|
||||
plural: clusters
|
||||
singular: cluster
|
||||
scope: Namespaced
|
||||
version: v1alpha1
|
||||
`
|
||||
}
|
||||
|
||||
func (i *InstallData) GetCockroachDBOperator(namespace string) string {
|
||||
|
||||
return `kind: Namespace
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: ` + namespace + `
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: rook-cockroachdb-operator
|
||||
rules:
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- pods
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- services
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- create
|
||||
- update
|
||||
- apiGroups:
|
||||
- apps
|
||||
resources:
|
||||
- statefulsets
|
||||
verbs:
|
||||
- create
|
||||
- apiGroups:
|
||||
- policy
|
||||
resources:
|
||||
- poddisruptionbudgets
|
||||
verbs:
|
||||
- create
|
||||
- apiGroups:
|
||||
- cockroachdb.rook.io
|
||||
resources:
|
||||
- "*"
|
||||
verbs:
|
||||
- "*"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: rook-cockroachdb-operator
|
||||
namespace: ` + namespace + `
|
||||
---
|
||||
kind: ClusterRoleBinding
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
metadata:
|
||||
name: rook-cockroachdb-operator
|
||||
namespace: ` + namespace + `
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: rook-cockroachdb-operator
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: rook-cockroachdb-operator
|
||||
namespace: ` + namespace + `
|
||||
---
|
||||
apiVersion: apps/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: rook-cockroachdb-operator
|
||||
namespace: ` + namespace + `
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: rook-cockroachdb-operator
|
||||
spec:
|
||||
serviceAccountName: rook-cockroachdb-operator
|
||||
containers:
|
||||
- name: rook-cockroachdb-operator
|
||||
image: rook/cockroachdb:master
|
||||
args: ["cockroachdb", "operator"]
|
||||
env:
|
||||
- name: POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
`
|
||||
}
|
||||
|
||||
func (i *InstallData) GetCockroachDBCluster(namespace string, count int) string {
|
||||
return `apiVersion: cockroachdb.rook.io/v1alpha1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
name: ` + namespace + `
|
||||
namespace: ` + namespace + `
|
||||
spec:
|
||||
scope:
|
||||
nodeCount: ` + strconv.Itoa(count) + `
|
||||
secure: false
|
||||
volumeSize: 1Gi
|
||||
cachePercent: 25
|
||||
maxSQLMemoryPercent: 25
|
||||
`
|
||||
}
|
||||
|
||||
func GatherCockroachDBDebuggingInfo(k8shelper *utils.K8sHelper, namespace string) {
|
||||
k8shelper.PrintPodDescribeForNamespace(namespace)
|
||||
k8shelper.PrintPVs(true /*detailed*/)
|
||||
k8shelper.PrintPVCs(namespace, true /*detailed*/)
|
||||
k8shelper.PrintStorageClasses(true /*detailed*/)
|
||||
}
|
||||
@@ -37,7 +37,6 @@ import (
|
||||
"github.com/rook/rook/tests/framework/objects"
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@@ -45,14 +44,17 @@ import (
|
||||
|
||||
const (
|
||||
rookOperatorCreatedCrd = "clusters.ceph.rook.io"
|
||||
cockroachDBCRD = "clusters.cockroachdb.rook.io"
|
||||
helmChartName = "local/rook-ceph"
|
||||
helmDeployName = "rook-ceph"
|
||||
)
|
||||
|
||||
var (
|
||||
logger = capnslog.NewPackageLogger("github.com/rook/rook", "installer")
|
||||
createArgs = []string{"create", "-f", "-"}
|
||||
deleteArgs = []string{"delete", "-f", "-"}
|
||||
logger = capnslog.NewPackageLogger("github.com/rook/rook", "installer")
|
||||
createArgs = []string{"create", "-f"}
|
||||
createFromStdinArgs = append(createArgs, "-")
|
||||
deleteArgs = []string{"delete", "-f"}
|
||||
deleteFromStdinArgs = append(deleteArgs, "-")
|
||||
)
|
||||
|
||||
//InstallHelper wraps installing and uninstalling rook on a platform
|
||||
@@ -71,7 +73,7 @@ func (h *InstallHelper) CreateK8sRookResources(namespace string) (err error) {
|
||||
|
||||
resources = h.installData.GetRookCRDs(namespace)
|
||||
|
||||
_, err = h.k8shelper.KubectlWithStdin(resources, createArgs...)
|
||||
_, err = h.k8shelper.KubectlWithStdin(resources, createFromStdinArgs...)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -89,7 +91,7 @@ func (h *InstallHelper) CreateK8sRookOperator(namespace string) (err error) {
|
||||
|
||||
rookOperator := h.installData.GetRookOperator(namespace)
|
||||
|
||||
_, err = h.k8shelper.KubectlWithStdin(rookOperator, createArgs...)
|
||||
_, err = h.k8shelper.KubectlWithStdin(rookOperator, createFromStdinArgs...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create rook-operator pod : %v ", err)
|
||||
}
|
||||
@@ -133,7 +135,7 @@ func (h *InstallHelper) CreateK8sRookToolbox(namespace string) (err error) {
|
||||
|
||||
rookToolbox := h.installData.GetRookToolBox(namespace)
|
||||
|
||||
_, err = h.k8shelper.KubectlWithStdin(rookToolbox, createArgs...)
|
||||
_, err = h.k8shelper.KubectlWithStdin(rookToolbox, createFromStdinArgs...)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create rook-toolbox pod : %v ", err)
|
||||
@@ -156,13 +158,11 @@ func (h *InstallHelper) CreateK8sRookCluster(namespace string, storeType string)
|
||||
func (h *InstallHelper) CreateK8sRookClusterWithHostPathAndDevices(namespace, storeType, dataDirHostPath string,
|
||||
useAllDevices bool, mon cephv1alpha1.MonSpec, startWithAllNodes bool) error {
|
||||
|
||||
ns := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
|
||||
_, err := h.k8shelper.Clientset.CoreV1().Namespaces().Create(ns)
|
||||
if err != nil && !errors.IsAlreadyExists(err) {
|
||||
return fmt.Errorf("failed to create namespace %s. %+v", namespace, err)
|
||||
if err := h.k8shelper.CreateNamespace(namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if h.k8shelper.VersionAtLeast("v1.8.0") {
|
||||
if h.k8shelper.IsRookClientsetAvailable() {
|
||||
logger.Infof("Starting Rook cluster with strongly typed clientset")
|
||||
|
||||
clust := &v1alpha1.Cluster{
|
||||
@@ -189,7 +189,7 @@ func (h *InstallHelper) CreateK8sRookClusterWithHostPathAndDevices(namespace, st
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err = h.k8shelper.RookClientset.CephV1alpha1().Clusters(namespace).Create(clust)
|
||||
_, err := h.k8shelper.RookClientset.CephV1alpha1().Clusters(namespace).Create(clust)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create cluster %s. %+v", clust.Name, err)
|
||||
}
|
||||
@@ -222,23 +222,21 @@ func (h *InstallHelper) CreateK8sRookClusterWithHostPathAndDevices(namespace, st
|
||||
} else {
|
||||
logger.Infof("Starting Rook Cluster with yaml")
|
||||
rookCluster := h.installData.GetRookCluster(namespace, storeType, dataDirHostPath, useAllDevices, mon.Count)
|
||||
if _, err := h.k8shelper.KubectlWithStdin(rookCluster, createArgs...); err != nil {
|
||||
if _, err := h.k8shelper.KubectlWithStdin(rookCluster, createFromStdinArgs...); err != nil {
|
||||
return fmt.Errorf("Failed to create rook cluster : %v ", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = h.k8shelper.WaitForPodCount("app=rook-ceph-mon", namespace, mon.Count)
|
||||
if err != nil {
|
||||
if err := h.k8shelper.WaitForPodCount("app=rook-ceph-mon", namespace, mon.Count); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = h.k8shelper.WaitForPodCount("app=rook-ceph-osd", namespace, 1)
|
||||
if err != nil {
|
||||
if err := h.k8shelper.WaitForPodCount("app=rook-ceph-osd", namespace, 1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Infof("Rook Cluster started")
|
||||
_, err = h.k8shelper.WaitForLabeledPodToRun("app=rook-ceph-osd", namespace)
|
||||
err := h.k8shelper.WaitForLabeledPodToRun("app=rook-ceph-osd", namespace)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -279,7 +277,7 @@ func (h *InstallHelper) InstallRookOnK8sWithHostPathAndDevices(namespace, storeT
|
||||
}
|
||||
}
|
||||
if !h.k8shelper.IsPodInExpectedState("rook-ceph-operator", onamespace, "Running") {
|
||||
fmt.Println("rook-ceph-operator is not running")
|
||||
logger.Error("rook-ceph-operator is not running")
|
||||
h.k8shelper.GetRookLogs("rook-ceph-operator", h.Env.HostType, onamespace, "test-setup")
|
||||
logger.Error("rook-ceph-operator is not Running, abort!")
|
||||
return false, err
|
||||
@@ -333,11 +331,15 @@ func (h *InstallHelper) UninstallRookFromMultipleNS(helmInstalled bool, systemNa
|
||||
assert.NoError(h.T(), err, "rook-ceph-osd cluster role and binding cannot be deleted: %+v", err)
|
||||
}
|
||||
|
||||
_, err = h.k8shelper.DeleteResource("-n", namespace, "cluster", namespace)
|
||||
_, err = h.k8shelper.DeleteResource("-n", namespace, "cluster.ceph.rook.io", namespace)
|
||||
h.checkError(err, fmt.Sprintf("cannot remove cluster %s", namespace))
|
||||
|
||||
err = h.waitForCustomResourceDeletion(namespace)
|
||||
h.checkError(err, fmt.Sprintf("failed to wait for namespace %s deletion", namespace))
|
||||
crdCheckerFunc := func() error {
|
||||
_, err := h.k8shelper.RookClientset.RookV1alpha1().Clusters(namespace).Get(namespace, metav1.GetOptions{})
|
||||
return err
|
||||
}
|
||||
err = h.waitForCustomResourceDeletion(namespace, crdCheckerFunc)
|
||||
h.checkError(err, fmt.Sprintf("failed to wait for crd %s deletion", namespace))
|
||||
|
||||
_, err = h.k8shelper.DeleteResource("namespace", namespace)
|
||||
h.checkError(err, fmt.Sprintf("cannot delete namespace %s", namespace))
|
||||
@@ -351,7 +353,7 @@ func (h *InstallHelper) UninstallRookFromMultipleNS(helmInstalled bool, systemNa
|
||||
err = h.helmHelper.DeleteLocalRookHelmChart(helmDeployName)
|
||||
} else {
|
||||
rookOperator := h.installData.GetRookOperator(systemNamespace)
|
||||
_, err = h.k8shelper.KubectlWithStdin(rookOperator, deleteArgs...)
|
||||
_, err = h.k8shelper.KubectlWithStdin(rookOperator, deleteFromStdinArgs...)
|
||||
}
|
||||
h.checkError(err, "cannot uninstall rook-operator")
|
||||
|
||||
@@ -369,27 +371,27 @@ func (h *InstallHelper) checkError(err error, message string) {
|
||||
assert.NoError(h.T(), err, "%s. %+v", message, err)
|
||||
}
|
||||
|
||||
func (h *InstallHelper) waitForCustomResourceDeletion(namespace string) error {
|
||||
func (h *InstallHelper) waitForCustomResourceDeletion(namespace string, checkerFunc func() error) error {
|
||||
if !h.k8shelper.VersionAtLeast("v1.8.0") {
|
||||
// v1.7 has an intermittent issue with long delay to delete resources so we will skip waiting
|
||||
return nil
|
||||
}
|
||||
|
||||
// wait for the operator to finalize and delete the cluster CRD
|
||||
// wait for the operator to finalize and delete the CRD
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err := h.k8shelper.RookClientset.RookV1alpha1().Clusters(namespace).Get(namespace, metav1.GetOptions{})
|
||||
err := checkerFunc()
|
||||
if err == nil {
|
||||
logger.Infof("cluster %s still exists", namespace)
|
||||
logger.Infof("custom resource %s still exists", namespace)
|
||||
time.Sleep(2 * time.Second)
|
||||
continue
|
||||
}
|
||||
if errors.IsNotFound(err) {
|
||||
logger.Infof("cluster %s deleted", namespace)
|
||||
logger.Infof("custom resource %s deleted", namespace)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
logger.Errorf("gave up deleting custom cluster resource %s", namespace)
|
||||
logger.Errorf("gave up deleting custom resource %s", namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Copyright 2018 The Rook Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package installer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
hostPathStorageClassName = "hostpath"
|
||||
hostPathProvisionerResourceBaseURL = `https://raw.githubusercontent.com/MaZderMind/hostpath-provisioner/master/manifests/%s`
|
||||
hostPathProvisionerRBAC = `rbac.yaml`
|
||||
hostPathProvisionerDeployment = `deployment.yaml`
|
||||
hostPathProvisionerStorageClass = `storageclass.yaml`
|
||||
)
|
||||
|
||||
// ************************************************************************************************
|
||||
// HostPath provisioner functions
|
||||
// ************************************************************************************************
|
||||
func (h *InstallHelper) InstallHostPathProvisioner() error {
|
||||
logger.Info("installing host path provisioner")
|
||||
|
||||
rbacResourceURL := fmt.Sprintf(hostPathProvisionerResourceBaseURL, hostPathProvisionerRBAC)
|
||||
args := append(createArgs, rbacResourceURL)
|
||||
out, err := h.k8shelper.Kubectl(args...)
|
||||
if err != nil && !errors.IsAlreadyExists(err) {
|
||||
return fmt.Errorf("failed to create hostpath provisioner RBAC: %+v. %s", err, out)
|
||||
}
|
||||
|
||||
deploymentResourceURL := fmt.Sprintf(hostPathProvisionerResourceBaseURL, hostPathProvisionerDeployment)
|
||||
args = append(createArgs, deploymentResourceURL)
|
||||
out, err = h.k8shelper.Kubectl(args...)
|
||||
if err != nil && !errors.IsAlreadyExists(err) {
|
||||
return fmt.Errorf("failed to create hostpath provisioner deployment: %+v. %s", err, out)
|
||||
}
|
||||
|
||||
storageClassResourceURL := fmt.Sprintf(hostPathProvisionerResourceBaseURL, hostPathProvisionerStorageClass)
|
||||
args = append(createArgs, storageClassResourceURL)
|
||||
out, err = h.k8shelper.Kubectl(args...)
|
||||
if err != nil && !errors.IsAlreadyExists(err) {
|
||||
return fmt.Errorf("failed to create hostpath provisioner StorageClass: %+v. %s", err, out)
|
||||
}
|
||||
|
||||
err = h.k8shelper.WaitForLabeledPodToRun("k8s-app=hostpath-provisioner", "kube-system")
|
||||
if err != nil {
|
||||
logger.Errorf("hostpath provisioner pod is not running: %+v", err)
|
||||
h.k8shelper.PrintPodDescribeForNamespace("kube-system")
|
||||
h.k8shelper.PrintStorageClasses(true /*detailed*/)
|
||||
return err
|
||||
}
|
||||
|
||||
err = h.k8shelper.IsStorageClassPresent(hostPathStorageClassName)
|
||||
if err != nil {
|
||||
logger.Errorf("storageClass %s not found: %+v", hostPathStorageClassName, err)
|
||||
h.k8shelper.PrintStorageClasses(true /*detailed*/)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *InstallHelper) UninstallHostPathProvisioner() error {
|
||||
logger.Info("uninstalling host path provisioner")
|
||||
|
||||
storageClassResourceURL := fmt.Sprintf(hostPathProvisionerResourceBaseURL, hostPathProvisionerStorageClass)
|
||||
args := append(deleteArgs, storageClassResourceURL)
|
||||
out, err := h.k8shelper.Kubectl(args...)
|
||||
if err != nil && !utils.IsKubectlErrorNotFound(out, err) {
|
||||
return fmt.Errorf("failed to delete hostpath provisioner StorageClass: %+v. %s", err, out)
|
||||
}
|
||||
|
||||
deploymentResourceURL := fmt.Sprintf(hostPathProvisionerResourceBaseURL, hostPathProvisionerDeployment)
|
||||
args = append(deleteArgs, deploymentResourceURL)
|
||||
out, err = h.k8shelper.Kubectl(args...)
|
||||
if err != nil && !utils.IsKubectlErrorNotFound(out, err) {
|
||||
return fmt.Errorf("failed to delete hostpath provisioner deployment: %+v. %s", err, out)
|
||||
}
|
||||
|
||||
rbacResourceURL := fmt.Sprintf(hostPathProvisionerResourceBaseURL, hostPathProvisionerRBAC)
|
||||
args = append(deleteArgs, rbacResourceURL)
|
||||
out, err = h.k8shelper.Kubectl(args...)
|
||||
if err != nil && !utils.IsKubectlErrorNotFound(out, err) {
|
||||
return fmt.Errorf("failed to delete hostpath provisioner RBAC: %+v. %s", err, out)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
storagev1util "k8s.io/kubernetes/pkg/apis/storage/v1/util"
|
||||
"k8s.io/kubernetes/pkg/util/version"
|
||||
)
|
||||
|
||||
@@ -95,17 +96,20 @@ func (k8sh *K8sHelper) VersionAtLeast(minVersion string) bool {
|
||||
return v.AtLeast(version.MustParseSemantic(minVersion))
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) IsRookClientsetAvailable() bool {
|
||||
return k8sh.VersionAtLeast("v1.8.0")
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) MakeContext() *clusterd.Context {
|
||||
return &clusterd.Context{Clientset: k8sh.Clientset, RookClientset: k8sh.RookClientset, Executor: k8sh.executor}
|
||||
}
|
||||
|
||||
//Kubectl is wrapper for executing kubectl commands
|
||||
func (k8sh *K8sHelper) Kubectl(args ...string) (string, error) {
|
||||
result, err := k8sh.executor.ExecuteCommandWithOutput(false, "", "kubectl", args...)
|
||||
result, err := k8sh.executor.ExecuteCommandWithTimeout(false, 10*time.Second, "kubectl", "kubectl", args...)
|
||||
if err != nil {
|
||||
k8slogger.Errorf("Failed to execute: kubectl %v : %v", args, err)
|
||||
return "", fmt.Errorf("Failed to run: kubectl %v : %v", args, err)
|
||||
|
||||
k8slogger.Errorf("Failed to execute: kubectl %+v : %+v. %s", args, err, result)
|
||||
return result, fmt.Errorf("Failed to run: kubectl %v : %v", args, err)
|
||||
}
|
||||
return result, nil
|
||||
|
||||
@@ -234,6 +238,18 @@ type kuserContext struct {
|
||||
} `json:"user"`
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) Exec(namespace, podName, command string, commandArgs []string) (string, error) {
|
||||
args := []string{"exec", "-n", namespace, podName, "--", command}
|
||||
args = append(args, commandArgs...)
|
||||
result, err := k8sh.Kubectl(args...)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("kubectl exec command %s failed on pod %s in namespace %s: %+v. output: %s",
|
||||
command, podName, namespace, err, result)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
//ResourceOperationFromTemplate performs a kubectl action from a template file after replacing its context
|
||||
func (k8sh *K8sHelper) ResourceOperationFromTemplate(action string, podDefinition string, config map[string]string) (string, error) {
|
||||
|
||||
@@ -295,6 +311,16 @@ func (k8sh *K8sHelper) GetResource(args ...string) (string, error) {
|
||||
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) CreateNamespace(namespace string) error {
|
||||
ns := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
|
||||
_, err := k8sh.Clientset.CoreV1().Namespaces().Create(ns)
|
||||
if err != nil && !errors.IsAlreadyExists(err) {
|
||||
return fmt.Errorf("failed to create namespace %s. %+v", namespace, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) CountPodsWithLabel(label string, namespace string) (int, error) {
|
||||
options := metav1.ListOptions{LabelSelector: label}
|
||||
pods, err := k8sh.Clientset.CoreV1().Pods(namespace).List(options)
|
||||
@@ -318,7 +344,7 @@ func (k8sh *K8sHelper) WaitForPodCount(label, namespace string, count int) error
|
||||
}
|
||||
|
||||
if len(pods.Items) == count {
|
||||
logger.Infof("found for %d pods with label %s", count, label)
|
||||
logger.Infof("found %d pods with label %s", count, label)
|
||||
return nil
|
||||
}
|
||||
inc++
|
||||
@@ -326,7 +352,7 @@ func (k8sh *K8sHelper) WaitForPodCount(label, namespace string, count int) error
|
||||
logger.Infof("waiting for %d pods (found %d) with label %s in namespace %s", count, len(pods.Items), label, namespace)
|
||||
|
||||
}
|
||||
return fmt.Errorf("Giving up waiting for pods with label %s", label, namespace)
|
||||
return fmt.Errorf("Giving up waiting for pods with label %s in namespace %s", label, namespace)
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) IsPodWithLabelPresent(label string, namespace string) bool {
|
||||
@@ -338,7 +364,7 @@ func (k8sh *K8sHelper) IsPodWithLabelPresent(label string, namespace string) boo
|
||||
}
|
||||
|
||||
//WaitForLabeledPodToRun returns true if a Pod is running status or goes to Running status within 90s else returns false
|
||||
func (k8sh *K8sHelper) WaitForLabeledPodToRun(label string, namespace string) (bool, error) {
|
||||
func (k8sh *K8sHelper) WaitForLabeledPodToRun(label string, namespace string) error {
|
||||
options := metav1.ListOptions{LabelSelector: label}
|
||||
inc := 0
|
||||
for inc < RetryLoop {
|
||||
@@ -346,7 +372,7 @@ func (k8sh *K8sHelper) WaitForLabeledPodToRun(label string, namespace string) (b
|
||||
if err == nil && len(pods.Items) > 0 {
|
||||
for _, pod := range pods.Items {
|
||||
if pod.Status.Phase == "Running" {
|
||||
return true, nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,7 +380,7 @@ func (k8sh *K8sHelper) WaitForLabeledPodToRun(label string, namespace string) (b
|
||||
logger.Infof("waiting for pod with label %s in namespace %s to be running. err=%+v", label, namespace, err)
|
||||
time.Sleep(RetryInterval * time.Second)
|
||||
}
|
||||
return false, fmt.Errorf("Giving up waiting for pod with label %s in namespace %s to be running", label, namespace)
|
||||
return fmt.Errorf("Giving up waiting for pod with label %s in namespace %s to be running", label, namespace)
|
||||
}
|
||||
|
||||
//WaitUntilPodWithLabelDeleted returns true if a Pod is deleted within 90s else returns false
|
||||
@@ -383,7 +409,7 @@ func (k8sh *K8sHelper) WaitUntilPodWithLabelDeleted(label string, namespace stri
|
||||
func (k8sh *K8sHelper) PrintPodStatus(namespace string) {
|
||||
pods, err := k8sh.Clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
logger.Info("failed to get pod status in namespace %s. %+v", namespace, err)
|
||||
logger.Errorf("failed to get pod status in namespace %s. %+v", namespace, err)
|
||||
return
|
||||
}
|
||||
for _, pod := range pods.Items {
|
||||
@@ -391,6 +417,22 @@ func (k8sh *K8sHelper) PrintPodStatus(namespace string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) PrintPodDescribeForNamespace(namespace string) {
|
||||
logger.Infof("printing pod describe for all pods in namespace %s", namespace)
|
||||
|
||||
pods, err := k8sh.Clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
logger.Errorf("failed to list pods in namespace %s. %+v", namespace, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, p := range pods.Items {
|
||||
logger.Infof("pod %s in namespace %s: %+v", p.Name, namespace, p)
|
||||
}
|
||||
|
||||
k8sh.PrintEventsForNamespace(namespace)
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) PrintPodDescribe(name, namespace string) {
|
||||
pod, err := k8sh.Clientset.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
@@ -399,6 +441,10 @@ func (k8sh *K8sHelper) PrintPodDescribe(name, namespace string) {
|
||||
}
|
||||
logger.Infof("pod %s in namespace %s: %+v", name, namespace, pod)
|
||||
|
||||
k8sh.PrintEventsForNamespace(namespace)
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) PrintEventsForNamespace(namespace string) {
|
||||
events, err := k8sh.Clientset.CoreV1().Events(namespace).List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
logger.Warningf("failed to get events in namespace %s. %+v", namespace, err)
|
||||
@@ -554,35 +600,72 @@ func (k8sh *K8sHelper) waitForVolume(namespace, volumeName string, exist bool) e
|
||||
}
|
||||
|
||||
k8sh.printVolumes(namespace, volumeName)
|
||||
k8sh.printPVs()
|
||||
k8sh.printPVCs(namespace)
|
||||
k8sh.PrintPVs(false /*detailed*/)
|
||||
k8sh.PrintPVCs(namespace, false /*detailed*/)
|
||||
return fmt.Errorf("timeout for Volume %s in namespace %s wait to %s", volumeName, namespace, action)
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) printPVs() {
|
||||
func (k8sh *K8sHelper) PrintPVs(detailed bool) {
|
||||
pvs, err := k8sh.Clientset.CoreV1().PersistentVolumes().List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
logger.Infof("failed to list pvs. %+v", err)
|
||||
logger.Errorf("failed to list pvs. %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var names []string
|
||||
for _, pv := range pvs.Items {
|
||||
names = append(names, pv.Name)
|
||||
if detailed {
|
||||
logger.Infof("Found %d PVs", len(pvs.Items))
|
||||
for _, pv := range pvs.Items {
|
||||
logger.Infof("PV %s: %+v", pv.Name, pv)
|
||||
}
|
||||
} else {
|
||||
var names []string
|
||||
for _, pv := range pvs.Items {
|
||||
names = append(names, pv.Name)
|
||||
}
|
||||
logger.Infof("Found PVs: %v", names)
|
||||
}
|
||||
logger.Infof("Found PVs: %v", names)
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) printPVCs(namespace string) {
|
||||
func (k8sh *K8sHelper) PrintPVCs(namespace string, detailed bool) {
|
||||
pvcs, err := k8sh.Clientset.CoreV1().PersistentVolumeClaims(namespace).List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
logger.Infof("failed to list pvcs. %+v", err)
|
||||
logger.Errorf("failed to list pvcs. %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var names []string
|
||||
for _, pvc := range pvcs.Items {
|
||||
names = append(names, pvc.Name)
|
||||
if detailed {
|
||||
logger.Infof("Found %d PVCs", len(pvcs.Items))
|
||||
for _, pvc := range pvcs.Items {
|
||||
logger.Infof("PVC %s: %+v", pvc.Name, pvc)
|
||||
}
|
||||
} else {
|
||||
var names []string
|
||||
for _, pvc := range pvcs.Items {
|
||||
names = append(names, pvc.Name)
|
||||
}
|
||||
logger.Infof("Found PVCs: %v", names)
|
||||
}
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) PrintStorageClasses(detailed bool) {
|
||||
scs, err := k8sh.Clientset.StorageV1().StorageClasses().List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
logger.Errorf("failed to list StorageClasses: %+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if detailed {
|
||||
logger.Infof("Found %d StorageClasses", len(scs.Items))
|
||||
for _, sc := range scs.Items {
|
||||
logger.Infof("StorageClass %s: %+v", sc.Name, sc)
|
||||
}
|
||||
} else {
|
||||
var names []string
|
||||
for _, sc := range scs.Items {
|
||||
names = append(names, sc.Name)
|
||||
}
|
||||
logger.Infof("Found StorageClasses: %v", names)
|
||||
}
|
||||
logger.Infof("Found PVCs: %v", names)
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) printVolumes(namespace, desiredVolume string) {
|
||||
@@ -609,6 +692,19 @@ func (k8sh *K8sHelper) isVolumeExist(namespace, name string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) GetPodNamesForApp(appName, namespace string) ([]string, error) {
|
||||
args := []string{"get", "pod", "-n", namespace, "-l", fmt.Sprintf("app=%s", appName),
|
||||
"-o", "jsonpath={.items[*].metadata.name}"}
|
||||
result, err := k8sh.Kubectl(args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get pod names for app %s: %+v. output: %s", appName, err, result)
|
||||
}
|
||||
|
||||
podNames := strings.Split(result, " ")
|
||||
return podNames, nil
|
||||
}
|
||||
|
||||
//GetPodDetails returns details about a pod
|
||||
func (k8sh *K8sHelper) GetPodDetails(podNamePattern string, namespace string) (string, error) {
|
||||
args := []string{"get", "pods", "-l", "app=" + podNamePattern, "-o", "wide", "--no-headers=true", "-o", "name"}
|
||||
@@ -693,14 +789,28 @@ func (k8sh *K8sHelper) GetServiceNodePort(serviceName string, namespace string)
|
||||
}
|
||||
|
||||
//IsStorageClassPresent returns true if storageClass is present, if not false
|
||||
func (k8sh *K8sHelper) IsStorageClassPresent(name string) (bool, error) {
|
||||
func (k8sh *K8sHelper) IsStorageClassPresent(name string) error {
|
||||
args := []string{"get", "storageclass", "-o", "jsonpath='{.items[*].metadata.name}'"}
|
||||
result, err := k8sh.Kubectl(args...)
|
||||
if strings.Contains(result, name) {
|
||||
return true, nil
|
||||
return nil
|
||||
}
|
||||
return false, fmt.Errorf("Storageclass %s not found, err ->%v", name, err)
|
||||
return fmt.Errorf("Storageclass %s not found, err ->%v", name, err)
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) IsDefaultStorageClassPresent() (bool, error) {
|
||||
scs, err := k8sh.Clientset.StorageV1().StorageClasses().List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to list StorageClasses: %+v", err)
|
||||
}
|
||||
|
||||
for _, sc := range scs.Items {
|
||||
if storagev1util.IsDefaultAnnotation(sc.ObjectMeta) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
//CheckPvcCount returns True if expected number pvs for a app are found
|
||||
@@ -808,7 +918,7 @@ func (k8sh *K8sHelper) CheckPodCountAndState(podName string, namespace string, m
|
||||
for inc < RetryLoop {
|
||||
podList, err := k8sh.Clientset.CoreV1().Pods(namespace).List(listOpts)
|
||||
if err != nil {
|
||||
logger.Errorf("Cannot get logs for app : %v in namespace %v, err: %v", podName, namespace, err)
|
||||
logger.Errorf("Cannot list pods for app=%s in namespace %s, err: %+v", podName, namespace, err)
|
||||
return false
|
||||
}
|
||||
actualPodCount = len(podList.Items)
|
||||
@@ -1088,7 +1198,24 @@ func (k8sh *K8sHelper) CreateAnonSystemClusterBinding() {
|
||||
logger.Warningf("anon-user-access not created")
|
||||
return
|
||||
}
|
||||
logger.Infof("anon-user-access created")
|
||||
|
||||
logger.Infof("anon-user-access creation completed, waiting for it to exist in API")
|
||||
inc := 0
|
||||
for inc < RetryLoop {
|
||||
var err error
|
||||
if k8sh.VersionAtLeast("v1.8.0") {
|
||||
if _, err = k8sh.Clientset.RbacV1().ClusterRoleBindings().Get("anon-user-access", metav1.GetOptions{}); err == nil {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if _, err = k8sh.Clientset.RbacV1beta1().ClusterRoleBindings().Get("anon-user-access", metav1.GetOptions{}); err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
logger.Warningf("failed to get anon-user-access clusterrolebinding, will try again: %+v", err)
|
||||
inc++
|
||||
time.Sleep(RetryInterval * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func (k8sh *K8sHelper) DeleteRoleAndBindings(name, namespace string) error {
|
||||
@@ -1110,3 +1237,7 @@ func (k8sh *K8sHelper) ScaleStatefulSet(statefulSetName, namespace string, repli
|
||||
_, err := k8sh.Kubectl(args...)
|
||||
return err
|
||||
}
|
||||
|
||||
func IsKubectlErrorNotFound(output string, err error) bool {
|
||||
return err != nil && strings.Contains(output, "Error from server (NotFound)")
|
||||
}
|
||||
@@ -83,7 +83,6 @@ func HandlePanics(r interface{}, op contracts.Setup, t func() *testing.T) {
|
||||
op.TearDown()
|
||||
t().FailNow()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//GetTestClient sets up SetTestClient for rook
|
||||
|
||||
@@ -115,9 +115,8 @@ func (s *BlockCreateSuite) TestCreateSamePVCTwice() {
|
||||
require.NoError(s.T(), err1)
|
||||
|
||||
logger.Infof("make sure storageclass is created")
|
||||
present, err := s.kh.IsStorageClassPresent("rook-ceph-block")
|
||||
err := s.kh.IsStorageClassPresent("rook-ceph-block")
|
||||
require.Nil(s.T(), err)
|
||||
require.True(s.T(), present, "Make sure storageclass is present")
|
||||
|
||||
logger.Infof("create pvc")
|
||||
result2, err2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, "ReadWriteOnce"), "create")
|
||||
@@ -230,9 +229,8 @@ func (s *BlockCreateSuite) CheckCreatingPVC(pvcName, pvcAccessMode string) {
|
||||
require.NoError(s.T(), err1)
|
||||
|
||||
//make sure storageclass is created
|
||||
present, err := s.kh.IsStorageClassPresent(storageClassName)
|
||||
err := s.kh.IsStorageClassPresent(storageClassName)
|
||||
require.Nil(s.T(), err)
|
||||
require.True(s.T(), present, "Make sure storageclass is present")
|
||||
|
||||
//create pvc
|
||||
result2, err2 := installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, pvcAccessMode), "create")
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
Copyright 2016 The Rook Authors. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rook/rook/tests/framework/installer"
|
||||
"github.com/rook/rook/tests/framework/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
// ************************************************
|
||||
// *** Major scenarios tested by the CockroachDBSuite ***
|
||||
// Setup
|
||||
// - via the cluster CRD with very simple properties
|
||||
// - 3 replicas
|
||||
// - default service ports
|
||||
// - insecure
|
||||
// - 1Gi volume from default provider
|
||||
// - 25% cache, 25% maxSQLMemory
|
||||
// ************************************************
|
||||
func TestCockroachDBSuite(t *testing.T) {
|
||||
s := new(CockroachDBSuite)
|
||||
defer func(s *CockroachDBSuite) {
|
||||
HandlePanics(recover(), s, s.T)
|
||||
}(s)
|
||||
suite.Run(t, s)
|
||||
}
|
||||
|
||||
type CockroachDBSuite struct {
|
||||
suite.Suite
|
||||
k8sHelper *utils.K8sHelper
|
||||
installHelper *installer.InstallHelper
|
||||
namespace string
|
||||
systemNamespace string
|
||||
instanceCount int
|
||||
}
|
||||
|
||||
func (suite *CockroachDBSuite) SetupSuite() {
|
||||
suite.SetUp()
|
||||
}
|
||||
|
||||
func (suite *CockroachDBSuite) TearDownSuite() {
|
||||
suite.TearDown()
|
||||
}
|
||||
|
||||
func (suite *CockroachDBSuite) SetUp() {
|
||||
suite.namespace = "cockroachdb-ns"
|
||||
suite.systemNamespace = installer.SystemNamespace(suite.namespace)
|
||||
suite.instanceCount = 1
|
||||
|
||||
k8sHelper, err := utils.CreateK8sHelper(suite.T)
|
||||
require.NoError(suite.T(), err)
|
||||
suite.k8sHelper = k8sHelper
|
||||
|
||||
k8sversion := suite.k8sHelper.GetK8sServerVersion()
|
||||
logger.Infof("Installing cockroachdb on k8s %s", k8sversion)
|
||||
|
||||
suite.installHelper = installer.NewK8sRookhelper(suite.k8sHelper.Clientset, suite.T)
|
||||
|
||||
err = suite.installHelper.InstallCockroachDB(suite.systemNamespace, suite.namespace, suite.instanceCount)
|
||||
if err != nil {
|
||||
logger.Errorf("cockroachdb was not installed successfully: %+v", err)
|
||||
suite.T().Fail()
|
||||
suite.TearDown()
|
||||
suite.T().FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *CockroachDBSuite) TearDown() {
|
||||
if suite.T().Failed() {
|
||||
installer.GatherCockroachDBDebuggingInfo(suite.k8sHelper, suite.systemNamespace)
|
||||
installer.GatherCockroachDBDebuggingInfo(suite.k8sHelper, suite.namespace)
|
||||
suite.installHelper.GatherAllCockroachDBLogs(suite.systemNamespace, suite.namespace, suite.T().Name())
|
||||
}
|
||||
suite.installHelper.UninstallCockroachDB(suite.systemNamespace, suite.namespace)
|
||||
}
|
||||
|
||||
func (suite *CockroachDBSuite) TestCockroachDBClusterInstallation() {
|
||||
logger.Infof("Verifying that all expected pods in cockroachdb cluster %s are running", suite.namespace)
|
||||
|
||||
// verify cockroachdb operator is running OK
|
||||
assert.True(suite.T(), suite.k8sHelper.CheckPodCountAndState("rook-cockroachdb-operator", suite.systemNamespace, 1, "Running"),
|
||||
"1 rook-cockroachdb-operator must be in Running state")
|
||||
|
||||
// verify cockroachdb cluster instances are running OK
|
||||
assert.True(suite.T(), suite.k8sHelper.CheckPodCountAndState("rook-cockroachdb", suite.namespace, suite.instanceCount, "Running"),
|
||||
fmt.Sprintf("%d rook-cockroachdb pods must be in Running state", suite.instanceCount))
|
||||
|
||||
// determine the cockroachdb operator pod name
|
||||
podNames, err := suite.k8sHelper.GetPodNamesForApp("rook-cockroachdb-operator", suite.systemNamespace)
|
||||
require.NoError(suite.T(), err)
|
||||
require.Equal(suite.T(), 1, len(podNames))
|
||||
operatorPodName := podNames[0]
|
||||
|
||||
// execute a sql command via exec in the cockroachdb operator pod to verify the database is functional
|
||||
command := "/cockroach/cockroach"
|
||||
commandArgs := []string{
|
||||
"sql", "--insecure", fmt.Sprintf("--host=cockroachdb-public.%s", suite.namespace), "-e",
|
||||
`create database rookcockroachdb; use rookcockroachdb; create table testtable ( testID int ); insert into testtable values (123456789); select * from testtable;`,
|
||||
}
|
||||
|
||||
inc := 0
|
||||
var result string
|
||||
for inc < utils.RetryLoop {
|
||||
result, err = suite.k8sHelper.Exec(suite.systemNamespace, operatorPodName, command, commandArgs)
|
||||
logger.Infof("cockroachdb sql command exited, err: %+v. result: %s", err, result)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
logger.Warning("cockroachdb sql command failed, will try again")
|
||||
inc++
|
||||
time.Sleep(utils.RetryInterval * time.Second)
|
||||
}
|
||||
|
||||
assert.NoError(suite.T(), err)
|
||||
assert.True(suite.T(), strings.Contains(result, "testid"))
|
||||
assert.True(suite.T(), strings.Contains(result, "123456789"))
|
||||
}
|
||||
@@ -20,7 +20,7 @@ var (
|
||||
// Create StorageClass and poll if needed
|
||||
func createStorageClassAndPool(t func() *testing.T, kh *utils.K8sHelper, namespace string, storageClassName string, poolName string) {
|
||||
//create storage class
|
||||
if scp, _ := kh.IsStorageClassPresent(storageClassName); !scp {
|
||||
if err := kh.IsStorageClassPresent(storageClassName); err != nil {
|
||||
logger.Infof("Install pool and storage class for rook block")
|
||||
_, err := installer.BlockResourceOperation(kh, installer.GetBlockPoolDef(poolName, namespace, "3"), "create")
|
||||
require.NoError(t(), err)
|
||||
@@ -28,9 +28,8 @@ func createStorageClassAndPool(t func() *testing.T, kh *utils.K8sHelper, namespa
|
||||
require.NoError(t(), err)
|
||||
|
||||
//make sure storageclass is created
|
||||
present, err := kh.IsStorageClassPresent(storageClassName)
|
||||
err = kh.IsStorageClassPresent(storageClassName)
|
||||
require.NoError(t(), err)
|
||||
require.True(t(), present, "Make sure storageclass is present")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,16 +29,18 @@ pipeline {
|
||||
}
|
||||
sh "wget -O ceph.tar.gz https://release.rook.io/build/pr/${params.PR}/${params.version}/images/linux_amd64/ceph.tar.gz"
|
||||
sh "wget -O ceph-toolbox.tar.gz https://release.rook.io/build/pr/${params.PR}/${params.version}/images/linux_amd64/ceph-toolbox.tar.gz"
|
||||
sh "wget -O cockroachdb.tar.gz https://release.rook.io/build/pr/${params.PR}/${params.version}/images/linux_amd64/cockroachdb.tar.gz"
|
||||
sh "wget -O version https://release.rook.io/build/pr/${params.PR}/${params.version}/version"
|
||||
|
||||
}else {
|
||||
sh "wget -O ceph.tar.gz https://release.rook.io/build/master/${params.version}/images/linux_amd64/ceph.tar.gz"
|
||||
sh "wget -O ceph-toolbox.tar.gz https://release.rook.io/build/master/${params.version}/images/linux_amd64/ceph-toolbox.tar.gz"
|
||||
sh "wget -O cockroachdb.tar.gz https://release.rook.io/build/master/${params.version}/images/linux_amd64/cockroachdb.tar.gz"
|
||||
sh "wget -O version https://release.rook.io/build/master/${params.version}/version"
|
||||
|
||||
}
|
||||
stash name: 'test-scripts',includes: 'tests/scripts/'
|
||||
stash name: 'test-images', includes: 'ceph.tar.gz,ceph-toolbox.tar.gz,version'
|
||||
stash name: 'test-images', includes: 'ceph.tar.gz,ceph-toolbox.tar.gz,cockroachdb.tar.gz,version'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,6 +100,7 @@ def setUpRookImages(){
|
||||
#!/bin/bash
|
||||
docker load -i ceph.tar.gz
|
||||
docker load -i ceph-toolbox.tar.gz
|
||||
docker load -i cockroachdb.tar.gz
|
||||
docker images
|
||||
rookImg=$(docker images |grep rook | awk '{print $1}')
|
||||
echo $rookImg
|
||||
@@ -108,4 +111,6 @@ def setUpRookImages(){
|
||||
docker tag $rookImg rook/ceph:master
|
||||
docker tag $rookImg rook/ceph:${versionId}
|
||||
docker tag $toolboxImg rook/ceph-toolbox:master'''
|
||||
docker tag $rookImg rook/cockroachdb:master
|
||||
docker tag $rookImg rook/cockroachdb:${versionId}
|
||||
}
|
||||
@@ -10,12 +10,16 @@ case "${1:-}" in
|
||||
arm|arm64|amd64)
|
||||
docker tag ${BUILD_REGISTRY}/ceph-$2:latest rook/ceph:master
|
||||
docker tag ${BUILD_REGISTRY}/ceph-toolbox-$2:latest rook/ceph-toolbox:master
|
||||
docker tag ${BUILD_REGISTRY}/cockroachdb-$2:latest rook/cockroachdb:master
|
||||
if [ ! -z $3 ]
|
||||
then
|
||||
docker tag ${BUILD_REGISTRY}/ceph-$2:latest rook/ceph:$3
|
||||
docker save -o ceph-$2.tar rook/ceph:master rook/ceph:$3 rook/ceph-toolbox:master
|
||||
docker tag ${BUILD_REGISTRY}/cockroachdb-$2:latest rook/cockroachdb:$3
|
||||
docker save -o cockroachdb-$2.tar rook/cockroachdb:master rook/cockroachdb:$3
|
||||
else
|
||||
docker save -o ceph-$2.tar rook/ceph:master rook/ceph-toolbox:master
|
||||
docker save -o cockroachdb-$2.tar rook/cockroachdb:master
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
@@ -27,6 +31,7 @@ case "${1:-}" in
|
||||
case "${2:-}" in
|
||||
arm|arm64|amd64)
|
||||
docker load -i ceph-$2.tar
|
||||
docker load -i cockroachdb-$2.tar
|
||||
;;
|
||||
*)
|
||||
echo "usage :" >&2
|
||||
@@ -40,6 +45,7 @@ case "${1:-}" in
|
||||
tag_version="${3:-"master"}"
|
||||
docker tag ${BUILD_REGISTRY}/ceph-$2:latest rook/ceph:${tag_version}
|
||||
docker tag ${BUILD_REGISTRY}/ceph-toolbox-$2:latest rook/ceph-toolbox:${tag_version}
|
||||
docker tag ${BUILD_REGISTRY}/cockroachdb-$2:latest rook/cockroachdb:${tag_version}
|
||||
;;
|
||||
*)
|
||||
echo "usage :" >&2
|
||||
|
||||
@@ -117,6 +117,7 @@ case "${1:-}" in
|
||||
minikube ssh "sudo mkdir /mnt/sda1/var/lib/rook;sudo ln -s /mnt/sda1/var/lib/rook /var/lib/rook"
|
||||
copy_image_to_cluster ${BUILD_REGISTRY}/ceph-amd64 rook/ceph:master
|
||||
copy_image_to_cluster ${BUILD_REGISTRY}/ceph-toolbox-amd64 rook/ceph-toolbox:master
|
||||
copy_image_to_cluster ${BUILD_REGISTRY}/cockroachdb-amd64 rook/cockroachdb:master
|
||||
;;
|
||||
down)
|
||||
minikube stop
|
||||
@@ -129,6 +130,7 @@ case "${1:-}" in
|
||||
echo "updating the rook images"
|
||||
copy_image_to_cluster ${BUILD_REGISTRY}/ceph-amd64 rook/ceph:master
|
||||
copy_image_to_cluster ${BUILD_REGISTRY}/ceph-toolbox-amd64 rook/ceph-toolbox:master
|
||||
copy_image_to_cluster ${BUILD_REGISTRY}/cockroachdb-amd64 rook/cockroachdb:master
|
||||
;;
|
||||
restart)
|
||||
if check_context; then
|
||||
|
||||
Reference in new issue
Block a user