Skip to content

Commit

Permalink
stop running get ca from service account test for ocp 1.24 or above
Browse files Browse the repository at this point in the history
Signed-off-by: zhujian <[email protected]>
  • Loading branch information
zhujian7 committed Nov 10, 2023
1 parent 4471917 commit 25e85cf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
27 changes: 21 additions & 6 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
openshiftclientset "github.com/openshift/client-go/config/clientset/versioned"
"github.com/stolostron/cluster-lifecycle-api/helpers/imageregistry"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/stolostron/multicloud-operators-foundation/test/e2e/util"

hiveclient "github.com/openshift/hive/pkg/client/clientset/versioned"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
apiregistrationclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1"

"github.com/stolostron/cluster-lifecycle-api/helpers/imageregistry"
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
clusterclient "open-cluster-management.io/api/client/cluster/clientset/versioned"

"github.com/stolostron/multicloud-operators-foundation/test/e2e/util"
)

func TestE2E(t *testing.T) {
Expand All @@ -33,6 +35,7 @@ const (

var (
dynamicClient dynamic.Interface
discoveryClient discovery.DiscoveryInterface
kubeClient kubernetes.Interface
hiveClient hiveclient.Interface
clusterClient clusterclient.Interface
Expand All @@ -42,8 +45,8 @@ var (
imageRegistryClient imageregistry.Interface
defaultManagedCluster string
foundationNS string
deployedByACM = false
isOcp = false
hubVersionInfo *version.Info
)

// This suite is sensitive to the following environment variables:
Expand All @@ -66,6 +69,9 @@ var _ = ginkgo.BeforeSuite(func() {
dynamicClient, err = util.NewDynamicClient()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

discoveryClient, err = util.NewDiscoveryClient()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

kubeClient, err = util.NewKubeClient()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

Expand All @@ -79,6 +85,8 @@ var _ = ginkgo.BeforeSuite(func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())

imageRegistryClient, err = util.NewImageRegistryClient()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

cfg, err := util.NewKubeConfig()
gomega.Expect(err).ToNot(gomega.HaveOccurred())
addonClient, err = addonv1alpha1client.NewForConfig(cfg)
Expand All @@ -93,6 +101,13 @@ var _ = ginkgo.BeforeSuite(func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}

hubVersionInfo, err = discoveryClient.ServerVersion()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

if hubVersionInfo != nil {
ginkgo.By("hub version: " + hubVersionInfo.String())
}

gomega.Eventually(func() error {
_, err = kubeClient.AppsV1().Deployments("open-cluster-management-agent-addon").Get(context.TODO(), "klusterlet-addon-workmgr", metav1.GetOptions{})
return err
Expand Down
19 changes: 18 additions & 1 deletion test/e2e/managedcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"reflect"
"strconv"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -156,8 +157,24 @@ var _ = ginkgo.Describe("Testing ManagedCluster", func() {
})

ginkgo.It("Get CA from service account", func() {
//Only need to test this case in ocp
// Only need to test this case in ocp (kubernetes version < 1.24)
if !isOcp {
ginkgo.By("hub is not ocp, skip running this test")
return
}

if hubVersionInfo == nil {
ginkgo.By("hub version is nil, skip running this test")
return
}
major, err := strconv.Atoi(hubVersionInfo.Major)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
minor, err := strconv.Atoi(hubVersionInfo.Minor)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

// check if the hub version is 1.24 or above
if major != 1 || minor >= 24 {
ginkgo.By(fmt.Sprintf("hub version is %s, skip running this test", hubVersionInfo.String()))
return
}
serviceAccountCa, err := utils.GetCAFromServiceAccount(context.TODO(), kubeClient)
Expand Down
16 changes: 15 additions & 1 deletion test/e2e/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
apiregistrationclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1"
Expand Down Expand Up @@ -131,6 +131,20 @@ func NewDynamicClient() (dynamic.Interface, error) {
return dynamicClient, nil
}

func NewDiscoveryClient() (discovery.DiscoveryInterface, error) {
kubeConfigFile, err := getKubeConfigFile()
if err != nil {
return nil, err
}

cfg, err := clientcmd.BuildConfigFromFlags("", kubeConfigFile)
if err != nil {
return nil, err
}

return discovery.NewDiscoveryClientForConfig(cfg)
}

func NewDynamicClientWithImpersonate(user string, groups []string) (dynamic.Interface, error) {
kubeConfigFile, err := getKubeConfigFile()
if err != nil {
Expand Down

0 comments on commit 25e85cf

Please sign in to comment.