generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid deleting scale set if annotation is not parsable or if it does …
…not exist
- Loading branch information
1 parent
6998bf0
commit d90efa2
Showing
10 changed files
with
166 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2022 The Kubernetes 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. | ||
|
||
DIR="$(dirname "${BASH_SOURCE[0]}")" | ||
|
||
DIR="$(realpath "${DIR}")" | ||
|
||
RELEASES=() | ||
|
||
function usage() { | ||
echo "Usage: $0 <kube-version...>" | ||
echo " <kube-version> is the version of kubernetes to test against." | ||
} | ||
|
||
function args() { | ||
if [[ $# -eq 0 ]]; then | ||
usage | ||
exit 1 | ||
fi | ||
while [[ $# -gt 0 ]]; do | ||
RELEASES+=("${1}") | ||
shift | ||
done | ||
} | ||
|
||
function test_create_cluster() { | ||
local release="${1}" | ||
local name="${2}" | ||
|
||
KWOK_KUBE_VERSION="${release}" kwokctl -v=-4 create cluster --name "${name}" --timeout 10m --wait 10m --quiet-pull --config="${DIR}/port-forward.yaml" | ||
if [[ $? -ne 0 ]]; then | ||
echo "Error: Cluster ${name} creation failed" | ||
exit 1 | ||
fi | ||
} | ||
|
||
function test_port_forward() { | ||
local name="${1}" | ||
local pid | ||
local result | ||
kwokctl --name "${name}" kubectl port-forward deployment/fake-pod 8080:"${2}" 2>&1 > /dev/null & | ||
pid=$! | ||
|
||
# allow some time for port forward to start | ||
sleep 1 | ||
result=$(curl localhost:8080/healthz 2>/dev/null) | ||
kill -INT $pid | ||
if [[ ! "${result}" == "ok" ]]; then | ||
echo "Error: failed to port-forward to ${2}" | ||
return 1 | ||
fi | ||
echo "${result}" | ||
} | ||
|
||
function test_apply_node_and_deployment() { | ||
kwokctl --name "${name}" kubectl apply -f "${DIR}/fake-node.yaml" | ||
if [[ $? -ne 0 ]]; then | ||
echo "Error: fake-node apply failed" | ||
exit 1 | ||
fi | ||
kwokctl --name "${name}" kubectl apply -f "${DIR}/fake-deployment.yaml" | ||
if [[ $? -ne 0 ]]; then | ||
echo "Error: fake-deployment apply failed" | ||
exit 1 | ||
fi | ||
} | ||
|
||
function test_delete_cluster() { | ||
local release="${1}" | ||
local name="${2}" | ||
kwokctl delete cluster --name "${name}" | ||
} | ||
|
||
function main() { | ||
local failed=() | ||
for release in "${RELEASES[@]}"; do | ||
echo "------------------------------" | ||
echo "Testing port-forwarding on ${KWOK_RUNTIME} for ${release}" | ||
name="port-forwarding-cluster-${KWOK_RUNTIME}-${release//./-}" | ||
test_create_cluster "${release}" "${name}" || failed+=("create_cluster_${name}") | ||
test_apply_node_and_deployment || failed+=("apply_node_and_deployment") | ||
test_port_forward "${name}" "8888" || failed+=("port_forward_${name}_default_forward") | ||
test_port_forward "${name}" "8001" || failed+=("port_forward_${name}_target_forward") | ||
test_port_forward "${name}" "8002" || failed+=("port_forward_${name}_command_forward") | ||
test_delete_cluster "${release}" "${name}" || failed+=("delete_cluster_${name}") | ||
done | ||
|
||
if [[ "${#failed[@]}" -ne 0 ]]; then | ||
echo "------------------------------" | ||
echo "Error: Some tests failed" | ||
for test in "${failed[@]}"; do | ||
echo " - ${test}" | ||
done | ||
exit 1 | ||
fi | ||
} | ||
|
||
args "$@" | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
kind: ClusterPortForward | ||
apiVersion: kwok.x-k8s.io/v1alpha1 | ||
metadata: | ||
name: cluster-port-forward-rules | ||
spec: | ||
forwards: | ||
# match the port 8001 forwards to the targetAddress:targetPort | ||
- ports: | ||
- 8001 | ||
targetPort: 10247 | ||
targetAddress: localhost | ||
|
||
# # match the port 8002 forwards with the stdin/stdout of nc | ||
- ports: | ||
- 8002 | ||
command: | ||
- nc | ||
- localhost | ||
- "10247" | ||
|
||
- targetPort: 10247 | ||
targetAddress: localhost |