From 73d99fd1c94bfee88739ab7cefef484c47d2f12e Mon Sep 17 00:00:00 2001 From: Tanmay Jain Date: Thu, 28 Sep 2023 16:20:18 +0530 Subject: [PATCH] adding service port update validation. --- controllers/rack.go | 2 +- test/cluster_helper.go | 40 ++++++++++++++++++++++++++++++++++++++++ test/cluster_test.go | 6 ++++++ test/utils.go | 7 +++++-- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/controllers/rack.go b/controllers/rack.go index d4661d30b..8b396d215 100644 --- a/controllers/rack.go +++ b/controllers/rack.go @@ -59,7 +59,7 @@ func (r *SingleClusterReconciler) reconcileRacks() reconcileResult { ignorablePodNames, ) - // handle failed racks + // Handle failed racks for idx := range rackStateList { var podList []*corev1.Pod diff --git a/test/cluster_helper.go b/test/cluster_helper.go index de006abf4..503dee048 100644 --- a/test/cluster_helper.go +++ b/test/cluster_helper.go @@ -381,6 +381,46 @@ func rollingRestartClusterByRemovingNamespaceDynamicallyTest( return updateCluster(k8sClient, ctx, aeroCluster) } +func validateServiceUpdate(k8sClient client.Client, ctx goctx.Context, + clusterNamespacedName types.NamespacedName, port int32) error { + aeroCluster, err := getCluster(k8sClient, ctx, clusterNamespacedName) + if err != nil { + return err + } + + serviceNamespacesNames := make([]types.NamespacedName, 0) + for podName := range aeroCluster.Status.Pods { + serviceNamespacesNames = append(serviceNamespacesNames, + types.NamespacedName{Name: podName, Namespace: clusterNamespacedName.Namespace}) + } + + serviceNamespacesNames = append(serviceNamespacesNames, clusterNamespacedName) + + for _, serviceNamespacesName := range serviceNamespacesNames { + service := &corev1.Service{} + + err = k8sClient.Get(ctx, serviceNamespacesName, service) + if err != nil { + return err + } + + portChanged := false + + for _, p := range service.Spec.Ports { + if p.Port == port { + portChanged = true + break + } + } + + if !portChanged { + return fmt.Errorf("service %s port not configured correctly", serviceNamespacesName.Name) + } + } + + return nil +} + func validateAerospikeConfigServiceClusterUpdate( log logr.Logger, k8sClient client.Client, ctx goctx.Context, clusterNamespacedName types.NamespacedName, updatedKeys []string, diff --git a/test/cluster_test.go b/test/cluster_test.go index 32374a399..eb19c3f97 100644 --- a/test/cluster_test.go +++ b/test/cluster_test.go @@ -709,6 +709,9 @@ func UpdateClusterTest(ctx goctx.Context) { ) Expect(err).ToNot(HaveOccurred()) + err = validateServiceUpdate(k8sClient, ctx, clusterNamespacedName, tlsPort) + Expect(err).ToNot(HaveOccurred()) + By("RollingRestart By changing tls to non-tls") err = rollingRestartClusterByDisablingTLS( @@ -716,6 +719,9 @@ func UpdateClusterTest(ctx goctx.Context) { ) Expect(err).ToNot(HaveOccurred()) + err = validateServiceUpdate(k8sClient, ctx, clusterNamespacedName, nontlsPort) + Expect(err).ToNot(HaveOccurred()) + By("Upgrade/Downgrade") // TODO: How to check if it is checking cluster stability before killing node diff --git a/test/utils.go b/test/utils.go index 612443669..cc61ca025 100644 --- a/test/utils.go +++ b/test/utils.go @@ -53,6 +53,9 @@ const aerospikeNs string = "aerospike" const zoneKey = "topology.kubernetes.io/zone" const regionKey = "topology.kubernetes.io/region" +const tlsPort = 4333 +const nontlsPort = 3000 + // list of all the namespaces used in test-suite var testNamespaces = []string{namespace, multiClusterNs1, multiClusterNs2, aerospikeNs} @@ -408,8 +411,8 @@ func getNetworkTLSConfig() map[string]interface{} { return map[string]interface{}{ "service": map[string]interface{}{ "tls-name": "aerospike-a-0.test-runner", - "tls-port": 4333, - "port": 3000, + "tls-port": tlsPort, + "port": nontlsPort, }, "fabric": map[string]interface{}{ "tls-name": "aerospike-a-0.test-runner",