Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
e2etest: Add e2e test to check if labels were added correctly.
Browse files Browse the repository at this point in the history
Signed-off-by: Imran Pochi <imran@kinvolk.io>
  • Loading branch information
ipochi committed Jun 23, 2020
1 parent 3148778 commit e1be658
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 10 deletions.
10 changes: 10 additions & 0 deletions test/components/cert-manager/cert-manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ func TestCertManagerDeployments(t *testing.T) {
})
}
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
15 changes: 14 additions & 1 deletion test/components/contour/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ import (
testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
namespace = "projectcontour"
)

func TestEnvoyDaemonset(t *testing.T) {
t.Parallel()
namespace := "projectcontour"
daemonset := "envoy"

client := testutil.CreateKubeClient(t)
Expand All @@ -43,3 +46,13 @@ func TestContourDeployment(t *testing.T) {

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
16 changes: 14 additions & 2 deletions test/components/dex/dex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
testutil "github.com/kinvolk/lokomotive/test/components/util"
)

func TestDexDeployment(t *testing.T) {
namespace := "dex"
const (
namespace = "dex"
)

func TestDexDeployment(t *testing.T) {
client := testutil.CreateKubeClient(t)

t.Run("deployment", func(t *testing.T) {
Expand All @@ -36,3 +38,13 @@ func TestDexDeployment(t *testing.T) {
testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
})
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
10 changes: 10 additions & 0 deletions test/components/external-dns/external-dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ func TestExternalDNSDeployments(t *testing.T) {
testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
})
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
15 changes: 14 additions & 1 deletion test/components/flatcar-linux-update-operator/fluo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ import (
testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
namespace = "reboot-coordinator"
)

func TestUpdateAgentDaemonset(t *testing.T) {
t.Parallel()
namespace := "reboot-coordinator"
daemonset := "flatcar-linux-update-agent"

client := testutil.CreateKubeClient(t)
Expand All @@ -43,3 +46,13 @@ func TestUpdateOperatorDeployment(t *testing.T) {

testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
16 changes: 14 additions & 2 deletions test/components/gangway/gangway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
testutil "github.com/kinvolk/lokomotive/test/components/util"
)

func TestGangwayDeployment(t *testing.T) {
namespace := "gangway"
const (
namespace = "gangway"
)

func TestGangwayDeployment(t *testing.T) {
client := testutil.CreateKubeClient(t)

t.Run("deployment", func(t *testing.T) {
Expand All @@ -36,3 +38,13 @@ func TestGangwayDeployment(t *testing.T) {
testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
})
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
37 changes: 37 additions & 0 deletions test/components/kubernetes/kube_system_labels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2020 The Lokomotive Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build aws aws_edge packet aks
// +build e2e

package kubernetes //nolint:testpackage

import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const namespace = "kube-system"

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
16 changes: 14 additions & 2 deletions test/components/metallb/metallb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
testutil "github.com/kinvolk/lokomotive/test/components/util"
)

func TestMetalLBDeployment(t *testing.T) {
namespace := "metallb-system"
const (
namespace = "metallb-system"
)

func TestMetalLBDeployment(t *testing.T) {
client := testutil.CreateKubeClient(t)

t.Run("speaker daemonset", func(t *testing.T) {
Expand All @@ -43,3 +45,13 @@ func TestMetalLBDeployment(t *testing.T) {
testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
})
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
16 changes: 14 additions & 2 deletions test/components/openebs-operator/openebs_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
testutil "github.com/kinvolk/lokomotive/test/components/util"
)

func TestOpenEBSOperatorDeployment(t *testing.T) {
namespace := "openebs"
const (
namespace = "openebs"
)

func TestOpenEBSOperatorDeployment(t *testing.T) {
client := testutil.CreateKubeClient(t)

deployments := []string{
Expand All @@ -46,3 +48,13 @@ func TestOpenEBSOperatorDeployment(t *testing.T) {
})
}
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
10 changes: 10 additions & 0 deletions test/components/prometheus-operator/prometheus_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,13 @@ func TestGrafanaLoadsEnvVars(t *testing.T) {
t.Fatalf("required env var %q not found in following env vars:\n\n%s\n", searchEnvVar, containerOutput)
}
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
14 changes: 14 additions & 0 deletions test/components/rook/rook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (
testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
namespace = "rook"
)

func TestRookDeployment(t *testing.T) {
namespace := "rook"

Expand All @@ -36,3 +40,13 @@ func TestRookDeployment(t *testing.T) {
testutil.WaitForDeployment(t, client, namespace, deployment, time.Second*5, time.Minute*5)
})
}

func TestNamespaceHasLabels(t *testing.T) {
client := testutil.CreateKubeClient(t)

labels := map[string]string{
"lokomotive.kinvolk.io/name": namespace,
}

testutil.IsLabelPresentInNamespace(t, client, namespace, labels, time.Second*5, time.Minute*5)
}
43 changes: 43 additions & 0 deletions test/components/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,49 @@ func WaitForDaemonSet(t *testing.T, client kubernetes.Interface, ns, name string
}
}

// IsLabelPresentInNamespace tests whether the given labels are present in the namespace.
func IsLabelPresentInNamespace(
t *testing.T,
client kubernetes.Interface,
ns string,
labels map[string]string,
retryInterval,
timeout time.Duration,
) {
var err error

var namespace *corev1.Namespace

if err = wait.PollImmediate(retryInterval, timeout, func() (done bool, err error) {
namespace, err = client.CoreV1().Namespaces().Get(context.TODO(), ns, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
t.Logf("waiting for namespace %s to be available", ns)

return false, nil
}

return false, err
}

for expectedKey, expectedValue := range labels {
value, ok := namespace.ObjectMeta.Labels[expectedKey]
if !ok {
t.Errorf("expected key '%s' not found", expectedKey)
}

if expectedValue != value {
t.Errorf("expected value '%s' for key '%s', got '%s'", expectedValue, expectedKey, value)
}
}

return true, nil
}); err != nil {
t.Errorf("error while waiting for namespace: %v", err)
return
}
}

func WaitForDeployment(t *testing.T, client kubernetes.Interface, ns, name string, retryInterval, timeout time.Duration) {
var err error
var deploy *appsv1.Deployment
Expand Down

0 comments on commit e1be658

Please sign in to comment.