diff --git a/pkg/controllers/follow/service/controller.go b/pkg/controllers/follow/service/controller.go index 3c312bb1..3eecf672 100644 --- a/pkg/controllers/follow/service/controller.go +++ b/pkg/controllers/follow/service/controller.go @@ -197,7 +197,12 @@ func (r reconciler) Handle(obj interface{}) (requeueAfter *time.Duration, err er } } else { spec := svc.Spec.DeepCopy() - spec.ClusterIP = remoteSvc.Spec.ClusterIP + if spec.Type != corev1.ServiceTypeExternalName { + // ClusterIP is controlled locally. + // However, if the type field is changed to ExternalName, ClusterIP must be reset. + spec.ClusterIP = remoteSvc.Spec.ClusterIP // "" + spec.ClusterIPs = remoteSvc.Spec.ClusterIPs // nil + } if !reflect.DeepEqual(&remoteSvc.Spec, spec) { remoteCopy := remoteSvc.DeepCopy() remoteCopy.Spec = *spec.DeepCopy() @@ -285,6 +290,11 @@ func makeRemoteService(actual *corev1.Service) *corev1.Service { gold.Annotations[common.AnnotationKeyIsDelegate] = "" controller.AddRemoteControllerReference(gold, actual) gold.Spec = *actual.Spec.DeepCopy() - gold.Spec.ClusterIP = "" // cluster IP given by each cluster (not really a top-level spec) + if actual.Spec.ClusterIP != corev1.ClusterIPNone { + // cluster IP given by each cluster (not really a top-level spec) + // but don't empty for headless services (keep None) + gold.Spec.ClusterIP = "" + gold.Spec.ClusterIPs = nil + } return gold } diff --git a/test/e2e/argo.sh b/test/e2e/argo.sh index 8fff23fd..80ec89f2 100755 --- a/test/e2e/argo.sh +++ b/test/e2e/argo.sh @@ -77,8 +77,8 @@ argo_test() { KUBECONFIG=kubeconfig-cluster$i ./argo submit --serviceaccount argo-workflow --wait examples/argo-workflows/blog-scenario-a-multicluster.yaml # delegate pods should be spread between both clusters - [ $(k "$i" get pod -l multicluster.admiralty.io/workflow | wc -l) -gt 1 ] - [ $(k "$j" get pod -l multicluster.admiralty.io/workflow | wc -l) -gt 1 ] + [ $(k "$i" get pod -l multicluster.admiralty.io/workflow | wc -l) -gt 1 ] || exit 1 + [ $(k "$j" get pod -l multicluster.admiralty.io/workflow | wc -l) -gt 1 ] || exit 1 KUBECONFIG=kubeconfig-cluster$i ./argo delete --all } diff --git a/test/e2e/cleanup/test.sh b/test/e2e/cleanup/test.sh index 0e0f7509..9fa62874 100755 --- a/test/e2e/cleanup/test.sh +++ b/test/e2e/cleanup/test.sh @@ -15,7 +15,7 @@ # limitations under the License. # -set -exuo pipefail +set -euo pipefail source test/e2e/aliases.sh source test/e2e/admiralty.sh @@ -29,7 +29,7 @@ cleanup_test() { k $i delete target $target export -f cleanup_test_iteration - timeout --foreground 90s bash -c "until cleanup_test_iteration $i; do sleep 1; done" + timeout --foreground 120s bash -c "until cleanup_test_iteration $i; do sleep 1; done" # use --foreground to catch ctrl-c # https://unix.stackexchange.com/a/233685 @@ -40,10 +40,10 @@ cleanup_test() { cleanup_test_iteration() { i=$1 - set -exuo pipefail + set -euo pipefail source test/e2e/aliases.sh - [ $(k $i get pod -l app=cleanup -o json | jq -e '.items[0].metadata.finalizers | length') -eq 0 ] + [ $(k $i get pod -l app=cleanup -o json | jq -e '.items[0].metadata.finalizers | length') -eq 0 ] || return 1 } if [[ "${BASH_SOURCE[0]:-}" == "${0}" ]]; then diff --git a/test/e2e/delete-delegate/test.sh b/test/e2e/delete-delegate/test.sh index 98d8c71d..f1b2d09d 100755 --- a/test/e2e/delete-delegate/test.sh +++ b/test/e2e/delete-delegate/test.sh @@ -15,7 +15,7 @@ # limitations under the License. # -set -exuo pipefail +set -euo pipefail source test/e2e/aliases.sh source test/e2e/admiralty.sh diff --git a/test/e2e/ingress/test.sh b/test/e2e/ingress/test.sh old mode 100644 new mode 100755 index a53f8581..a5162468 --- a/test/e2e/ingress/test.sh +++ b/test/e2e/ingress/test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Copyright 2020 The Multicluster-Scheduler Authors. +# Copyright 2022 The Multicluster-Scheduler Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -37,12 +37,13 @@ ingress_test_iteration() { i=$1 j=$2 + set -euo pipefail source test/e2e/aliases.sh - [ $(k "$j" get ingress | wc -l) -eq 2 ] # including header - [ $(k "$j" get service | wc -l) -eq 3 ] # including header and the "kubernetes" service + [ $(k "$j" get ingress | wc -l) -eq 2 ] || return 1 # including header + [ $(k "$j" get service | wc -l) -eq 3 ] || return 1 # including header and the "kubernetes" service - k "$i" annotate ing follow annotate=test + k "$i" annotate ing follow annotate=test --overwrite k "$j" get ing follow --no-headers -o custom-columns=ANNOTATIONS:.metadata.annotations | grep "annotate:test" } diff --git a/test/e2e/no-reservation/test.sh b/test/e2e/no-reservation/test.sh index 1cbc768e..e7d6a492 100755 --- a/test/e2e/no-reservation/test.sh +++ b/test/e2e/no-reservation/test.sh @@ -15,7 +15,7 @@ # limitations under the License. # -set -exuo pipefail +set -euo pipefail source test/e2e/aliases.sh source test/e2e/admiralty.sh @@ -29,7 +29,7 @@ no-reservation_test() { k 1 apply -f test/e2e/no-reservation/test.yaml export -f no-reservation_test_iteration - timeout --foreground 30s bash -c "until no-reservation_test_iteration; do sleep 1; done" + timeout --foreground 60s bash -c "until no-reservation_test_iteration; do sleep 1; done" # use --foreground to catch ctrl-c # https://unix.stackexchange.com/a/233685 @@ -42,7 +42,7 @@ no-reservation_test() { } no-reservation_test_iteration() { - set -exuo pipefail + set -euo pipefail source test/e2e/aliases.sh k 1 get pod -l app=no-reservation -o json | jq -e '.items[0].status.conditions[] | select(.type == "PodScheduled") | .reason == "Unschedulable"' diff --git a/test/e2e/no-rogue-finalizer/test.sh b/test/e2e/no-rogue-finalizer/test.sh index 06acc3ad..090f41a9 100755 --- a/test/e2e/no-rogue-finalizer/test.sh +++ b/test/e2e/no-rogue-finalizer/test.sh @@ -21,18 +21,19 @@ source test/e2e/aliases.sh no-rogue-finalizer_test() { # give the controllers 30s to clean up after other test objects have been deleted export -f no-rogue-finalizer_test_iteration - timeout --foreground 5s bash -c "until no-rogue-finalizer_test_iteration; do sleep 1; done" + timeout --foreground 30s bash -c "until no-rogue-finalizer_test_iteration; do sleep 1; done" # use --foreground to catch ctrl-c # https://unix.stackexchange.com/a/233685 } no-rogue-finalizer_test_iteration() { + set -euo pipefail source test/e2e/aliases.sh # check that we didn't add finalizers to uncontrolled resources finalizer="multicluster.admiralty.io/" for resource in pods configmaps secrets services ingresses; do - [ $(k 1 get $resource -A -o custom-columns=FINALIZERS:.metadata.finalizers | grep -c $finalizer) -eq 0 ] + k 1 get $resource -A -o custom-columns=FINALIZERS:.metadata.finalizers | grep -qv $finalizer done }