2020-01-29 11:44:45 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2020-04-14 06:59:04 +00:00
|
|
|
"context"
|
2020-02-26 08:11:05 +00:00
|
|
|
"strings"
|
2020-02-25 11:45:54 +00:00
|
|
|
|
2020-01-29 11:44:45 +00:00
|
|
|
. "github.com/onsi/gomega" // nolint
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
|
|
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
vaultExamplePath = "../examples/kms/vault/"
|
|
|
|
vaultServicePath = "vault.yaml"
|
|
|
|
vaultPSPPath = "vault-psp.yaml"
|
|
|
|
vaultRBACPath = "csi-vaulttokenreview-rbac.yaml"
|
|
|
|
vaultConfigPath = "kms-config.yaml"
|
|
|
|
)
|
|
|
|
|
|
|
|
func deployVault(c kubernetes.Interface, deployTimeout int) {
|
2020-04-01 07:20:43 +00:00
|
|
|
// hack to make helm E2E pass as helm charts creates this configmap as part
|
|
|
|
// of cephcsi deployment
|
2021-06-25 12:47:11 +00:00
|
|
|
_, err := framework.RunKubectl(
|
|
|
|
cephCSINamespace,
|
|
|
|
"delete",
|
|
|
|
"cm",
|
|
|
|
"ceph-csi-encryption-kms-config",
|
|
|
|
"--namespace",
|
|
|
|
cephCSINamespace,
|
|
|
|
"--ignore-not-found=true")
|
2020-04-01 07:20:43 +00:00
|
|
|
Expect(err).Should(BeNil())
|
|
|
|
|
2020-02-26 08:11:05 +00:00
|
|
|
createORDeleteVault("create")
|
2020-01-29 11:44:45 +00:00
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=vault",
|
|
|
|
}
|
|
|
|
|
2020-04-14 06:59:04 +00:00
|
|
|
pods, err := c.CoreV1().Pods(cephCSINamespace).List(context.TODO(), opt)
|
2020-01-29 11:44:45 +00:00
|
|
|
Expect(err).Should(BeNil())
|
|
|
|
Expect(len(pods.Items)).Should(Equal(1))
|
|
|
|
name := pods.Items[0].Name
|
2021-06-15 10:08:51 +00:00
|
|
|
err = waitForPodInRunningState(name, cephCSINamespace, c, deployTimeout, noError)
|
2020-01-29 11:44:45 +00:00
|
|
|
Expect(err).Should(BeNil())
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteVault() {
|
2020-02-26 08:11:05 +00:00
|
|
|
createORDeleteVault("delete")
|
|
|
|
}
|
|
|
|
|
|
|
|
func createORDeleteVault(action string) {
|
|
|
|
data, err := replaceNamespaceInTemplate(vaultExamplePath + vaultServicePath)
|
|
|
|
if err != nil {
|
2021-02-16 12:28:34 +00:00
|
|
|
e2elog.Failf("failed to read content from %s %v", vaultExamplePath+vaultServicePath, err)
|
2020-02-26 08:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data = strings.ReplaceAll(data, "vault.default", "vault."+cephCSINamespace)
|
|
|
|
|
|
|
|
data = strings.ReplaceAll(data, "value: default", "value: "+cephCSINamespace)
|
2020-04-14 06:59:04 +00:00
|
|
|
_, err = framework.RunKubectlInput(cephCSINamespace, data, action, ns, "-f", "-")
|
2020-02-26 08:11:05 +00:00
|
|
|
if err != nil {
|
2021-02-16 12:28:34 +00:00
|
|
|
e2elog.Failf("failed to %s vault statefulset %v", action, err)
|
2020-02-26 08:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data, err = replaceNamespaceInTemplate(vaultExamplePath + vaultRBACPath)
|
|
|
|
if err != nil {
|
2021-02-16 12:28:34 +00:00
|
|
|
e2elog.Failf("failed to read content from %s %v", vaultExamplePath+vaultRBACPath, err)
|
2020-02-26 08:11:05 +00:00
|
|
|
}
|
2020-04-14 06:59:04 +00:00
|
|
|
_, err = framework.RunKubectlInput(cephCSINamespace, data, action, ns, "-f", "-")
|
2020-01-29 11:44:45 +00:00
|
|
|
if err != nil {
|
2021-02-16 12:28:34 +00:00
|
|
|
e2elog.Failf("failed to %s vault statefulset %v", action, err)
|
2020-01-29 11:44:45 +00:00
|
|
|
}
|
2020-02-26 08:11:05 +00:00
|
|
|
|
|
|
|
data, err = replaceNamespaceInTemplate(vaultExamplePath + vaultConfigPath)
|
|
|
|
if err != nil {
|
2021-02-16 12:28:34 +00:00
|
|
|
e2elog.Failf("failed to read content from %s %v", vaultExamplePath+vaultConfigPath, err)
|
2020-02-26 08:11:05 +00:00
|
|
|
}
|
|
|
|
data = strings.ReplaceAll(data, "default", cephCSINamespace)
|
2020-04-14 06:59:04 +00:00
|
|
|
_, err = framework.RunKubectlInput(cephCSINamespace, data, action, ns, "-f", "-")
|
2020-01-29 11:44:45 +00:00
|
|
|
if err != nil {
|
2021-02-16 12:28:34 +00:00
|
|
|
e2elog.Failf("failed to %s vault configmap %v", action, err)
|
2020-01-29 11:44:45 +00:00
|
|
|
}
|
2020-02-26 08:11:05 +00:00
|
|
|
|
|
|
|
data, err = replaceNamespaceInTemplate(vaultExamplePath + vaultPSPPath)
|
2020-01-29 11:44:45 +00:00
|
|
|
if err != nil {
|
2021-02-16 12:28:34 +00:00
|
|
|
e2elog.Failf("failed to read content from %s %v", vaultExamplePath+vaultPSPPath, err)
|
2020-01-29 11:44:45 +00:00
|
|
|
}
|
2020-04-14 06:59:04 +00:00
|
|
|
_, err = framework.RunKubectlInput(cephCSINamespace, data, action, ns, "-f", "-")
|
2020-01-29 11:44:45 +00:00
|
|
|
if err != nil {
|
2021-02-16 12:28:34 +00:00
|
|
|
e2elog.Failf("failed to %s vault psp %v", action, err)
|
2020-01-29 11:44:45 +00:00
|
|
|
}
|
|
|
|
}
|