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

disable auto-sync & add CR deletion #88

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 41 additions & 12 deletions templates/decapod-apps/remove-lma-uniformed-wftpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ spec:
templates:
- name: process
steps:
- - name: disableAutoSyncOfPrometheus
- - name: disableAutoSync
template: disableAutoSync

# Delete prometheus CR first so that it doesn't hang
# Delete CRs first so that it doesn't hang
# due to earlier service-account deletion #
- - name: removePrometheusCR
template: removePrometheusCR
Expand All @@ -31,6 +31,14 @@ spec:
- name: namespace
value: "lma"

# This is for EFK option
- - name: removeFluentbitCR
template: removeFluentbitCR
arguments:
parameters:
- name: namespace
value: "lma"

# Remove argo CD apps
- - name: removeLMA
templateRef:
Expand All @@ -57,20 +65,17 @@ spec:
- /bin/bash
- '-c'
- |
PROM_APP_NAME="prometheus"
if [[ -n "{{workflow.parameters.app_prefix}}" ]]; then
PROM_APP_NAME="{{workflow.parameters.app_prefix}}-prometheus"
fi
echo "[temp] ARGO_SERVER: $ARGO_SERVER"

# Login to Argo CD server
./argocd login $ARGO_SERVER --plaintext --insecure --username $ARGO_USERNAME \
--password $ARGO_PASSWORD

echo "Disabling auto-sync of [$PROM_APP_NAME]' app.."

# Disable auto-sync
./argocd app set $PROM_APP_NAME --sync-policy none
app_list=$(./argocd app list -l {{workflow.parameters.filter}} --output name)
echo -e "app list:\n $app_list"
if [[ $? -eq 0 && -n $app_list ]]; then
# Disable auto-sync
echo "Disabling auto-sync of LMA app_group.."
echo "$app_list" | xargs -I '{}' ./argocd app set '{}' --sync-policy none
fi
envFrom:
- secretRef:
name: "decapod-argocd-config"
Expand Down Expand Up @@ -101,6 +106,30 @@ spec:
kubectl $kube_params delete prometheus --all -n {{inputs.parameters.namespace}}
kubectl $kube_params delete alertmanager --all -n {{inputs.parameters.namespace}}

- name: removeFluentbitCR
inputs:
parameters:
- name: namespace
container:
name: remove-fluentbit-cr
image: k8s.gcr.io/hyperkube:v1.18.6
command:
- /bin/bash
- '-c'
- |
echo "Deleting fluentbit CR..."

kube_params=""

if [[ -n "{{workflow.parameters.cluster_id}}" ]]; then
kube_secret=$(kubectl get secret -n {{workflow.parameters.cluster_id}} {{workflow.parameters.cluster_id}}-kubeconfig -o jsonpath="{.data.value}" | base64 -d)
echo -e "kube_secret:\n$kube_secret" | head -n 5
cat <<< "$kube_secret" > /etc/kubeconfig

kube_params+="--kubeconfig=/etc/kubeconfig"
fi

kubectl $kube_params delete fluentbit --all -n {{inputs.parameters.namespace}} || true

- name: removeLeftoverResources
inputs:
Expand Down
62 changes: 61 additions & 1 deletion templates/decapod-apps/remove-servicemesh-all-wftpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ spec:
#=========================================================
- name: remove-start
steps:
- - name: remove-service-mesh-app
- - name: disableAutoSync
template: disableAutoSync

# Delete CRs first so that it doesn't hang
# due to earlier service-account deletion.
- - name: removeFluentbitCR
template: removeFluentbitCR
arguments:
parameters:
- name: namespace
value: "lma"

- - name: remove-service-mesh-argocd-apps
templateRef:
name: delete-apps
template: DeleteAppsByLabel
Expand All @@ -39,6 +51,54 @@ spec:
#=========================================================
# Template Definition
#=========================================================
- name: disableAutoSync
container:
name: disable-auto-sync
image: docker.io/sktcloud/argocd-cli:v2.2.5
command:
- /bin/bash
- '-c'
- |
# Login to Argo CD server
./argocd login $ARGO_SERVER --plaintext --insecure --username $ARGO_USERNAME \
--password $ARGO_PASSWORD

app_list=$(./argocd app list -l {{workflow.parameters.filter}} --output name)
echo -e "app list:\n $app_list"
if [[ $? -eq 0 && -n $app_list ]]; then
# Disable auto-sync
echo "Disabling auto-sync of service-mesh app_group.."
echo "$app_list" | xargs -I '{}' ./argocd app set '{}' --sync-policy none
fi
envFrom:
- secretRef:
name: "decapod-argocd-config"

- name: removeFluentbitCR
inputs:
parameters:
- name: namespace
container:
name: remove-fluentbit-cr
image: k8s.gcr.io/hyperkube:v1.18.6
command:
- /bin/bash
- '-c'
- |
echo "Deleting fluentbit CR..."

kube_params=""

if [[ -n "{{workflow.parameters.cluster_id}}" ]]; then
kube_secret=$(kubectl get secret -n {{workflow.parameters.cluster_id}} {{workflow.parameters.cluster_id}}-kubeconfig -o jsonpath="{.data.value}" | base64 -d)
echo -e "kube_secret:\n$kube_secret" | head -n 5
cat <<< "$kube_secret" > /etc/kubeconfig

kube_params+="--kubeconfig=/etc/kubeconfig"
fi

kubectl $kube_params delete fluentbit --all -n {{inputs.parameters.namespace}} || true

- name: delete-argocd-app
inputs:
parameters:
Expand Down