-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[patch] Fix add_labels postsync for routes (#213)
- Loading branch information
Showing
4 changed files
with
207 additions
and
2 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
186 changes: 186 additions & 0 deletions
186
instance-applications/220-ibm-mas-workspace/templates/05-postsync-add-label_Job.yaml
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,186 @@ | ||
{{- if .Values.ingress }} | ||
|
||
{{ $job_label := "mas-ws-route-patch" }} | ||
--- | ||
# Permit outbound communication by the Job pods | ||
# (Needed to communicate with the K8S HTTP API and AWS SM) | ||
kind: NetworkPolicy | ||
apiVersion: networking.k8s.io/v1 | ||
metadata: | ||
name: mas-ws-route-np | ||
namespace: mas-{{ .Values.instance_id }}-core | ||
annotations: | ||
argocd.argoproj.io/sync-wave: "221" | ||
argocd.argoproj.io/hook: PostSync | ||
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation | ||
{{- if .Values.custom_labels }} | ||
labels: | ||
{{ .Values.custom_labels | toYaml | indent 4 }} | ||
{{- end }} | ||
spec: | ||
podSelector: | ||
matchLabels: | ||
app: {{ $job_label }} | ||
egress: | ||
- {} | ||
policyTypes: | ||
- Egress | ||
|
||
|
||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: mas-ws-route-sa | ||
namespace: mas-{{ .Values.instance_id }}-core | ||
annotations: | ||
argocd.argoproj.io/sync-wave: "221" | ||
argocd.argoproj.io/hook: PostSync | ||
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation | ||
{{- if .Values.custom_labels }} | ||
labels: | ||
{{ .Values.custom_labels | toYaml | indent 4 }} | ||
{{- end }} | ||
|
||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: mas-ws-route-prereq-role-{{ .Values.instance_id }} | ||
namespace: mas-{{ .Values.instance_id }}-core | ||
annotations: | ||
argocd.argoproj.io/sync-wave: "221" | ||
argocd.argoproj.io/hook: PostSync | ||
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation | ||
{{- if .Values.custom_labels }} | ||
labels: | ||
{{ .Values.custom_labels | toYaml | indent 4 }} | ||
{{- end }} | ||
rules: | ||
- verbs: | ||
- get | ||
- list | ||
- patch | ||
apiGroups: | ||
- "route.openshift.io" | ||
resources: | ||
- routes | ||
- verbs: | ||
- get | ||
- list | ||
apiGroups: | ||
- core.mas.ibm.com | ||
resources: | ||
- workspaces | ||
|
||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: mas-ws-route-prereq-rb-{{ .Values.instance_id }} | ||
namespace: mas-{{ .Values.instance_id }}-core | ||
annotations: | ||
argocd.argoproj.io/sync-wave: "222" | ||
argocd.argoproj.io/hook: PostSync | ||
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation | ||
{{- if .Values.custom_labels }} | ||
labels: | ||
{{ .Values.custom_labels | toYaml | indent 4 }} | ||
{{- end }} | ||
subjects: | ||
- kind: ServiceAccount | ||
name: mas-ws-route-sa | ||
namespace: mas-{{ .Values.instance_id }}-core | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: mas-ws-route-prereq-role-{{ .Values.instance_id }} | ||
|
||
--- | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: "mas-ws-route-patch-v1-{{ .Values | toYaml | adler32sum }}" | ||
namespace: mas-{{ .Values.instance_id }}-core | ||
annotations: | ||
argocd.argoproj.io/sync-wave: "223" | ||
argocd.argoproj.io/hook: PostSync | ||
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation | ||
{{- if .Values.custom_labels }} | ||
labels: | ||
{{ .Values.custom_labels | toYaml | indent 4 }} | ||
{{- end }} | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ $job_label }} | ||
{{- if .Values.custom_labels }} | ||
{{ .Values.custom_labels | toYaml | indent 8 }} | ||
{{- end }} | ||
spec: | ||
containers: | ||
- name: run | ||
image: quay.io/ibmmas/cli:latest | ||
imagePullPolicy: IfNotPresent | ||
resources: | ||
limits: | ||
cpu: 200m | ||
memory: 512Mi | ||
requests: | ||
cpu: 10m | ||
memory: 64Mi | ||
env: | ||
- name: SUITE_NAMESPACE | ||
value: mas-{{ .Values.instance_id }}-core | ||
command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
set -e | ||
echo | ||
echo "================================================================================" | ||
echo "Wait for Suite Workspace Routes to be ready and add label type=external to routes" | ||
echo "================================================================================" | ||
echo | ||
echo "Wait for Suite Workspace Routes to be ready" | ||
wait_period=0 | ||
while true; do | ||
wait_period=$(($wait_period+60)) | ||
if [ $wait_period -gt 3600 ]; then | ||
echo "Suite Workspace Routes is not ready after 20 minutes of waiting. exiting..." | ||
exit 1 | ||
else | ||
sleep 60 | ||
fi | ||
SUITE_WORKSPACE_NAME=$(oc get Workspace -n $SUITE_NAMESPACE -o NAME) | ||
echo "SUITE_WORKSPACE_NAME == ${SUITE_WORKSPACE_NAME}" | ||
export READY=$(oc get ${SUITE_WORKSPACE_NAME} -n ${SUITE_NAMESPACE} -o=jsonpath="{.status.conditions[?(@.type=='Ready')].status}") | ||
echo "READY == ${READY}" | ||
if [[ "${READY}" == "True" ]]; then | ||
echo "Suite Workspace Routes are now in ready status" | ||
break | ||
fi | ||
done | ||
export routes=$(oc get routes -n ${SUITE_NAMESPACE} -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}') | ||
echo "Add label to routes updated ${routes}" | ||
for route in $routes; do | ||
echo "Adding label to route - ${route}" | ||
oc patch route/${route} -p '{"metadata":{"labels":{"type":"external"}}}' | ||
done | ||
restartPolicy: Never | ||
serviceAccountName: "mas-ws-route-sa" | ||
backoffLimit: 4 | ||
|
||
{{- end }} | ||
|
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