diff --git a/hack/check_endpoints.sh b/hack/check_endpoints.sh new file mode 100755 index 0000000..75f5bde --- /dev/null +++ b/hack/check_endpoints.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +function check_endpoints { + endpoints=( $("${KUBECTL}" -n "${CROSSPLANE_NAMESPACE}" get endpoints --no-headers | grep '^provider-' | awk '{print $1}') ) + for endpoint in ${endpoints[@]}; do + port=$(${KUBECTL} -n "${CROSSPLANE_NAMESPACE}" get endpoints "$endpoint" -o jsonpath='{.subsets[*].ports[0].port}') + if [[ -z "${port}" ]]; then + echo "$endpoint - No served ports" + return 1 + else + echo "$endpoint - Ports present" + fi + done +} + +attempt=1 +max_attempts=10 +while [[ $attempt -le $max_attempts ]]; do + if check_endpoints; then + exit 0 + else + printf "Retrying... (%d/%d)\n" "$attempt" "$max_attempts" >&2 + fi + ((attempt++)) + sleep 5 +done +exit 1 diff --git a/hack/patch.sh b/hack/patch.sh new file mode 100755 index 0000000..6fbc04e --- /dev/null +++ b/hack/patch.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +function patch { + kindgroup=$1; + name=$2; + if ${KUBECTL} --subresource=status patch "$kindgroup/$name" --type=merge -p '{"status":{"conditions":[]}}' ; then + return 0; + else + return 1; + fi; +}; + + +kindgroup=$1; +name=$2; +attempt=1; +max_attempts=10; +while [[ $attempt -le $max_attempts ]]; do + if patch "$kindgroup" "$name"; then + echo "Successfully patched $kindgroup/$name"; + ${KUBECTL} annotate "$kindgroup/$name" uptest-old-id=$(${KUBECTL} get "$kindgroup/$name" -o=jsonpath='{.status.atProvider.id}') --overwrite; + break; + else + printf "Retrying... (%d/%d) for %s/%s\n" "$attempt" "$max_attempts" "$kindgroup" "$name" >&2; + fi; + ((attempt++)); + sleep 5; +done; +if [[ $attempt -gt $max_attempts ]]; then + echo "Failed to patch $kindgroup/$name after $max_attempts attempts"; + exit 1; +fi; +exit 0; diff --git a/internal/templates/02-import.yaml.tmpl b/internal/templates/02-import.yaml.tmpl index 615332a..1fd4392 100644 --- a/internal/templates/02-import.yaml.tmpl +++ b/internal/templates/02-import.yaml.tmpl @@ -8,14 +8,15 @@ commands: - command: sleep 10 - command: ${KUBECTL} scale deployment crossplane -n ${CROSSPLANE_NAMESPACE} --replicas=1 --timeout 10s - script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get deploy --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} scale deploy --replicas=1 -- script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get pods --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} wait pods --for=condition=Ready --timeout=60s +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/check_endpoints.sh -o /tmp/check_endpoints.sh && chmod +x /tmp/check_endpoints.sh +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/patch.sh -o /tmp/patch.sh && chmod +x /tmp/patch.sh +- script: /tmp/check_endpoints.sh {{- range $resource := .Resources }} {{- if eq $resource.KindGroup "secret." -}} {{continue}} {{- end -}} {{- if not $resource.Namespace }} -- command: ${KUBECTL} --subresource=status patch {{ $resource.KindGroup }}/{{ $resource.Name }} --type=merge -p '{"status":{"conditions":[]}}' -- script: ${KUBECTL} annotate {{ $resource.KindGroup }}/{{ $resource.Name }} uptest-old-id=$(${KUBECTL} get {{ $resource.KindGroup }}/{{ $resource.Name }} -o=jsonpath='{.status.atProvider.id}') --overwrite +- script: /tmp/patch.sh {{ $resource.KindGroup }} {{ $resource.Name }} {{- end }} {{- end }} - command: ${KUBECTL} annotate managed --all crossplane.io/paused=false --overwrite diff --git a/internal/templates/renderer_test.go b/internal/templates/renderer_test.go index d7e42fe..5104883 100644 --- a/internal/templates/renderer_test.go +++ b/internal/templates/renderer_test.go @@ -116,9 +116,10 @@ commands: - command: sleep 10 - command: ${KUBECTL} scale deployment crossplane -n ${CROSSPLANE_NAMESPACE} --replicas=1 --timeout 10s - script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get deploy --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} scale deploy --replicas=1 -- script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get pods --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} wait pods --for=condition=Ready --timeout=60s -- command: ${KUBECTL} --subresource=status patch s3.aws.upbound.io/example-bucket --type=merge -p '{"status":{"conditions":[]}}' -- script: ${KUBECTL} annotate s3.aws.upbound.io/example-bucket uptest-old-id=$(${KUBECTL} get s3.aws.upbound.io/example-bucket -o=jsonpath='{.status.atProvider.id}') --overwrite +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/check_endpoints.sh -o /tmp/check_endpoints.sh && chmod +x /tmp/check_endpoints.sh +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/patch.sh -o /tmp/patch.sh && chmod +x /tmp/patch.sh +- script: /tmp/check_endpoints.sh +- script: /tmp/patch.sh s3.aws.upbound.io example-bucket - command: ${KUBECTL} annotate managed --all crossplane.io/paused=false --overwrite `, @@ -227,9 +228,10 @@ commands: - command: sleep 10 - command: ${KUBECTL} scale deployment crossplane -n ${CROSSPLANE_NAMESPACE} --replicas=1 --timeout 10s - script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get deploy --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} scale deploy --replicas=1 -- script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get pods --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} wait pods --for=condition=Ready --timeout=60s -- command: ${KUBECTL} --subresource=status patch s3.aws.upbound.io/example-bucket --type=merge -p '{"status":{"conditions":[]}}' -- script: ${KUBECTL} annotate s3.aws.upbound.io/example-bucket uptest-old-id=$(${KUBECTL} get s3.aws.upbound.io/example-bucket -o=jsonpath='{.status.atProvider.id}') --overwrite +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/check_endpoints.sh -o /tmp/check_endpoints.sh && chmod +x /tmp/check_endpoints.sh +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/patch.sh -o /tmp/patch.sh && chmod +x /tmp/patch.sh +- script: /tmp/check_endpoints.sh +- script: /tmp/patch.sh s3.aws.upbound.io example-bucket - command: ${KUBECTL} annotate managed --all crossplane.io/paused=false --overwrite `, "03-assert.yaml": `# This assert file belongs to the resource delete step. @@ -341,9 +343,10 @@ commands: - command: sleep 10 - command: ${KUBECTL} scale deployment crossplane -n ${CROSSPLANE_NAMESPACE} --replicas=1 --timeout 10s - script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get deploy --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} scale deploy --replicas=1 -- script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get pods --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} wait pods --for=condition=Ready --timeout=60s -- command: ${KUBECTL} --subresource=status patch s3.aws.upbound.io/example-bucket --type=merge -p '{"status":{"conditions":[]}}' -- script: ${KUBECTL} annotate s3.aws.upbound.io/example-bucket uptest-old-id=$(${KUBECTL} get s3.aws.upbound.io/example-bucket -o=jsonpath='{.status.atProvider.id}') --overwrite +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/check_endpoints.sh -o /tmp/check_endpoints.sh && chmod +x /tmp/check_endpoints.sh +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/patch.sh -o /tmp/patch.sh && chmod +x /tmp/patch.sh +- script: /tmp/check_endpoints.sh +- script: /tmp/patch.sh s3.aws.upbound.io example-bucket - command: ${KUBECTL} annotate managed --all crossplane.io/paused=false --overwrite `, }, @@ -435,9 +438,10 @@ commands: - command: sleep 10 - command: ${KUBECTL} scale deployment crossplane -n ${CROSSPLANE_NAMESPACE} --replicas=1 --timeout 10s - script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get deploy --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} scale deploy --replicas=1 -- script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get pods --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} wait pods --for=condition=Ready --timeout=60s -- command: ${KUBECTL} --subresource=status patch s3.aws.upbound.io/example-bucket --type=merge -p '{"status":{"conditions":[]}}' -- script: ${KUBECTL} annotate s3.aws.upbound.io/example-bucket uptest-old-id=$(${KUBECTL} get s3.aws.upbound.io/example-bucket -o=jsonpath='{.status.atProvider.id}') --overwrite +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/check_endpoints.sh -o /tmp/check_endpoints.sh && chmod +x /tmp/check_endpoints.sh +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/patch.sh -o /tmp/patch.sh && chmod +x /tmp/patch.sh +- script: /tmp/check_endpoints.sh +- script: /tmp/patch.sh s3.aws.upbound.io example-bucket - command: ${KUBECTL} annotate managed --all crossplane.io/paused=false --overwrite `, }, @@ -529,9 +533,10 @@ commands: - command: sleep 10 - command: ${KUBECTL} scale deployment crossplane -n ${CROSSPLANE_NAMESPACE} --replicas=1 --timeout 10s - script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get deploy --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} scale deploy --replicas=1 -- script: ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} get pods --no-headers -o custom-columns=":metadata.name" | grep "provider-" | xargs ${KUBECTL} -n ${CROSSPLANE_NAMESPACE} wait pods --for=condition=Ready --timeout=60s -- command: ${KUBECTL} --subresource=status patch s3.aws.upbound.io/example-bucket --type=merge -p '{"status":{"conditions":[]}}' -- script: ${KUBECTL} annotate s3.aws.upbound.io/example-bucket uptest-old-id=$(${KUBECTL} get s3.aws.upbound.io/example-bucket -o=jsonpath='{.status.atProvider.id}') --overwrite +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/check_endpoints.sh -o /tmp/check_endpoints.sh && chmod +x /tmp/check_endpoints.sh +- script: curl -sL https://raw.githubusercontent.com/crossplane/uptest/main/hack/patch.sh -o /tmp/patch.sh && chmod +x /tmp/patch.sh +- script: /tmp/check_endpoints.sh +- script: /tmp/patch.sh s3.aws.upbound.io example-bucket - command: ${KUBECTL} annotate managed --all crossplane.io/paused=false --overwrite `, },