From 44c3fb4b3cfbf99c100d1d16e45038548a998b9d Mon Sep 17 00:00:00 2001 From: prkalle <38508878+prkalle@users.noreply.github.com> Date: Tue, 26 Jul 2022 14:11:58 -0700 Subject: [PATCH] Add e2e test for TKR compatibility status condition (#3003) Signed-off-by: Prem Kumar Kalle --- pkg/v1/tkg/test/framework/cluster_proxy.go | 7 +- .../tkg/test/tkgctl/aws_cc/aws_cc_tkr_test.go | 20 ++++++ pkg/v1/tkg/test/tkgctl/shared/tkr_cc_misc.go | 70 +++++++++++++++++++ 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 pkg/v1/tkg/test/tkgctl/aws_cc/aws_cc_tkr_test.go create mode 100644 pkg/v1/tkg/test/tkgctl/shared/tkr_cc_misc.go diff --git a/pkg/v1/tkg/test/framework/cluster_proxy.go b/pkg/v1/tkg/test/framework/cluster_proxy.go index 57acced6ed..ac94fee3b8 100644 --- a/pkg/v1/tkg/test/framework/cluster_proxy.go +++ b/pkg/v1/tkg/test/framework/cluster_proxy.go @@ -8,18 +8,17 @@ import ( "context" . "github.com/onsi/gomega" // nolint:stylecheck - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - - runv1 "github.com/vmware-tanzu/tanzu-framework/apis/run/v1alpha3" - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3" "sigs.k8s.io/controller-runtime/pkg/client" + + runv1 "github.com/vmware-tanzu/tanzu-framework/apis/run/v1alpha3" ) // ClusterProxy hold information to connect to a cluster diff --git a/pkg/v1/tkg/test/tkgctl/aws_cc/aws_cc_tkr_test.go b/pkg/v1/tkg/test/tkgctl/aws_cc/aws_cc_tkr_test.go new file mode 100644 index 0000000000..31f904ed23 --- /dev/null +++ b/pkg/v1/tkg/test/tkgctl/aws_cc/aws_cc_tkr_test.go @@ -0,0 +1,20 @@ +// Copyright 2022 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package aws_cc + +import ( + "context" + + . "github.com/onsi/ginkgo" + + . "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/test/tkgctl/shared" +) + +var _ = Describe("Functional tests for aws - TKR Compatibility tests", func() { + TKRCompatibilityValidationSpec(context.TODO(), func() TKRCompatibilityValidationSpecInput { + return TKRCompatibilityValidationSpecInput{ + E2EConfig: e2eConfig, + } + }) +}) diff --git a/pkg/v1/tkg/test/tkgctl/shared/tkr_cc_misc.go b/pkg/v1/tkg/test/tkgctl/shared/tkr_cc_misc.go new file mode 100644 index 0000000000..7645aed2ab --- /dev/null +++ b/pkg/v1/tkg/test/tkgctl/shared/tkr_cc_misc.go @@ -0,0 +1,70 @@ +// Copyright 2022 VMware, Inc. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +// nolint:typecheck,goconst,gocritic,stylecheck,nolintlint +package shared + +import ( + "context" + "fmt" + + "github.com/go-logr/logr" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/util/conditions" + + runv1 "github.com/vmware-tanzu/tanzu-framework/apis/run/v1alpha3" + "github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/test/framework" + "github.com/vmware-tanzu/tanzu-framework/pkg/v2/tkr/controller/tkr-source/compatibility" +) + +type TKRCompatibilityValidationSpecInput struct { + E2EConfig *framework.E2EConfig + OtherConfigs map[string]string +} + +func TKRCompatibilityValidationSpec(ctx context.Context, inputGetter func() TKRCompatibilityValidationSpecInput) { //nolint:funlen + var ( + input TKRCompatibilityValidationSpecInput + mcProxy *framework.ClusterProxy + mcContextName string + tkrs []*runv1.TanzuKubernetesRelease + ) + + BeforeEach(func() { //nolint:dupl + input = inputGetter() + mcClusterName := input.E2EConfig.ManagementClusterName + mcContextName = mcClusterName + "-admin@" + mcClusterName + mcProxy = framework.NewClusterProxy(mcClusterName, "", mcContextName) + }) + + It("Should validate the compatible status is correctly calculated for all TKRs", func() { + tkrCompatibility := &compatibility.Compatibility{ + Client: mcProxy.GetClient(), + Config: compatibility.Config{ + TKRNamespace: "tkg-system", + }, + Log: logr.Discard(), + } + By("Validating all TKRs compatibility status condition is updated correctly") + compatibleSet, err := tkrCompatibility.CompatibleVersions(context.Background()) + fmt.Printf("CompatibleSet is :%+v \n", compatibleSet) + Expect(err).ToNot(HaveOccurred()) + tkrs = mcProxy.GetTKRs(ctx) + for i := range tkrs { + fmt.Printf("Validating the compatibility status condition for TKR '%s'\n", tkrs[i].Name) + if compatibleSet.Has(tkrs[i].Spec.Version) { + Expect(conditions.IsTrue(tkrs[i], runv1.ConditionCompatible)).To(BeTrue(), + fmt.Sprintf("TKR '%s' is expected to have Compatible condition to be true", tkrs[i].Name)) + } else { + Expect(conditions.IsFalse(tkrs[i], runv1.ConditionCompatible)).To(BeTrue(), + fmt.Sprintf("TKR '%s' is expected to have Compatible condition to be false", tkrs[i].Name)) + Expect(*conditions.GetSeverity(tkrs[i], runv1.ConditionCompatible)).ToNot(Equal(clusterv1.ConditionSeverityWarning), + fmt.Sprintf("TKR '%s' Compatible condition's severity is expected to be 'Warning' if condition status is False", tkrs[i].Name)) + } + } + By("Test successful !") + }) + +}