From c9227a080f7353db63af6014207362f791204a9d Mon Sep 17 00:00:00 2001 From: Natale Vinto Date: Wed, 20 May 2020 21:51:31 +0200 Subject: [PATCH] Add integration test TestOlmAddon Enable olm and install etcd operator checking successful installation --- test/integration/addons_test.go | 105 ++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 0a63c39d23..d7f39ee001 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -328,3 +328,108 @@ func validateHelmTillerAddon(ctx context.Context, t *testing.T, profile string) t.Errorf("failed disabling helm-tiller addon. arg %q.s %v", rr.Command(), err) } } + +func TestOlmAddon(t *testing.T) { + profile := UniqueProfileName("addons") + ctx, cancel := context.WithTimeout(context.Background(), Minutes(40)) + defer Cleanup(t, profile, cancel) + + args := append([]string{"start", "-p", profile, "--wait=false", "--memory=2600", "--alsologtostderr", "--addons=olm"}, StartArgs()...) + rr, err := Run(t, exec.CommandContext(ctx, Target(), args...)) + if err != nil { + t.Fatalf("%s failed: %v", rr.Command(), err) + } + + // Parallelized tests + t.Run("parallel", func(t *testing.T) { + tests := []struct { + name string + validator validateFunc + }{ + {"Olm", validateOlmAddon}, + } + for _, tc := range tests { + tc := tc + t.Run(tc.name, func(t *testing.T) { + MaybeParallel(t) + tc.validator(ctx, t, profile) + }) + } + }) + + // Assert that disable/enable works offline + rr, err = Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile)) + if err != nil { + t.Errorf("failed to stop minikube. args %q : %v", rr.Command(), err) + } + rr, err = Run(t, exec.CommandContext(ctx, Target(), "addons", "enable", "dashboard", "-p", profile)) + if err != nil { + t.Errorf("failed to enable dashboard addon: args %q : %v", rr.Command(), err) + } + rr, err = Run(t, exec.CommandContext(ctx, Target(), "addons", "disable", "dashboard", "-p", profile)) + if err != nil { + t.Errorf("failed to disable dashboard addon: args %q : %v", rr.Command(), err) + } +} + +func validateOlmAddon(ctx context.Context, t *testing.T, profile string) { + defer PostMortemLogs(t, profile) + + client, err := kapi.Client(profile) + if err != nil { + t.Fatalf("failed to get Kubernetes client for %s: %v", profile, err) + } + + start := time.Now() + if err := kapi.WaitForDeploymentToStabilize(client, "olm", "catalog-operator", Minutes(6)); err != nil { + t.Errorf("failed waiting for catalog-operator deployment to stabilize: %v", err) + } + t.Logf("catalog-operator stabilized in %s", time.Since(start)) + if err := kapi.WaitForDeploymentToStabilize(client, "olm", "olm-operator", Minutes(6)); err != nil { + t.Errorf("failed waiting for olm-operator deployment to stabilize: %v", err) + } + t.Logf("olm-operator stabilized in %s", time.Since(start)) + if err := kapi.WaitForDeploymentToStabilize(client, "olm", "packageserver", Minutes(6)); err != nil { + t.Errorf("failed waiting for packageserver deployment to stabilize: %v", err) + } + t.Logf("packageserver stabilized in %s", time.Since(start)) + + if _, err := PodWait(ctx, t, profile, "olm", "app=catalog-operator", Minutes(6)); err != nil { + t.Fatalf("failed waiting for pod catalog-operator: %v", err) + } + if _, err := PodWait(ctx, t, profile, "olm", "app=olm-operator", Minutes(6)); err != nil { + t.Fatalf("failed waiting for pod olm-operator: %v", err) + } + if _, err := PodWait(ctx, t, profile, "olm", "app=packageserver", Minutes(6)); err != nil { + t.Fatalf("failed waiting for pod packageserver: %v", err) + } + if _, err := PodWait(ctx, t, profile, "olm", "olm.catalogSource=operatorhubio-catalog", Minutes(6)); err != nil { + t.Fatalf("failed waiting for pod operatorhubio-catalog: %v", err) + } + + // Install one sample Operator such as etcd + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "-f", "https://operatorhub.io/install/etcd.yaml")) + if err != nil { + t.Logf("etcd operator installation with %s failed: %v", rr.Command(), err) + } + + want := "Succeeded" + checkOperatorInstalled := func() error { + rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "get", "csv", "-n", "my-etcd")) + if err != nil { + return err + } + if rr.Stderr.String() != "" { + t.Logf("%v: unexpected stderr: %s", rr.Command(), rr.Stderr) + } + if !strings.Contains(rr.Stdout.String(), want) { + return fmt.Errorf("%v stdout = %q, want %q", rr.Command(), rr.Stdout, want) + } + return nil + } + + // Operator installation takes a while + if err := retry.Expo(checkOperatorInstalled, time.Second*3, Minutes(6)); err != nil { + t.Errorf("failed checking operator installed: %v", err.Error()) + } +}