Test hive CreateNamespace in e2e (#2433)

This commit is contained in:
Yehor Naumenko 2023-01-18 11:45:46 +01:00 коммит произвёл GitHub
Родитель 0527b974fe
Коммит c19247339b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 72 добавлений и 26 удалений

Просмотреть файл

@ -16,24 +16,11 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"github.com/Azure/ARO-RP/pkg/util/liveconfig"
)
// Tests the kubeconfig ability to get and manipulate the cluster
var _ = Describe("AKS cluster present", Pending, func() {
ctx := context.Background()
var liveConfig liveconfig.Manager
var kubeConfig *rest.Config
BeforeEach(func() {
var err error
liveConfig, err = _env.NewLiveConfigManager(ctx)
Expect(err).To(BeNil())
})
// TODO: remove this when all regions have the AKS
// since this is going to happen in a weeks,
@ -59,16 +46,6 @@ var _ = Describe("AKS cluster present", Pending, func() {
var err error
// AKS shards starts from 1
// E2E uses kubeconfig directly, therefore this call is useless in e2e scenario
// first real test is done in INT environment
kubeConfig, err = liveConfig.HiveRestConfig(ctx, 1)
Expect(err).To(BeNil())
Expect(kubeConfig).ToNot(BeNil())
kubernetescli, err := kubernetes.NewForConfig(kubeConfig)
Expect(err).To(BeNil())
// to avoid name collision by accident
testNamespaceName := "e2e-test-namespace-" + time.Now().Format("20060102150405")
@ -78,16 +55,16 @@ var _ = Describe("AKS cluster present", Pending, func() {
},
}
_, err = kubernetescli.CoreV1().Namespaces().Create(ctx, testNamespace, metav1.CreateOptions{})
_, err = clients.HiveAKS.CoreV1().Namespaces().Create(ctx, testNamespace, metav1.CreateOptions{})
Expect(err).To(BeNil())
Eventually(func() error {
_, err := kubernetescli.CoreV1().Namespaces().Get(ctx, testNamespaceName, metav1.GetOptions{})
_, err := clients.HiveAKS.CoreV1().Namespaces().Get(ctx, testNamespaceName, metav1.GetOptions{})
return err
}).WithTimeout(20 * time.Second).WithPolling(1 * time.Second).Should(Succeed())
Eventually(func() error {
return kubernetescli.CoreV1().Namespaces().Delete(ctx, testNamespaceName, metav1.DeleteOptions{})
return clients.HiveAKS.CoreV1().Namespaces().Delete(ctx, testNamespaceName, metav1.DeleteOptions{})
}).WithTimeout(20 * time.Second).WithPolling(1 * time.Second).Should(Succeed())
})

42
test/e2e/hive_manager.go Normal file
Просмотреть файл

@ -0,0 +1,42 @@
package e2e
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var _ = Describe("Hive manager creates a namespace", func() {
var ns *corev1.Namespace
AfterEach(func() {
if ns != nil {
Eventually(func() error {
return clients.HiveAKS.CoreV1().Namespaces().Delete(context.Background(), ns.Name, metav1.DeleteOptions{})
}).WithTimeout(20 * time.Second).WithPolling(1 * time.Second).Should(Succeed())
}
})
It("Should be created successfully", func() {
var err error
ns, err = clients.HiveClusterManager.CreateNamespace(context.Background())
Expect(err).NotTo(HaveOccurred())
Expect(ns).NotTo(BeNil())
res, err := clients.HiveAKS.CoreV1().Namespaces().Get(context.Background(), ns.Name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(res).NotTo(BeNil())
Expect(res.String()).To(Equal(ns.String()))
})
})

Просмотреть файл

@ -34,6 +34,7 @@ import (
"k8s.io/client-go/tools/clientcmd/api/latest"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/hive"
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/compute"
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/features"
@ -60,6 +61,9 @@ type clientSet struct {
NetworkSecurityGroups network.SecurityGroupsClient
Subnet network.SubnetsClient
HiveAKS kubernetes.Interface
HiveClusterManager hive.ClusterManager
RestConfig *rest.Config
Kubernetes kubernetes.Interface
MachineAPI machineclient.Interface
@ -289,6 +293,26 @@ func newClientSet(ctx context.Context) (*clientSet, error) {
return nil, err
}
liveCfg, err := _env.NewLiveConfigManager(ctx)
if err != nil {
return nil, err
}
aksCfg, err := liveCfg.HiveRestConfig(ctx, 1)
if err != nil {
return nil, err
}
hiveAKS, err := kubernetes.NewForConfig(aksCfg)
if err != nil {
return nil, err
}
hiveCM, err := hive.NewFromConfig(log, _env, aksCfg)
if err != nil {
return nil, err
}
return &clientSet{
OpenshiftClustersv20200430: redhatopenshift20200430.NewOpenShiftClustersClient(_env.Environment(), _env.SubscriptionID(), authorizer),
Operationsv20200430: redhatopenshift20200430.NewOperationsClient(_env.Environment(), _env.SubscriptionID(), authorizer),
@ -302,6 +326,9 @@ func newClientSet(ctx context.Context) (*clientSet, error) {
Subnet: network.NewSubnetsClient(_env.Environment(), _env.SubscriptionID(), authorizer),
NetworkSecurityGroups: network.NewSecurityGroupsClient(_env.Environment(), _env.SubscriptionID(), authorizer),
HiveAKS: hiveAKS,
HiveClusterManager: hiveCM,
RestConfig: restconfig,
Kubernetes: cli,
MachineAPI: machineapicli,