Skip to content

Commit

Permalink
Merge pull request #147 from adrienjt/fix-service-propagation
Browse files Browse the repository at this point in the history
fix service propagation
  • Loading branch information
adrienjt authored Mar 17, 2022
2 parents ed1135e + 54d3209 commit 2581da6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
14 changes: 12 additions & 2 deletions pkg/controllers/follow/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions test/e2e/argo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions test/e2e/cleanup/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

set -exuo pipefail
set -euo pipefail

source test/e2e/aliases.sh
source test/e2e/admiralty.sh
Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/delete-delegate/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

set -exuo pipefail
set -euo pipefail

source test/e2e/aliases.sh
source test/e2e/admiralty.sh
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/ingress/test.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"
}

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/no-reservation/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

set -exuo pipefail
set -euo pipefail

source test/e2e/aliases.sh
source test/e2e/admiralty.sh
Expand All @@ -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

Expand All @@ -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"'
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/no-rogue-finalizer/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 2581da6

Please sign in to comment.