Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Add e2e test for TKR compatibility status condition (#3003)
Browse files Browse the repository at this point in the history
Signed-off-by: Prem Kumar Kalle <[email protected]>
  • Loading branch information
prkalle authored Jul 26, 2022
1 parent e9cd07f commit 44c3fb4
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/v1/tkg/test/framework/cluster_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions pkg/v1/tkg/test/tkgctl/aws_cc/aws_cc_tkr_test.go
Original file line number Diff line number Diff line change
@@ -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,
}
})
})
70 changes: 70 additions & 0 deletions pkg/v1/tkg/test/tkgctl/shared/tkr_cc_misc.go
Original file line number Diff line number Diff line change
@@ -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 !")
})

}

0 comments on commit 44c3fb4

Please sign in to comment.