Skip to content

Commit f8312ec

Browse files
fra98adamjensenbot
authored andcommitted
test: decreased ha replicas to 2 + small fixes
1 parent b242938 commit f8312ec

File tree

11 files changed

+108
-29
lines changed

11 files changed

+108
-29
lines changed

pkg/gateway/concurrent/gateway.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package concurrent
1616

1717
import (
1818
"context"
19+
"fmt"
1920
"net"
2021

2122
corev1 "k8s.io/api/core/v1"
@@ -31,16 +32,16 @@ var _ manager.Runnable = &RunnableGateway{}
3132
type RunnableGateway struct {
3233
Client client.Client
3334

34-
PodName string
35-
DeploymentName string
36-
Namespace string
35+
PodName string
36+
GatewayName string
37+
Namespace string
3738

3839
Socket net.Listener
3940
GuestConnections ipc.GuestConnections
4041
}
4142

4243
// NewRunnableGateway creates a new Runnable.
43-
func NewRunnableGateway(cl client.Client, podName, deploymentName, namespace string, containerNames []string) (*RunnableGateway, error) {
44+
func NewRunnableGateway(cl client.Client, podName, gatewayName, namespace string, containerNames []string) (*RunnableGateway, error) {
4445
guestConnections := ipc.NewGuestConnections(containerNames)
4546

4647
socket, err := ipc.CreateListenSocket(unixSocketPath)
@@ -56,7 +57,7 @@ func NewRunnableGateway(cl client.Client, podName, deploymentName, namespace str
5657
return &RunnableGateway{
5758
Client: cl,
5859
PodName: podName,
59-
DeploymentName: deploymentName,
60+
GatewayName: gatewayName,
6061
Namespace: namespace,
6162
Socket: socket,
6263
GuestConnections: guestConnections,
@@ -67,7 +68,7 @@ func NewRunnableGateway(cl client.Client, podName, deploymentName, namespace str
6768
func (rg *RunnableGateway) Start(ctx context.Context) error {
6869
defer rg.Close()
6970

70-
pods, err := ListAllGatewaysReplicas(ctx, rg.Client, rg.Namespace, rg.DeploymentName)
71+
pods, err := ListAllGatewaysReplicas(ctx, rg.Client, rg.Namespace, rg.GatewayName)
7172
if err != nil {
7273
return err
7374
}
@@ -84,6 +85,10 @@ func (rg *RunnableGateway) Start(ctx context.Context) error {
8485
}
8586
}
8687

88+
if activePod == nil {
89+
return fmt.Errorf("active gateway pod not found")
90+
}
91+
8792
if err := AddActiveGatewayLabel(ctx, rg.Client, client.ObjectKeyFromObject(activePod)); err != nil {
8893
return err
8994
}

pkg/gateway/concurrent/k8s.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ func RemoveActiveGatewayLabel(ctx context.Context, cl client.Client, key client.
7777
return nil
7878
}
7979

80-
// ListAllGatewaysReplicas returns the list of all the gateways replicas of the same deployment.
81-
func ListAllGatewaysReplicas(ctx context.Context, cl client.Client, namespace, deploymentName string) ([]corev1.Pod, error) {
80+
// ListAllGatewaysReplicas returns the list of all the gateways replicas of the same gateway.
81+
func ListAllGatewaysReplicas(ctx context.Context, cl client.Client, namespace, gatewayName string) ([]corev1.Pod, error) {
8282
podList := &corev1.PodList{}
8383
if err := cl.List(ctx, podList, client.InNamespace(namespace), client.MatchingLabels{
84-
consts.K8sAppNameKey: deploymentName,
84+
consts.K8sAppNameKey: gatewayName,
8585
}); err != nil {
8686
return nil, err
8787
}

pkg/utils/maps/maps.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package maps
1717
import (
1818
"fmt"
1919
"maps"
20-
"sort"
20+
"slices"
2121
"strings"
2222

2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -179,16 +179,14 @@ func UpdateCache(annots, template map[string]string, cacheKey string) map[string
179179
// SerializeMap convert a map in a string of concatenated keys seprated by commas.
180180
func SerializeMap(m map[string]string) string {
181181
serialized := ""
182-
keys := make([]string, len(m))
183-
i := 0
182+
keys := make([]string, 0, len(m))
184183
for k := range m {
185-
keys[i] = k
186-
i++
184+
keys = append(keys, k)
187185
}
188-
sort.Strings(keys)
186+
slices.Sort(keys)
189187

190188
for _, k := range keys {
191-
serialized += fmt.Sprintf("%s,", m[k])
189+
serialized += fmt.Sprintf("%s,", k)
192190
}
193191
return serialized
194192
}

test/e2e/cruise/network/network_test.go

+49-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444

4545
const (
4646
// clustersRequired is the number of clusters required in this E2E test.
47-
clustersRequired = 2
47+
clustersRequired = 3
4848
// testName is the name of this E2E test.
4949
testName = "NETWORK"
5050
// StressMax is the maximum number of stress iterations.
@@ -126,16 +126,29 @@ var _ = Describe("Liqo E2E", func() {
126126
When("\"liqoctl test network\" runs", func() {
127127
It("should succeed both before and after gateway pods restart", func() {
128128
// Run the tests.
129-
Eventually(runLiqoctlNetworkTests(defaultArgs), timeout, interval).Should(Succeed())
129+
Eventually(func() error {
130+
return runLiqoctlNetworkTests(defaultArgs)
131+
}, timeout, interval).Should(Succeed())
130132

131133
// Restart the gateway pods.
132134
for i := range testContext.Clusters {
133135
RestartPods(testContext.Clusters[i].ControllerClient)
134136
}
135137

138+
// Check if there is only one active gateway pod per remote cluster.
139+
for i := range testContext.Clusters {
140+
numActiveGateway := testContext.Clusters[i].NumPeeredConsumers + testContext.Clusters[i].NumPeeredProviders
141+
Eventually(func() error {
142+
return checkUniqueActiveGatewayPod(testContext.Clusters[i].ControllerClient, numActiveGateway)
143+
}, timeout, interval).Should(Succeed())
144+
}
145+
136146
// Run the tests again.
137-
Eventually(runLiqoctlNetworkTests(defaultArgs), timeout, interval).Should(Succeed())
147+
Eventually(func() error {
148+
return runLiqoctlNetworkTests(defaultArgs)
149+
}, timeout, interval).Should(Succeed())
138150
})
151+
139152
It("should succeed both before and after gateway pods restart (stress gateway deletion and run basic tests)", func() {
140153
args := defaultArgs
141154
args.basic = true
@@ -146,12 +159,22 @@ var _ = Describe("Liqo E2E", func() {
146159
RestartPods(testContext.Clusters[j].ControllerClient)
147160
}
148161

162+
// Check if there is only one active gateway pod per remote cluster.
163+
for j := range testContext.Clusters {
164+
numActiveGateway := testContext.Clusters[j].NumPeeredConsumers + testContext.Clusters[j].NumPeeredProviders
165+
Eventually(func() error {
166+
return checkUniqueActiveGatewayPod(testContext.Clusters[j].ControllerClient, numActiveGateway)
167+
}, timeout, interval).Should(Succeed())
168+
}
169+
149170
if i == stressMax-1 {
150171
args.remove = true
151172
}
152173

153174
// Run the tests.
154-
Eventually(runLiqoctlNetworkTests(args), timeout, interval).Should(Succeed())
175+
Eventually(func() error {
176+
return runLiqoctlNetworkTests(args)
177+
}, timeout, interval).Should(Succeed())
155178
}
156179
})
157180
})
@@ -299,7 +322,6 @@ func RestartPods(cl client.Client) {
299322
if err := cl.List(ctx, deploymentList, &client.ListOptions{
300323
LabelSelector: labels.SelectorFromSet(labels.Set{
301324
gateway.GatewayComponentKey: gateway.GatewayComponentGateway,
302-
concurrent.ActiveGatewayKey: concurrent.ActiveGatewayValue,
303325
}),
304326
}); err != nil {
305327
return err
@@ -314,3 +336,25 @@ func RestartPods(cl client.Client) {
314336
return nil
315337
}, timeout, interval).Should(Succeed())
316338
}
339+
340+
// checkUniqueActiveGatewayPod checks if there is only one active gateway pod.
341+
func checkUniqueActiveGatewayPod(cl client.Client, numActiveGateway int) error {
342+
// Sleep few seconds to be sure that the new leader is elected.
343+
time.Sleep(2 * time.Second)
344+
345+
podList := &corev1.PodList{}
346+
if err := cl.List(ctx, podList, &client.ListOptions{
347+
LabelSelector: labels.SelectorFromSet(labels.Set{
348+
gateway.GatewayComponentKey: gateway.GatewayComponentGateway,
349+
concurrent.ActiveGatewayKey: concurrent.ActiveGatewayValue,
350+
}),
351+
}); err != nil {
352+
return fmt.Errorf("unable to list active gateway pods: %w", err)
353+
}
354+
355+
if len(podList.Items) != numActiveGateway {
356+
return fmt.Errorf("expected %d active gateway pod, got %d", numActiveGateway, len(podList.Items))
357+
}
358+
359+
return nil
360+
}

test/e2e/pipeline/infra/cluster-api/setup.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ WORKDIR=$(dirname "$FILEPATH")
3838
source "$WORKDIR/../../utils.sh"
3939

4040
# shellcheck disable=SC1091
41-
# shellcheck source=./cni.sh
42-
source "$WORKDIR/cni.sh"
41+
# shellcheck source=../cni.sh
42+
source "$WORKDIR/../cni.sh"
4343

4444
export K8S_VERSION=${K8S_VERSION:-"1.29.7"}
4545
K8S_VERSION=$(echo -n "$K8S_VERSION" | sed 's/v//g') # remove the leading v
File renamed without changes.

test/e2e/pipeline/infra/kind/pre-requirements.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ install_kubectl "${OS}" "${ARCH}" "${K8S_VERSION}"
4747

4848
install_helm "${OS}" "${ARCH}"
4949

50-
KIND_VERSION="v0.23.0"
50+
KIND_VERSION="v0.24.0"
5151

5252
echo "Downloading Kind ${KIND_VERSION}"
5353

test/e2e/pipeline/infra/kind/setup.sh

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ WORKDIR=$(dirname "$FILEPATH")
3434
# shellcheck source=../../utils.sh
3535
source "$WORKDIR/../../utils.sh"
3636

37+
# shellcheck disable=SC1091
38+
# shellcheck source=../cni.sh
39+
source "$WORKDIR/../cni.sh"
40+
3741
KIND="${BINDIR}/kind"
3842

3943
CLUSTER_NAME=cluster
@@ -59,6 +63,11 @@ do
5963
echo "Creating cluster ${CLUSTER_NAME}${i}..."
6064
${KIND} create cluster --name "${CLUSTER_NAME}${i}" --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}" --config "${TMPDIR}/liqo-cluster-${CLUSTER_NAME}${i}.yaml" --wait 2m
6165

66+
# Install CNI if kindnet disabled
67+
if [[ ${DISABLE_KINDNET} == "true" ]]; then
68+
"install_${CNI}" "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
69+
fi
70+
6271
# Install metrics-server
6372
install_metrics_server "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
6473
done

test/e2e/pipeline/installer/liqoctl/setup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ LIQO_VERSION="${LIQO_VERSION:-$(git rev-parse HEAD)}"
6363
export SERVICE_CIDR=10.100.0.0/16
6464
export POD_CIDR=10.200.0.0/16
6565
export POD_CIDR_OVERLAPPING=${POD_CIDR_OVERLAPPING:-"false"}
66-
export HA_REPLICAS=3
66+
export HA_REPLICAS=2
6767

6868
for i in $(seq 1 "${CLUSTER_NUMBER}");
6969
do

test/e2e/postinstall/basic_test.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/labels"
2828
"k8s.io/klog/v2"
29+
"k8s.io/utils/ptr"
2930

3031
"github.com/liqotech/liqo/pkg/consts"
32+
gwconsts "github.com/liqotech/liqo/pkg/gateway"
3133
fcutils "github.com/liqotech/liqo/pkg/utils/foreigncluster"
34+
"github.com/liqotech/liqo/pkg/vkMachinery"
3235
"github.com/liqotech/liqo/test/e2e/testutils/tester"
3336
"github.com/liqotech/liqo/test/e2e/testutils/util"
3437
)
@@ -92,8 +95,28 @@ var _ = Describe("Liqo E2E", func() {
9295
for _, tenantNs := range tenantNsList.Items {
9396
Eventually(func() bool {
9497
readyPods, notReadyPods, err := util.ArePodsUp(ctx, cluster.NativeClient, tenantNs.Name)
98+
Expect(err).ToNot(HaveOccurred())
9599
klog.Infof("Tenant pods status: %d ready, %d not ready", len(readyPods), len(notReadyPods))
96-
return err == nil && len(notReadyPods) == 0 && len(readyPods) == util.NumPodsInTenantNs(true, cluster.Role)
100+
// Get deployment gateway
101+
gwDeployments, err := cluster.NativeClient.AppsV1().Deployments(tenantNs.Name).List(ctx, metav1.ListOptions{
102+
LabelSelector: fmt.Sprintf("%s=%s", gwconsts.GatewayComponentKey, gwconsts.GatewayComponentGateway),
103+
})
104+
Expect(err).ToNot(HaveOccurred())
105+
Expect(gwDeployments.Items).To(HaveLen(1))
106+
gwReplicas := int(ptr.Deref(gwDeployments.Items[0].Spec.Replicas, 1))
107+
108+
// Get deployment virtual-kubelet if role is consumer
109+
vkReplicas := 0
110+
if fcutils.IsConsumer(cluster.Role) {
111+
vkDeployments, err := cluster.NativeClient.AppsV1().Deployments(tenantNs.Name).List(ctx, metav1.ListOptions{
112+
LabelSelector: labels.SelectorFromSet(vkMachinery.KubeletBaseLabels).String(),
113+
})
114+
Expect(err).ToNot(HaveOccurred())
115+
Expect(vkDeployments.Items).To(HaveLen(1))
116+
vkReplicas = int(ptr.Deref(vkDeployments.Items[0].Spec.Replicas, 1))
117+
}
118+
return len(notReadyPods) == 0 &&
119+
len(readyPods) == util.NumPodsInTenantNs(true, cluster.Role, gwReplicas, vkReplicas)
97120
}, timeout, interval).Should(BeTrue())
98121
}
99122
},

test/e2e/testutils/util/pod.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ func ArePodsUp(ctx context.Context, clientset kubernetes.Interface, namespace st
7979
}
8080

8181
// NumPodsInTenantNs returns the number of pods that should be present in a tenant namespace.
82-
func NumPodsInTenantNs(networkingEnabled bool, role liqov1beta1.RoleType) int {
82+
func NumPodsInTenantNs(networkingEnabled bool, role liqov1beta1.RoleType, gwReplicas, vkReplicas int) int {
8383
count := 0
8484
// If the network is enabled, it should have the gateway pod.
8585
if networkingEnabled {
86-
count += 3
86+
count += gwReplicas
8787
}
8888
// If the cluster is a consumer, it should have the virtual-kubelet pod.
8989
if fcutils.IsConsumer(role) {
90-
count++
90+
count += vkReplicas
9191
}
9292
return count
9393
}

0 commit comments

Comments
 (0)