Skip to content

Commit

Permalink
Merge pull request #14 from sergenyalcin/change-sync-point-to-svc-end…
Browse files Browse the repository at this point in the history
…points

Add a endpoint based sync point after scaling up the pods in import step
  • Loading branch information
sergenyalcin authored May 7, 2024
2 parents c5aeca5 + 701c15b commit ac371c9
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 18 deletions.
27 changes: 27 additions & 0 deletions hack/check_endpoints.sh
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions hack/patch.sh
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 4 additions & 3 deletions internal/templates/02-import.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 20 additions & 15 deletions internal/templates/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`,

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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
`,
},
Expand Down Expand Up @@ -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
`,
},
Expand Down

0 comments on commit ac371c9

Please sign in to comment.