-
Notifications
You must be signed in to change notification settings - Fork 187
/
e2e_suite_test.go
156 lines (135 loc) · 5.07 KB
/
e2e_suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//go:build e2e
// +build e2e
package e2e
import (
"fmt"
"testing"
"time"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework/deploy"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework/exec"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework/helm"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework/keyvault"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework/pod"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/client-go/kubernetes"
e2eframework "k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
testutils "k8s.io/kubernetes/test/utils"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var (
clusterProxy framework.ClusterProxy
config *framework.Config
kubeClient client.Client
clientSet *kubernetes.Clientset
kvClient keyvault.Client
kubeconfigPath string
coreNamespaces = []string{
framework.NamespaceKubeSystem,
}
)
const (
// podStartTimeout is how long to wait for the pod to be started.
podStartTimeout = 5 * time.Minute
)
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "sscdproviderazure")
}
var _ = BeforeSuite(func() {
By("Parsing test configuration")
var err error
config, err = framework.ParseConfig()
Expect(err).To(BeNil())
By("Creating a Cluster Proxy")
clusterProxy = framework.NewClusterProxy(initScheme())
kubeClient = clusterProxy.GetClient()
clientSet = clusterProxy.GetClientSet()
kubeconfigPath = clusterProxy.GetKubeconfigPath()
By("Creating a Keyvault Client")
kvClient = keyvault.NewClient(config)
if config.IsSoakTest || config.IsArcTest {
return
}
if !config.IsHelmTest {
By("Installing Secrets Store CSI Driver and Azure Key Vault Provider via kubectl from deployment manifest.")
deploy.InstallManifest(kubeconfigPath, config)
return
}
// if helm release exists, it means either cluster upgrade test or backward compatibility test is underway
if !helm.ReleaseExists() {
By(fmt.Sprintf("Installing Secrets Store CSI Driver and Azure Key Vault Provider via Helm from - %s.", config.HelmChartDir))
helm.Install(helm.InstallInput{
Config: config,
})
} else if config.IsBackwardCompatibilityTest {
// upgrade helm charts only if running backward compatibility tests
By(fmt.Sprintf("Upgrading Secrets Store CSI Driver and Azure Key Vault Provider via Helm to New Version from - %s.", config.HelmChartDir))
helm.Upgrade(helm.UpgradeInput{
Config: config,
})
}
// Ensure driver and provider pods are running and ready before starting tests
By("Waiting for driver and provider pods to be running and ready before starting tests.")
driverAndProviderLabels, err := labels.NewRequirement("app", selection.In, []string{"secrets-store-csi-driver", "csi-secrets-store-provider-azure"})
Expect(err).To(BeNil())
listOpts := metav1.ListOptions{
LabelSelector: driverAndProviderLabels.String(),
}
if _, err := e2epod.WaitForAllPodsCondition(clientSet, framework.NamespaceKubeSystem, listOpts, 1, "running and ready", podStartTimeout, testutils.PodRunningReady); err != nil {
e2eframework.Failf("error waiting for driver and provider pods to be running and ready: %v", err)
}
})
var _ = AfterSuite(func() {
// cleanup
defer func() {
// uninstall if it's not Soak Test, not backward compatibility test and if cluster is already upgraded or it's not cluster upgrade test
if !config.IsSoakTest && !config.IsArcTest && !config.IsBackwardCompatibilityTest && (!config.IsUpgradeTest || config.IsClusterUpgraded) {
if helm.ReleaseExists() {
By("Uninstalling Secrets Store CSI Driver and Azure Key Vault Provider via Helm")
helm.Uninstall()
}
}
}()
dumpLogs()
})
func initScheme() *runtime.Scheme {
scheme := runtime.NewScheme()
framework.TryAddDefaultSchemes(scheme)
return scheme
}
func dumpLogs() {
for component, containers := range map[string][]string{
"secrets-store-csi-driver": {"node-driver-registrar", "secrets-store", "liveness-probe"},
"csi-secrets-store-provider-azure": {"provider-azure-installer"},
} {
podList := pod.List(pod.ListInput{
Lister: kubeClient,
Namespace: framework.NamespaceKubeSystem,
Labels: map[string]string{
"app": component,
},
})
for _, p := range podList.Items {
for _, containerName := range containers {
By(fmt.Sprintf("Dumping logs for %s scheduled to %s, container %s", p.Name, p.Spec.NodeName, containerName))
out, err := exec.KubectlLogs(kubeconfigPath, p.Name, containerName, framework.NamespaceKubeSystem)
Expect(err).To(BeNil())
fmt.Println(out + "\n")
}
}
}
}
// getPodExecCommand returns the exec command to use for validating mount contents
func getPodExecCommand(cmd string) string {
if config.IsWindowsTest {
return fmt.Sprintf("powershell.exe -Command %s", cmd)
}
return cmd
}