From f85633ded8ba955f10702c31edafafc2b6383c8a Mon Sep 17 00:00:00 2001 From: audrastump Date: Mon, 6 Jan 2025 13:10:10 -0800 Subject: [PATCH] adding createnamespace param for helm workflow --- .../workflows/azure-kubernetes-service-helm.yml | 13 +++++++------ .../templatetests/workflows_github_helm_test.go | 1 + .../workflows/azure-kubernetes-service-helm.yml | 13 +++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/fixtures/workflows/github/helm/.github/workflows/azure-kubernetes-service-helm.yml b/pkg/fixtures/workflows/github/helm/.github/workflows/azure-kubernetes-service-helm.yml index ee8eea28..cc596deb 100644 --- a/pkg/fixtures/workflows/github/helm/.github/workflows/azure-kubernetes-service-helm.yml +++ b/pkg/fixtures/workflows/github/helm/.github/workflows/azure-kubernetes-service-helm.yml @@ -48,6 +48,7 @@ env: CLUSTER_NAME: testCluster CLUSTER_RESOURCE_GROUP: testClusterRG CLUSTER_RESOURCE_TYPE: Microsoft.ContainerService/managedClusters + CREATE_NAMESPACE: true DOCKER_FILE: ./Dockerfile BUILD_CONTEXT_PATH: test CHART_PATH: testPath @@ -121,8 +122,8 @@ jobs: echo "PRIVATE_CLUSTER=$result" >> "$GITHUB_OUTPUT" # Deploys application - - name: Deploy application on private cluster - if: steps.isPrivate.outputs.PRIVATE_CLUSTER == 'true' + - name: Deploy application on private cluster with created namespace + if: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER == 'true' && env.CREATE_NAMESPACE != 'false'}} run: | command_id=$(az aks command invoke --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.CLUSTER_NAME }} --command "helm upgrade --wait -i -f ${{ env.CHART_OVERRIDE_PATH }} --set ${{ env.CHART_OVERRIDES }} --set image.tag=${{ github.sha }} automated-deployment ${{ env.CHART_PATH }} --namespace ${{ env.NAMESPACE }} --create-namespace --timeout 240s" --file . --query id -o tsv) result=$(az aks command result --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.CLUSTER_NAME }} --command-id $command_id) @@ -133,12 +134,12 @@ jobs: exit $exitCode fi - - name: Deploy application on public cluster - if: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER != 'true' && env.CLUSTER_RESOURCE_TYPE != 'Microsoft.ContainerService/fleets' }} + - name: Deploy application on public cluster with created namespace + if: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER != 'true' && env.CREATE_NAMESPACE != 'false'}} run: | helm upgrade --wait -i -f ${{ env.CHART_OVERRIDE_PATH }} --set ${{ env.CHART_OVERRIDES }} --set image.tag=${{ github.sha }} automated-deployment ${{ env.CHART_PATH }} --namespace ${{ env.NAMESPACE }} --create-namespace - - name: Deploy application on fleet hub cluster - if: ${{ env.CLUSTER_RESOURCE_TYPE == 'Microsoft.ContainerService/fleets' }} + - name: Deploy application without creating namespace + if: ${{ env.CREATE_NAMESPACE == 'false' }} run: | helm upgrade -i -f ${{ env.CHART_OVERRIDE_PATH }} --set ${{ env.CHART_OVERRIDES }} --set image.tag=${{ github.sha }} automated-deployment ${{ env.CHART_PATH }} --namespace ${{ env.NAMESPACE }} diff --git a/pkg/handlers/templatetests/workflows_github_helm_test.go b/pkg/handlers/templatetests/workflows_github_helm_test.go index cbec3d3f..5cccd226 100644 --- a/pkg/handlers/templatetests/workflows_github_helm_test.go +++ b/pkg/handlers/templatetests/workflows_github_helm_test.go @@ -24,6 +24,7 @@ func TestGitHubWorkflowHelmTemplates(t *testing.T) { "CLUSTERRESOURCEGROUP": "testClusterRG", "CLUSTERRESOURCETYPE": "Microsoft.ContainerService/managedClusters", "CLUSTERNAME": "testCluster", + "CREATENAMESPACE": "true", "KUSTOMIZEPATH": "./overlays/production", "DEPLOYMENTMANIFESTPATH": "./manifests", "DOCKERFILE": "./Dockerfile", diff --git a/template/workflows/helm/.github/workflows/azure-kubernetes-service-helm.yml b/template/workflows/helm/.github/workflows/azure-kubernetes-service-helm.yml index 48e9affc..ad6c324d 100644 --- a/template/workflows/helm/.github/workflows/azure-kubernetes-service-helm.yml +++ b/template/workflows/helm/.github/workflows/azure-kubernetes-service-helm.yml @@ -48,6 +48,7 @@ env: CLUSTER_NAME: {{ .Config.GetVariableValue "CLUSTERNAME" }} CLUSTER_RESOURCE_GROUP: {{ .Config.GetVariableValue "CLUSTERRESOURCEGROUP" }} CLUSTER_RESOURCE_TYPE: {{ .Config.GetVariableValue "CLUSTERRESOURCETYPE" }} + CREATE_NAMESPACE: {{ .Config.GetVariableValue "CREATENAMESPACE" }} DOCKER_FILE: {{ .Config.GetVariableValue "DOCKERFILE" }} BUILD_CONTEXT_PATH: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} CHART_PATH: {{ .Config.GetVariableValue "CHARTPATH" }} @@ -121,8 +122,8 @@ jobs: echo "PRIVATE_CLUSTER=$result" >> "$GITHUB_OUTPUT" # Deploys application - - name: Deploy application on private cluster - if: steps.isPrivate.outputs.PRIVATE_CLUSTER == 'true' + - name: Deploy application on private cluster with created namespace + if: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER == 'true' && env.CREATE_NAMESPACE != 'false'}} run: | command_id=$(az aks command invoke --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.CLUSTER_NAME }} --command "helm upgrade --wait -i -f ${{ env.CHART_OVERRIDE_PATH }} --set ${{ env.CHART_OVERRIDES }} --set image.tag=${{ github.sha }} automated-deployment ${{ env.CHART_PATH }} --namespace ${{ env.NAMESPACE }} --create-namespace --timeout 240s" --file . --query id -o tsv) result=$(az aks command result --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.CLUSTER_NAME }} --command-id $command_id) @@ -133,13 +134,13 @@ jobs: exit $exitCode fi - - name: Deploy application on public cluster - if: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER != 'true' && env.CLUSTER_RESOURCE_TYPE != 'Microsoft.ContainerService/fleets' }} + - name: Deploy application on public cluster with created namespace + if: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER != 'true' && env.CREATE_NAMESPACE != 'false'}} run: | helm upgrade --wait -i -f ${{ env.CHART_OVERRIDE_PATH }} --set ${{ env.CHART_OVERRIDES }} --set image.tag=${{ github.sha }} automated-deployment ${{ env.CHART_PATH }} --namespace ${{ env.NAMESPACE }} --create-namespace - - name: Deploy application on fleet hub cluster - if: ${{ env.CLUSTER_RESOURCE_TYPE == 'Microsoft.ContainerService/fleets' }} + - name: Deploy application without creating namespace + if: ${{ env.CREATE_NAMESPACE == 'false' }} run: | helm upgrade -i -f ${{ env.CHART_OVERRIDE_PATH }} --set ${{ env.CHART_OVERRIDES }} --set image.tag=${{ github.sha }} automated-deployment ${{ env.CHART_PATH }} --namespace ${{ env.NAMESPACE }} `}}