Skip to content

Commit

Permalink
adding createnamespace param for helm workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
audrastump committed Jan 6, 2025
1 parent e6f555e commit f85633d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 }}
1 change: 1 addition & 0 deletions pkg/handlers/templatetests/workflows_github_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }}
Expand Down Expand Up @@ -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)
Expand All @@ -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

This comment has been minimized.

Copy link
@nwnt

nwnt Jan 6, 2025

Instead of separate if steps, each checking env.CREATE_NAMESPACE, can we do the following:

if : // remove && env.CREATE_NAMESPACE != 'false'
env:
  CREATE_NAMESPACE: ${{ env.CREATE_NAMESPACE}} // to create the bash env var from github action var
run: |
  if [ ${CREATE_NAMESPACE}='true' ]; then
    CREATE_NAMESPACE='--create-namespace'
  else
    CREATE_NAMESPACE=''
  fi
  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 }} ${CREATE_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 }}
`}}

1 comment on commit f85633d

@nwnt
Copy link

@nwnt nwnt commented on f85633d Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the parameter to this file too.

Please sign in to comment.