4
4
workflow_call :
5
5
inputs :
6
6
cluster-name :
7
- required : true
7
+ required : false
8
8
description : AKS Cluster Name
9
9
type : string
10
10
skr-client-kid :
11
- required : true
11
+ required : false
12
12
description : SKR key id
13
13
default : " default-skr-client-kid"
14
14
type : string
15
+ debug :
16
+ description : " Debug Flag"
17
+ default : false
18
+ required : false
19
+ type : boolean
20
+ test-name :
21
+ description : " Test Name"
22
+ required : true
23
+ type : string
24
+ schedule :
25
+ - cron : " 0 0 * * *"
15
26
16
27
jobs :
28
+ cleanup-running-acis :
29
+ name : Cleanup Running Container Groups
30
+ runs-on : ubuntu-latest
31
+ if : ${{ !inputs.debug }}
32
+ env :
33
+ RESOURCE_GROUP : ${{ vars.RESOURCE_GROUP }}
34
+ steps :
35
+ - name : Log into Azure
36
+ uses : azure/login@v2
37
+ with :
38
+ client-id : ${{ secrets.AZURE_CLIENT_ID }}
39
+ tenant-id : ${{ secrets.AZURE_TENANT_ID }}
40
+ subscription-id : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
41
+
42
+ - name : Delete All Container Groups
43
+ run : |
44
+ RUNNING_CONTAINERS=$(az container list \
45
+ --resource-group $RESOURCE_GROUP \
46
+ --query "[?!starts_with(name, 'uptime-')]")
47
+
48
+ for container in $(echo $RUNNING_CONTAINERS | jq -r '.[].id'); do
49
+ echo "Deleting container group: ${container}"
50
+ az resource delete --ids ${container}
51
+ done
52
+
53
+ cleanup-failed-acis :
54
+ name : Cleanup Failed Container Groups
55
+ runs-on : ubuntu-latest
56
+ if : ${{ !inputs.debug }}
57
+ env :
58
+ RESOURCE_GROUP : ${{ vars.RESOURCE_GROUP }}
59
+ steps :
60
+ - name : Log into Azure
61
+ uses : azure/login@v2
62
+ with :
63
+ client-id : ${{ secrets.AZURE_CLIENT_ID }}
64
+ tenant-id : ${{ secrets.AZURE_TENANT_ID }}
65
+ subscription-id : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
66
+
67
+ - name : Delete Failed Container Groups
68
+ run : |
69
+ NON_RUNNING_CONTAINERS=$(az container list \
70
+ --resource-group $RESOURCE_GROUP \
71
+ --query "[?provisioningState=='Failed' || provisioningState=='Unhealthy']")
72
+
73
+ for container in $(echo $NON_RUNNING_CONTAINERS | jq -r '.[].id'); do
74
+ echo "Deleting container group: ${container}"
75
+ az resource delete --ids ${container}
76
+ done
77
+
17
78
cleanup_registry :
18
79
name : Cleanup Container Registry
19
80
runs-on : ubuntu-latest
@@ -25,23 +86,32 @@ jobs:
25
86
tenant-id : ${{ secrets.AZURE_TENANT_ID }}
26
87
subscription-id : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
27
88
28
- - name : Cleanup Public Azure Container Registry
29
- if : github.event_name != 'pull_request'
89
+ - name : Cleanup Hello World ACI Images
90
+ if : ${{ inputs.test-name == 'hello-world-aci' }}
91
+ run : |
92
+ # adding || true so that it doesn't fail if the image doesn't exist (i.e. helloworld didn't run)
93
+ az acr login --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }}
94
+ az acr repository delete --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/aci/helloworld:${{ github.sha }} --yes || true
95
+
96
+ - name : Cleanup Hello World AKS Images
97
+ if : ${{ inputs.test-name == 'hello-world-aks' }}
30
98
run : |
31
- az acr login --name ${{ secrets.AZURE_REGISTRY_NAME }}
32
- az acr repository delete --name ${{ secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }} --yes
33
- az acr repository delete --name ${{ secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/producer :${{ github.sha }} --yes
99
+ # adding || true so that it doesn't fail if the image doesn't exist (i.e. helloworld didn't run)
100
+ az acr login --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }}
101
+ az acr repository delete --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets. AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/aks/helloworld :${{ github.sha }} --yes || true
34
102
35
- - name : Cleanup Test Azure Container Registry
36
- if : github.event_name == 'pull_request'
103
+ - name : Cleanup Kafka Images
104
+ if : ${{ inputs.test-name == 'kafka' }}
37
105
run : |
38
- az acr login --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }}
39
- az acr repository delete --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }} --yes
40
- az acr repository delete --name ${{ secrets.TEST_AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/producer:${{ github.sha }} --yes
106
+ # adding || true so that it doesn't fail if the image doesn't exist (i.e. kafka didn't run)
107
+ az acr login --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }}
108
+ az acr repository delete --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/consumer:${{ github.sha }} --yes || true
109
+ az acr repository delete --name ${{ github.event_name == 'pull_request' && secrets.TEST_AZURE_REGISTRY_NAME || secrets.AZURE_REGISTRY_NAME }} --image private/${{ github.actor }}/acc/samples/kafka/producer:${{ github.sha }} --yes || true
41
110
42
111
cleanup-cluster :
43
- name : Clean Up
112
+ name : Clean Up Cluster
44
113
runs-on : ubuntu-latest
114
+ if : ${{ inputs.cluster-name != '' }}
45
115
steps :
46
116
- name : Log into Azure
47
117
uses : azure/login@v2
@@ -52,12 +122,12 @@ jobs:
52
122
53
123
- name : Clean Up
54
124
id : cleanup
55
- env :
125
+ env :
56
126
RESOURCE_GROUP : ${{ vars.RESOURCE_GROUP }}
57
127
CLUSTER_NAME : ${{ inputs.cluster-name }}
58
128
SKR_CLIENT_KID : ${{ inputs.skr-client-kid }}
59
- run : |
60
- # cannot rely on the job success/fail indicator to determine whether the SKR_CLIENT_KID exists or not so attempt to delete anyway
129
+ run : |
130
+ # cannot rely on the job success/fail indicator to determine whether the SKR_CLIENT_KID exists or not so attempt to delete anyway
61
131
az keyvault key delete --vault-name kafka-test-pipeline-akv --name $SKR_CLIENT_KID 2>&1 || true
62
132
result=$(az aks list -g $RESOURCE_GROUP --query "[].name" -o tsv)
63
133
0 commit comments