Skip to content

Commit c88dc8b

Browse files
authored
[chore] Fix chart waiting for deployments in tests (#1734)
Use chart "wait" feature instead of custom logic
1 parent 2afa56b commit c88dc8b

File tree

4 files changed

+2
-29
lines changed

4 files changed

+2
-29
lines changed

functional_tests/configuration_switching/configuration_switching_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ type sinks struct {
4141
func deployChartsAndApps(t *testing.T, valuesFileName string, repl map[string]interface{}) {
4242
testKubeConfig, setKubeConfig := os.LookupEnv("KUBECONFIG")
4343
require.True(t, setKubeConfig, "the environment variable KUBECONFIG must be set")
44-
kubeConfig, err := clientcmd.BuildConfigFromFlags("", testKubeConfig)
45-
require.NoError(t, err)
46-
client, err := kubernetes.NewForConfig(kubeConfig)
47-
require.NoError(t, err)
4844

4945
hostEp := internal.HostEndpoint(t)
5046
if len(hostEp) == 0 {
@@ -61,7 +57,6 @@ func deployChartsAndApps(t *testing.T, valuesFileName string, repl map[string]in
6157
valuesFile, err := filepath.Abs(filepath.Join(testDir, valuesDir, valuesFileName))
6258
require.NoError(t, err)
6359
internal.ChartInstallOrUpgrade(t, testKubeConfig, valuesFile, replacements)
64-
internal.WaitForAllDeploymentsToStart(t, client)
6560

6661
t.Cleanup(func() {
6762
if os.Getenv("SKIP_TEARDOWN") == "true" {

functional_tests/functional/functional_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ func deployChartsAndApps(t *testing.T, testKubeConfig string) {
194194
"KubeTestEnv": kubeTestEnv,
195195
}
196196
internal.ChartInstallOrUpgrade(t, testKubeConfig, valuesFile, replacements)
197-
internal.WaitForAllDeploymentsToStart(t, client)
198197

199198
deployments := client.AppsV1().Deployments(internal.Namespace)
200199

@@ -340,8 +339,6 @@ func deployChartsAndApps(t *testing.T, testKubeConfig string) {
340339
}
341340
}
342341

343-
internal.WaitForAllDeploymentsToStart(t, client)
344-
345342
t.Cleanup(func() {
346343
if os.Getenv("SKIP_TEARDOWN") == "true" {
347344
t.Log("Skipping teardown as SKIP_TEARDOWN is set to true")

functional_tests/internal/chart.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func ChartInstallOrUpgrade(t *testing.T, testKubeConfig string, valuesFile strin
4646
install := action.NewInstall(actionConfig)
4747
install.Namespace = Namespace
4848
install.ReleaseName = chartReleaseName
49+
install.Wait = true
4950
install.Timeout = helmActionTimeout
5051

5152
// If UPGRADE_FROM_VALUES env var is set, we install the helm chart using the values. Otherwise, run helm install.
@@ -66,7 +67,7 @@ func ChartInstallOrUpgrade(t *testing.T, testKubeConfig string, valuesFile strin
6667
// test the upgrade
6768
upgrade := action.NewUpgrade(actionConfig)
6869
upgrade.Namespace = Namespace
69-
upgrade.Install = true
70+
upgrade.Wait = true
7071
upgrade.Timeout = helmActionTimeout
7172
t.Log("Running helm upgrade")
7273
_, err = upgrade.Run(chartReleaseName, loadChart(t), values)

functional_tests/internal/common.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,3 @@ func AnnotateNamespace(t *testing.T, clientset *kubernetes.Clientset, name, key,
178178
_, err = clientset.CoreV1().Namespaces().Update(context.TODO(), ns, metav1.UpdateOptions{})
179179
require.NoError(t, err)
180180
}
181-
182-
func WaitForAllDeploymentsToStart(t *testing.T, client *kubernetes.Clientset) {
183-
require.Eventually(t, func() bool {
184-
di, err := client.AppsV1().Deployments(Namespace).List(context.Background(), metav1.ListOptions{})
185-
require.NoError(t, err)
186-
for _, d := range di.Items {
187-
if d.Status.ReadyReplicas != d.Status.Replicas {
188-
var messages string
189-
for _, c := range d.Status.Conditions {
190-
messages += c.Message
191-
messages += "\n"
192-
}
193-
194-
t.Logf("Deployment not ready: %s, %s", d.Name, messages)
195-
return false
196-
}
197-
}
198-
return true
199-
}, 10*time.Minute, 10*time.Second)
200-
}

0 commit comments

Comments
 (0)