github.com/oam-dev/cluster-gateway@v1.9.0/e2e/benchmark/configmap.go (about) 1 package kubernetes 2 3 import ( 4 "context" 5 6 . "github.com/onsi/ginkgo/v2" 7 . "github.com/onsi/gomega" 8 corev1 "k8s.io/api/core/v1" 9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 "k8s.io/client-go/kubernetes" 11 12 "github.com/oam-dev/cluster-gateway/e2e/framework" 13 multicluster "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/transport" 14 ) 15 16 const ( 17 configmapTestBasename = "configmap-benchmark" 18 ) 19 20 var direct bool 21 22 var _ = Describe("Basic RoundTrip Test", 23 func() { 24 f := framework.NewE2EFramework(configmapTestBasename) 25 26 var multiClusterClient kubernetes.Interface 27 var err error 28 29 cfg := f.HubRESTConfig() 30 cfg.RateLimiter = nil 31 if !direct { 32 cfg.WrapTransport = multicluster.NewClusterGatewayRoundTripper 33 } 34 multiClusterClient, err = kubernetes.NewForConfig(cfg) 35 Expect(err).NotTo(HaveOccurred()) 36 37 var targetConfigMapName = "cluster-gateway-e2e-" + framework.RunID 38 var targetConfigMapNamespace = "default" 39 40 Measure("it should do something hard efficiently", func(b Benchmarker) { 41 runtime := b.Time("create-update-delete", func() { 42 43 creatingConfigMap := &corev1.ConfigMap{ 44 ObjectMeta: metav1.ObjectMeta{ 45 Namespace: targetConfigMapNamespace, 46 Name: targetConfigMapName, 47 }, 48 Data: map[string]string{ 49 "version": "1", 50 }, 51 } 52 createdConfigMap, err := multiClusterClient.CoreV1(). 53 ConfigMaps(targetConfigMapNamespace). 54 Create( 55 multicluster.WithMultiClusterContext(context.TODO(), f.TestClusterName()), 56 creatingConfigMap, 57 metav1.CreateOptions{}) 58 Expect(err).NotTo(HaveOccurred()) 59 60 createdConfigMap.Data["version"] = "2" 61 _, err = multiClusterClient.CoreV1(). 62 ConfigMaps(targetConfigMapNamespace). 63 Update( 64 multicluster.WithMultiClusterContext(context.TODO(), f.TestClusterName()), 65 createdConfigMap, 66 metav1.UpdateOptions{}) 67 Expect(err).NotTo(HaveOccurred()) 68 69 err = multiClusterClient.CoreV1(). 70 ConfigMaps(targetConfigMapNamespace). 71 Delete( 72 multicluster.WithMultiClusterContext(context.TODO(), f.TestClusterName()), 73 targetConfigMapName, 74 metav1.DeleteOptions{}) 75 Expect(err).NotTo(HaveOccurred()) 76 }) 77 78 Ω(runtime.Seconds()). 79 Should( 80 BeNumerically("<", 15), 81 "shouldn't take too long.") 82 }, 100) 83 84 Measure("get namespace kube-system from managed cluster", func(b Benchmarker) { 85 runtime := b.Time("runtime", func() { 86 _, err = multiClusterClient.CoreV1().Namespaces().Get( 87 multicluster.WithMultiClusterContext(context.TODO(), f.TestClusterName()), "kube-system", metav1.GetOptions{}) 88 Expect(err).NotTo(HaveOccurred()) 89 }) 90 91 Ω(runtime.Seconds()).Should(BeNumerically("<", 15)) 92 93 }, 1000) 94 95 Measure("list namespace from managed cluster", func(b Benchmarker) { 96 runtime := b.Time("runtime", func() { 97 _, err = multiClusterClient.CoreV1().Namespaces().List( 98 multicluster.WithMultiClusterContext(context.TODO(), f.TestClusterName()), metav1.ListOptions{Limit: 100}) 99 Expect(err).NotTo(HaveOccurred()) 100 }) 101 102 Ω(runtime.Seconds()).Should(BeNumerically("<", 15)) 103 104 }, 1000) 105 })