Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix recreate delegate pod when deleted #145

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ kubemcsa
kubeconfig*

scratch/
cluster-dump/
4 changes: 1 addition & 3 deletions pkg/scheduler_plugins/candidate/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ func (pl *Plugin) Name() string {

func (pl *Plugin) PreFilter(ctx context.Context, state *framework.CycleState, p *v1.Pod) *framework.Status {
// reset annotations
patch := []byte(`{"metadata":{"annotations":{
"` + common.AnnotationKeyIsReserved + `":null,
"` + common.AnnotationKeyIsAllowed + `":null}}}`)
patch := []byte(`{"metadata":{"annotations":{"` + common.AnnotationKeyIsReserved + `":null}}}`)
if _, err := pl.client.MulticlusterV1alpha1().PodChaperons(p.Namespace).Patch(ctx, p.Name, types.MergePatchType, patch, metav1.PatchOptions{}); err != nil {
return framework.NewStatus(framework.Error, err.Error())
}
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 @@ -24,16 +24,16 @@ cleanup_test() {
i=$1

k $i apply -f test/e2e/cleanup/test.yaml
k $i rollout status deploy pause
target="$(k $i get pod -l app=pause -o json | jq -er '.items[0].metadata.finalizers[0] | split("-") | .[1]')"
k $i rollout status deploy cleanup
target="$(k $i get pod -l app=cleanup -o json | jq -er '.items[0].metadata.finalizers[0] | split("-") | .[1]')"
k $i delete target $target

export -f cleanup_test_iteration
timeout --foreground 90s bash -c "until cleanup_test_iteration $i; do sleep 1; done"
# use --foreground to catch ctrl-c
# https://unix.stackexchange.com/a/233685

admiralty_connect 1 "${target: -1}"
admiralty_connect $i "${target: -1}"
k $i delete -f test/e2e/cleanup/test.yaml
}

Expand All @@ -43,7 +43,7 @@ cleanup_test_iteration() {
set -exuo pipefail
source test/e2e/aliases.sh

[ $(k $i get pod -l app=pause -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 ]
}

if [[ "${BASH_SOURCE[0]:-}" == "${0}" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/cleanup/test.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pause
name: cleanup
spec:
selector:
matchLabels:
app: pause
app: cleanup
template:
metadata:
labels:
app: pause
app: cleanup
annotations:
multicluster.admiralty.io/elect: ""
spec:
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/delete-delegate/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
#
# 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.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -exuo pipefail

source test/e2e/aliases.sh
source test/e2e/admiralty.sh

delete-delegate_test() {
i=$1

k $i apply -f test/e2e/delete-delegate/test.yaml
k $i rollout status deploy delete-delegate
target="$(k $i get pod -l app=delete-delegate -o json | jq -er '.items[0].metadata.finalizers[0] | split("-") | .[1]')"
j="${target: -1}"
k $j delete pod -l multicluster.admiralty.io/app=delete-delegate --wait --timeout=30s
k $j wait pod -l multicluster.admiralty.io/app=delete-delegate --for=condition=PodScheduled
k $i delete -f test/e2e/delete-delegate/test.yaml
}

if [[ "${BASH_SOURCE[0]:-}" == "${0}" ]]; then
delete-delegate_test "${@}"
fi
18 changes: 18 additions & 0 deletions test/e2e/delete-delegate/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: delete-delegate
spec:
selector:
matchLabels:
app: delete-delegate
template:
metadata:
labels:
app: delete-delegate
annotations:
multicluster.admiralty.io/elect: ""
spec:
containers:
- name: pause
image: gcr.io/google_containers/pause