代码拉取完成,页面将自动刷新
package roundtrip
import (
"context"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
clusterv1 "open-cluster-management.io/api/cluster/v1"
"github.com/oam-dev/cluster-gateway/e2e/framework"
multicluster "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/transport"
clusterv1alpha1 "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1"
)
const (
roundtripTestBasename = "roundtrip"
)
var _ = Describe("Basic RoundTrip Test", func() {
f := framework.NewE2EFramework(roundtripTestBasename)
It("ClusterGateway in the API discovery",
func() {
By("Discovering ClusterGateway")
nativeClient := f.HubNativeClient()
resources, err := nativeClient.Discovery().
ServerResourcesForGroupVersion("cluster.core.oam.dev/v1alpha1")
Expect(err).NotTo(HaveOccurred())
apiFound := false
for _, resource := range resources.APIResources {
if resource.Kind == "ClusterGateway" {
apiFound = true
}
}
if !apiFound {
Fail(`Api ClusterGateway not found`)
}
})
It("ManagedCluster present",
func() {
By("Getting ManagedCluster")
if f.IsOCMInstalled() {
runtimeClient := f.HubRuntimeClient()
cluster := &clusterv1.ManagedCluster{}
err := runtimeClient.Get(context.TODO(), types.NamespacedName{
Name: f.TestClusterName(),
}, cluster)
Expect(err).NotTo(HaveOccurred())
}
})
It("ClusterGateway can be read via GET",
func() {
By("Getting ClusterGateway")
runtimeClient := f.HubRuntimeClient()
clusterGateway := &clusterv1alpha1.ClusterGateway{}
err := runtimeClient.Get(context.TODO(), types.NamespacedName{
Name: f.TestClusterName(),
}, clusterGateway)
Expect(err).NotTo(HaveOccurred())
})
It("ClusterGateway can be read via LIST",
func() {
By("Getting ClusterGateway")
runtimeClient := f.HubRuntimeClient()
clusterGatewayList := &clusterv1alpha1.ClusterGatewayList{}
err := runtimeClient.List(context.TODO(), clusterGatewayList)
Expect(err).NotTo(HaveOccurred())
clusterFound := false
for _, clusterGateway := range clusterGatewayList.Items {
if clusterGateway.Name == f.TestClusterName() {
clusterFound = true
}
}
if !clusterFound {
Fail(`ClusterGateway not found`)
}
})
It("ClusterGateway healthiness can be manipulated",
func() {
By("get healthiness")
gw, err := f.HubGatewayClient().
ClusterV1alpha1().
ClusterGateways().
GetHealthiness(context.TODO(), f.TestClusterName(), metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(gw).ShouldNot(BeNil())
Expect(gw.Status.Healthy).To(BeFalse())
By("update healthiness")
gw.Status.Healthy = true
gw.Status.HealthyReason = clusterv1alpha1.HealthyReasonTypeConnectionTimeout
updated, err := f.HubGatewayClient().
ClusterV1alpha1().
ClusterGateways().
UpdateHealthiness(context.TODO(), gw, metav1.UpdateOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(updated).NotTo(BeNil())
Expect(updated.Status.Healthy).To(BeTrue())
Expect(updated.Status.HealthyReason).To(Equal(clusterv1alpha1.HealthyReasonTypeConnectionTimeout))
})
It("Probing cluster health (raw)",
func() {
resp, err := f.HubNativeClient().Discovery().
RESTClient().
Get().
AbsPath(
"apis/cluster.core.oam.dev/v1alpha1/clustergateways",
f.TestClusterName(),
"proxy",
"healthz",
).DoRaw(context.TODO())
Expect(err).NotTo(HaveOccurred())
Expect(string(resp)).To(Equal("ok"))
})
It("Probing cluster health (context)",
func() {
cfg := f.HubRESTConfig()
cfg.WrapTransport = multicluster.NewClusterGatewayRoundTripper
multiClusterClient, err := kubernetes.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())
resp, err := multiClusterClient.RESTClient().
Get().
AbsPath("healthz").
DoRaw(multicluster.WithMultiClusterContext(context.TODO(), f.TestClusterName()))
Expect(err).NotTo(HaveOccurred())
Expect(string(resp)).To(Equal("ok"))
})
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。