2020-01-29 11:44:45 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2020-02-25 11:45:54 +00:00
|
|
|
"fmt"
|
|
|
|
|
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-02-25 11:45:54 +00:00
|
|
|
framework.RunKubectlOrDie("create", "-f", vaultExamplePath+vaultServicePath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
|
|
|
framework.RunKubectlOrDie("create", "-f", vaultExamplePath+vaultPSPPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
|
|
|
framework.RunKubectlOrDie("create", "-f", vaultExamplePath+vaultRBACPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
|
|
|
framework.RunKubectlOrDie("create", "-f", vaultExamplePath+vaultConfigPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2020-01-29 11:44:45 +00:00
|
|
|
|
|
|
|
opt := metav1.ListOptions{
|
|
|
|
LabelSelector: "app=vault",
|
|
|
|
}
|
|
|
|
|
2020-02-25 11:45:54 +00:00
|
|
|
pods, err := c.CoreV1().Pods(cephCSINamespace).List(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
|
2020-02-25 11:45:54 +00:00
|
|
|
err = waitForPodInRunningState(name, cephCSINamespace, c, deployTimeout)
|
2020-01-29 11:44:45 +00:00
|
|
|
Expect(err).Should(BeNil())
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteVault() {
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err := framework.RunKubectl("delete", "-f", vaultExamplePath+vaultServicePath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2020-01-29 11:44:45 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete vault statefull set %v", err)
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err = framework.RunKubectl("delete", "-f", vaultExamplePath+vaultRBACPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2020-01-29 11:44:45 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete vault statefull set %v", err)
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err = framework.RunKubectl("delete", "-f", vaultExamplePath+vaultConfigPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2020-01-29 11:44:45 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete vault config map %v", err)
|
|
|
|
}
|
2020-02-25 11:45:54 +00:00
|
|
|
_, err = framework.RunKubectl("delete", "-f", vaultExamplePath+vaultPSPPath, fmt.Sprintf("--namespace=%s", cephCSINamespace))
|
2020-01-29 11:44:45 +00:00
|
|
|
if err != nil {
|
|
|
|
e2elog.Logf("failed to delete vault psp %v", err)
|
|
|
|
}
|
|
|
|
}
|