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

App-serving: update 및 delete 로직 구현 #113

Merged
merged 5 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
130 changes: 130 additions & 0 deletions app_serving/delete-java-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: delete-java-app
namespace: argo
spec:
entrypoint: main
onExit: exit-handler
volumes:
- name: tks-proto-vol
configMap:
name: tks-proto
arguments:
parameters:
- name: target_cluster_id
value: "C011b88fa"
- name: app_name
value: "sample-petclinic"
- name: namespace
value: "{{workflow.parameters.app_name}}"
- name: asa_id
value: ""
- name: asa_task_id
value: ""
- name: tks_info_host
value: "tks-info.tks"

templates:
- name: exit-handler
steps:
- - name: notify-delete-failure
templateRef:
name: update-tks-asa-status
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "DELETE_FAILED"
- name: output
value: "{{workflow.outputs.parameters.delete_output_global}}"
when: "{{workflow.status}} != Succeeded"

- name: main
steps:
- - name: notify-delete-start
templateRef:
name: update-tks-asa-status
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "DELETING"
- name: output
value: ""
- - name: delete-app
template: delete-app
- - name: notify-delete-success
templateRef:
name: update-tks-asa-status
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "DELETE_SUCCESS"
- name: output
value: "{{steps.delete-app.outputs.parameters.delete_output}}"

#######################
# Template Definition #
#######################
- name: delete-app
volumes:
- name: out
emptyDir: {}
outputs:
parameters:
- name: delete_output
valueFrom:
path: /mnt/out/delete_output.log
globalName: delete_output_global
container:
image: 'sktcloud/appserving-worker:latest'
volumeMounts:
- name: out
mountPath: /mnt/out
env:
- name: DOCKERHUB_TOKEN
valueFrom:
secretKeyRef:
name: dockerhub-robert-token
key: TOKEN
robertchoi80 marked this conversation as resolved.
Show resolved Hide resolved
command:
- /bin/sh
- '-exc'
- |
DELETE_LOG='/mnt/out/delete_output.log'

# Prepare kubeconfig
echo "Preparing kubeconfig for target cluster..." | tee -a $DELETE_LOG
KUBECONFIG_=$(kubectl get secret -n {{workflow.parameters.target_cluster_id}} {{workflow.parameters.target_cluster_id}}-kubeconfig -o jsonpath="{.data.value}" | base64 -d)
if [[ -z "$KUBECONFIG_" ]]; then
echo "Couldn't get kubeconfig for cluster {{workflow.parameters.target_cluster_id}}" | tee -a $DELETE_LOG
exit 1
fi

echo "$KUBECONFIG_" > /etc/kubeconfig_temp
chmod 0600 /etc/kubeconfig_temp
export KUBECONFIG='/etc/kubeconfig_temp'

# Deploy
echo "Deleting app \"{{workflow.parameters.app_name}}\"..." | tee -a $DELETE_LOG
# If make this strict, use asa_id as prefix to guarantee uniqueness of helm release.
helm delete --kubeconfig /etc/kubeconfig_temp -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} 2> >(tee -a $DELETE_LOG >&2)
if [[ $? =~ 0 ]]; then
echo "App was deleted successfully."
else
echo "Error occurred while deleting app."
exit 1
fi

# Just for debug
# If there's any case where the release is not deleted normally,
# then extra validation will be required.
helm list --kubeconfig /etc/kubeconfig_temp -n {{workflow.parameters.namespace}}
44 changes: 26 additions & 18 deletions app_serving/serve-java-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ spec:
value: "sample-petclinic"
- name: namespace
value: "{{workflow.parameters.app_name}}"
- name: app_id
- name: asa_id
value: ""
- name: asa_task_id
value: ""
- name: artifact_url
value: "http://github.com/robertchoi80/sample-petclinic/spring-petclinic-2.7.0-SNAPSHOT.jar"
Expand Down Expand Up @@ -67,8 +69,8 @@ spec:
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_id
value: "{{workflow.parameters.app_id}}"
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "BUILD_FAILED"
- name: output
Expand All @@ -80,8 +82,8 @@ spec:
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_id
value: "{{workflow.parameters.app_id}}"
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "DEPLOY_FAILED"
- name: output
Expand All @@ -97,8 +99,8 @@ spec:
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_id
value: "{{workflow.parameters.app_id}}"
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "BUILDING"
- name: output
Expand All @@ -113,8 +115,8 @@ spec:
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_id
value: "{{workflow.parameters.app_id}}"
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "BUILD_SUCCESS"
- name: output
Expand All @@ -126,8 +128,8 @@ spec:
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_id
value: "{{workflow.parameters.app_id}}"
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "DEPLOYING"
- name: output
Expand All @@ -142,8 +144,8 @@ spec:
template: updateTksAsaStatus
arguments:
parameters:
- name: asa_id
value: "{{workflow.parameters.app_id}}"
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: status
value: "DEPLOY_SUCCESS"
- name: output
Expand All @@ -156,7 +158,9 @@ spec:
arguments:
parameters:
- name: asa_id
value: "{{workflow.parameters.app_id}}"
value: "{{workflow.parameters.asa_id}}"
- name: asa_task_id
value: "{{workflow.parameters.asa_task_id}}"
- name: endpoint
value: "{{steps.deploy-app.outputs.parameters.endpoint}}"
- name: helm_revision
Expand Down Expand Up @@ -234,7 +238,7 @@ spec:
echo "=== End of Dockerfile ===" | tee -a $BUILD_LOG

# Give time for the docker daemon to start in sidecar
# TODO: It's better to check docker.sock file with while loop
# TODO: It's better to check docker.sock file with busy-wait loop
sleep 10

echo "Building container image..." | tee -a $BUILD_LOG
Expand Down Expand Up @@ -313,13 +317,14 @@ spec:
fi

echo "$KUBECONFIG_" > /etc/kubeconfig_temp
chmod 0600 /etc/kubeconfig_temp
export KUBECONFIG='/etc/kubeconfig_temp'

# Deploy
echo "Starting deployment..." | tee -a $DEPLOY_LOG
# If make this strict, use asa_id as prefix to guarantee uniqueness of helm release.
kubectl create ns {{workflow.parameters.namespace}} || true
helm install --kubeconfig /etc/kubeconfig_temp -f values-{{workflow.parameters.resource_spec}}.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2)
helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f values-{{workflow.parameters.resource_spec}}.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2)

# Just make sure helm release is deployed before status cmd
sleep 1
Expand All @@ -342,11 +347,10 @@ spec:

kubectl wait --for=condition=Available --timeout=300s -n {{workflow.parameters.namespace}} deploy/{{workflow.parameters.app_name}} 2> >(tee -a $DEPLOY_LOG >&2)


# Check num of replicas
ready=false
SLEEP_INTERVAL=5
for i in {1..12}
for i in `seq 1 15`
do
replicas=$(kubectl get deploy/{{workflow.parameters.app_name}} -n {{workflow.parameters.namespace}} -o jsonpath='{.status.replicas}')
available_repls=$(kubectl get deploy/{{workflow.parameters.app_name}} -n {{workflow.parameters.namespace}} -o jsonpath='{.status.availableReplicas}')
Expand All @@ -360,6 +364,7 @@ spec:
if [ "$replicas" == "$available_repls" ]; then
echo "All replicas are available. Deployment is successful!" | tee -a $DEPLOY_LOG
ready=true
break
fi
sleep $SLEEP_INTERVAL
done
Expand All @@ -374,6 +379,9 @@ spec:
# This msg will be sent to CLI by app-serviing service.
echo "The app <{{workflow.parameters.app_name}}> has been deployed."

# TODO: fix this temp sleep cmd to busy-wait loop
sleep 5

# Writing endpoint to file
kubectl get svc {{workflow.parameters.app_name}} -n {{workflow.parameters.namespace}} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' > /mnt/out/endpoint
echo ":{{workflow.parameters.port}}" >> /mnt/out/endpoint
Expand Down
4 changes: 3 additions & 1 deletion tks_info/update-asa-endpoint-wftpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ spec:
inputs:
parameters:
- name: asa_id
- name: asa_task_id
- name: endpoint
- name: helm_revision
script:
image: sktdev/python-centos-wf-worker:v1.0
command: ["python"]
Expand Down Expand Up @@ -48,5 +50,5 @@ spec:
with grpc.insecure_channel(addr) as channel:
asa_stub = info_pb2_grpc.AppServeAppServiceStub(channel)

res = asa_stub.UpdateAppServeAppEndpoint(info_pb2.UpdateAppServeAppEndpointRequest(app_serve_app_id="{{inputs.parameters.asa_id}}", endpoint="{{inputs.parameters.endpoint}}"))
res = asa_stub.UpdateAppServeAppEndpoint(info_pb2.UpdateAppServeAppEndpointRequest(app_serve_app_id="{{inputs.parameters.asa_id}}", app_serve_app_task_id="{{inputs.parameters.asa_task_id}}", endpoint="{{inputs.parameters.endpoint}}", helm_revision={{inputs.parameters.helm_revision}}))
print("Response code from UpdateAppServeAppEndpoint: %d" % res.code)
4 changes: 2 additions & 2 deletions tks_info/update-asa-status-wftpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
- name: updateTksAsaStatus
inputs:
parameters:
- name: asa_id
- name: asa_task_id
zugwan marked this conversation as resolved.
Show resolved Hide resolved
- name: status
- name: output
script:
Expand Down Expand Up @@ -51,5 +51,5 @@ spec:
with grpc.insecure_channel(addr) as channel:
asa_stub = info_pb2_grpc.AppServeAppServiceStub(channel)

res = asa_stub.UpdateAppServeAppStatus(info_pb2.UpdateAppServeAppStatusRequest(app_serve_app_id="{{inputs.parameters.asa_id}}", status="{{inputs.parameters.status}}", output='''{{inputs.parameters.output}}'''))
res = asa_stub.UpdateAppServeAppStatus(info_pb2.UpdateAppServeAppStatusRequest(app_serve_app_task_id="{{inputs.parameters.asa_task_id}}", status="{{inputs.parameters.status}}", output='''{{inputs.parameters.output}}'''))
print("Response code from UpdateAppServeApp: %d" % res.code)