From 8de9a9ed05038b03a84d1c28db9f3494651ad0ea Mon Sep 17 00:00:00 2001 From: audrastump Date: Thu, 14 Nov 2024 11:14:13 -0800 Subject: [PATCH 01/15] test workflow --- .github/workflows/integration-linux.yml | 2 -- cmd/generate-workflow.go | 25 ++++++++++++++++--- cmd/setup-gh.go | 18 +++++++++++++ go.mod | 2 +- go.sum | 4 --- pkg/providers/azure.go | 14 +++++++++-- .../workflows/azure-kubernetes-service.yml | 7 ++++++ test/integration/swift/helm.yaml | 4 --- test/integration/swift/kustomize.yaml | 4 --- test/integration/swift/manifest.yaml | 4 --- 10 files changed, 59 insertions(+), 25 deletions(-) diff --git a/.github/workflows/integration-linux.yml b/.github/workflows/integration-linux.yml index 23a3d5d0..16a968c5 100644 --- a/.github/workflows/integration-linux.yml +++ b/.github/workflows/integration-linux.yml @@ -444,8 +444,6 @@ jobs: npm install -g ajv-cli@5.0.0 ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json - run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1 - - name: print manifests - run: cat ./langtest/manifests/* - name: start minikube id: minikube uses: medyagh/setup-minikube@master diff --git a/cmd/generate-workflow.go b/cmd/generate-workflow.go index c47bb0b4..9d7fac2c 100644 --- a/cmd/generate-workflow.go +++ b/cmd/generate-workflow.go @@ -8,16 +8,17 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "github.com/Azure/draft/pkg/cmdhelpers" "github.com/Azure/draft/pkg/handlers" "github.com/Azure/draft/pkg/prompts" "github.com/Azure/draft/pkg/templatewriter" - "github.com/Azure/draft/pkg/cmdhelpers" "github.com/Azure/draft/pkg/templatewriter/writers" ) type generateWorkflowCmd struct { dest string deployType string + fleet string flagVariables []string templateWriter templatewriter.TemplateWriter } @@ -47,6 +48,8 @@ with draft on AKS. This command assumes the 'setup-gh' command has been run prop f.StringVarP(&gwCmd.dest, "destination", "d", currentDirDefaultFlagValue, "specify the path to the project directory") f.StringVarP(&gwCmd.deployType, "deploy-type", "", "", "specify the k8s deployment type (helm, kustomize, manifests)") + f.StringVarP(&gwCmd.fleet, "fleet", "f", "", "specify if this is a fleet deployment (yes, no)") + f.StringArrayVarP(&gwCmd.flagVariables, "variable", "", []string{}, "pass template variables (e.g. --variable CLUSTERNAME=testCluster --variable DOCKERFILE=./Dockerfile)") gwCmd.templateWriter = &writers.LocalFSWriter{} return cmd @@ -60,7 +63,17 @@ func (gwc *generateWorkflowCmd) generateWorkflows() error { var err error flagVariablesMap = flagVariablesToMap(gwc.flagVariables) - + if gwc.fleet == "" { + selection := &promptui.Select{ + Label: "Is this a fleet deployment?", + Items: []string{"yes", "no"}, + } + _, gwc.fleet, err = selection.Run() + if err != nil { + return err + } + } + flagVariablesMap["FLEET"] = gwc.fleet if gwc.deployType == "" { selection := &promptui.Select{ Label: "Select k8s Deployment Type", @@ -82,11 +95,15 @@ func (gwc *generateWorkflowCmd) generateWorkflows() error { } t.Config.VariableMapToDraftConfig(flagVariablesMap) - + for key, value := range t.Config.GetVariableMap() { + fmt.Printf("%s: %s\n", key, value) + } if err = prompts.RunPromptsFromConfigWithSkips(t.Config); err != nil { return err } - + for key, value := range t.Config.GetVariableMap() { + fmt.Printf("%s: %s\n", key, value) + } if err := cmdhelpers.UpdateProductionDeployments(gwc.deployType, gwc.dest, t.Config, gwc.templateWriter); err != nil { return fmt.Errorf("update production deployments: %w", err) } diff --git a/cmd/setup-gh.go b/cmd/setup-gh.go index 8c0fdb44..524497f7 100644 --- a/cmd/setup-gh.go +++ b/cmd/setup-gh.go @@ -102,6 +102,11 @@ func fillSetUpConfig(sc *providers.SetUpCmd) error { if err != nil { return fmt.Errorf("getting subscription ID: %w", err) } + + sc.Fleet = getFleet() + if err != nil { + return fmt.Errorf("getting fleet: %w", err) + } } else { sc.SubscriptionID = getSubscriptionID() } @@ -248,6 +253,19 @@ func getAzSubscriptionId(subLabels []providers.SubLabel, currentSub providers.Su return subLabel.ID, nil } +func getFleet() string { + selection := &promptui.Select{ + Label: "Is this for a fleet deployment?", + Items: []string{"Yes", "No"}, + } + _, selectResponse, err := selection.Run() + if err != nil { + return err.Error() + } + + return selectResponse +} + func init() { rootCmd.AddCommand(newSetUpCmd()) } diff --git a/go.mod b/go.mod index 8d8493e0..860cae8c 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,6 @@ require ( github.com/stretchr/testify v1.9.0 github.com/yannh/kubeconform v0.6.7 go.uber.org/mock v0.4.0 - golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f golang.org/x/mod v0.20.0 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 @@ -142,6 +141,7 @@ require ( go.opentelemetry.io/proto/otlp v1.0.0 // indirect go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect golang.org/x/crypto v0.28.0 // indirect + golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect golang.org/x/net v0.30.0 // indirect golang.org/x/oauth2 v0.19.0 // indirect golang.org/x/sync v0.8.0 // indirect diff --git a/go.sum b/go.sum index 2c32cd87..dd0aab19 100644 --- a/go.sum +++ b/go.sum @@ -507,8 +507,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -544,8 +542,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= diff --git a/pkg/providers/azure.go b/pkg/providers/azure.go index dfc2a8e4..65efbb42 100644 --- a/pkg/providers/azure.go +++ b/pkg/providers/azure.go @@ -28,6 +28,7 @@ type SetUpCmd struct { tenantId string appObjectId string spObjectId string + Fleet string AzClient AzClient } @@ -43,6 +44,7 @@ func InitiateAzureOIDCFlow(ctx context.Context, sc *SetUpCmd, s spinner.Spinner) } if AzAppExists(sc.AppName) { + log.Debug(sc.AppName) return errors.New("app already exists") } else if err := sc.createAzApp(); err != nil { return err @@ -165,7 +167,6 @@ func (sc *SetUpCmd) CreateServicePrincipal() error { } func (sc *SetUpCmd) assignSpRole(ctx context.Context) error { - log.Debug("Assigning contributor role to service principal...") roleAssignClient, err := createRoleAssignmentClient(sc.SubscriptionID) if err != nil { @@ -174,7 +175,16 @@ func (sc *SetUpCmd) assignSpRole(ctx context.Context) error { scope := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s", sc.SubscriptionID, sc.ResourceGroupName) objectID := sc.spObjectId - roleId := "b24988ac-6180-42a0-ab88-20f7382dd24c" // Contributor role ID + var roleId string + if sc.Fleet == "Yes" { + log.Debug("Assigning Azure Kubernetes Fleet Manager RBAC Writer role to service principal...") + roleId = "5af6afb3-c06c-4fa4-8848-71a8aee05683" // Azure Kubernetes Fleet Manager RBAC Writer + + } else { + log.Debug("Assigning contributor role to service principal...") + roleId = "b24988ac-6180-42a0-ab88-20f7382dd24c" // Contributor role ID + + } raUid := uuid.New().String() fullAssignmentId := fmt.Sprintf("/%s/providers/Microsoft.Authorization/roleAssignments/%s", scope, raUid) diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index 7e425e79..7e4ee877 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -47,6 +47,7 @@ env: DOCKER_FILE: {{ .Config.GetVariableValue "DOCKERFILE" }} BUILD_CONTEXT_PATH: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} NAMESPACE: {{ .Config.GetVariableValue "NAMESPACE" }} + FLEET: {{ .Config.GetVariableValue "FLEET" }} {{` jobs: buildImage: @@ -94,9 +95,15 @@ jobs: uses: azure/use-kubelogin@v1 with: kubelogin-version: 'v0.0.25' + # Retrieves fleet credentials + - name: Get fleet credentials + if: env.FLEET == 'yes' + run: | + az fleet get-credentials -g ${{ env.CLUSTER_RESOURCE_GROUP }} -n ${{ env.CLUSTER_NAME }} # Retrieves your Azure Kubernetes Service cluster's kubeconfig file - name: Get K8s context + if: env.FLEET != 'yes' uses: azure/aks-set-context@v3 with: resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} diff --git a/test/integration/swift/helm.yaml b/test/integration/swift/helm.yaml index c750d8be..eecb1c58 100644 --- a/test/integration/swift/helm.yaml +++ b/test/integration/swift/helm.yaml @@ -10,10 +10,6 @@ deployVariables: value: "testapp" - name: "IMAGENAME" value: "host.minikube.internal:5001/testapp" - - name: "CPULIMIT" - value: "3" - - name: "MEMLIMIT" - value: "2Gi" languageVariables: - name: "VERSION" value: "5.5" diff --git a/test/integration/swift/kustomize.yaml b/test/integration/swift/kustomize.yaml index e03493e8..254bbb98 100644 --- a/test/integration/swift/kustomize.yaml +++ b/test/integration/swift/kustomize.yaml @@ -10,10 +10,6 @@ deployVariables: value: "testapp" - name: "IMAGENAME" value: "host.minikube.internal:5001/testapp" - - name: "CPULIMIT" - value: "3" - - name: "MEMLIMIT" - value: "2Gi" languageVariables: - name: "VERSION" value: "5.5" diff --git a/test/integration/swift/manifest.yaml b/test/integration/swift/manifest.yaml index 1c1a4609..91b7fbdb 100644 --- a/test/integration/swift/manifest.yaml +++ b/test/integration/swift/manifest.yaml @@ -10,10 +10,6 @@ deployVariables: value: "testapp" - name: "IMAGENAME" value: "host.minikube.internal:5001/testapp" - - name: "CPULIMIT" - value: "3" - - name: "MEMLIMIT" - value: "2Gi" languageVariables: - name: "VERSION" value: "5.5" From 3b2f7d95dc2bb80a1f44e6d3f7a4df9055024377 Mon Sep 17 00:00:00 2001 From: audrastump Date: Thu, 14 Nov 2024 14:37:46 -0800 Subject: [PATCH 02/15] Revert file to master --- .../.github/workflows/azure-kubernetes-service.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index 7e4ee877..7e425e79 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -47,7 +47,6 @@ env: DOCKER_FILE: {{ .Config.GetVariableValue "DOCKERFILE" }} BUILD_CONTEXT_PATH: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} NAMESPACE: {{ .Config.GetVariableValue "NAMESPACE" }} - FLEET: {{ .Config.GetVariableValue "FLEET" }} {{` jobs: buildImage: @@ -95,15 +94,9 @@ jobs: uses: azure/use-kubelogin@v1 with: kubelogin-version: 'v0.0.25' - # Retrieves fleet credentials - - name: Get fleet credentials - if: env.FLEET == 'yes' - run: | - az fleet get-credentials -g ${{ env.CLUSTER_RESOURCE_GROUP }} -n ${{ env.CLUSTER_NAME }} # Retrieves your Azure Kubernetes Service cluster's kubeconfig file - name: Get K8s context - if: env.FLEET != 'yes' uses: azure/aks-set-context@v3 with: resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} From c3b33a7effaada306e83db96ae2e97ba3fa87a21 Mon Sep 17 00:00:00 2001 From: audrastump Date: Thu, 14 Nov 2024 15:08:24 -0800 Subject: [PATCH 03/15] cleaned up --- cmd/generate-workflow.go | 14 +------------ cmd/setup-gh.go | 17 --------------- pkg/providers/azure.go | 21 +++++++++---------- .../workflows/azure-kubernetes-service.yml | 20 +++++++++++++++++- template/workflows/manifests/draft.yaml | 14 +++++++++++++ 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/cmd/generate-workflow.go b/cmd/generate-workflow.go index 9d7fac2c..06970421 100644 --- a/cmd/generate-workflow.go +++ b/cmd/generate-workflow.go @@ -18,7 +18,6 @@ import ( type generateWorkflowCmd struct { dest string deployType string - fleet string flagVariables []string templateWriter templatewriter.TemplateWriter } @@ -48,7 +47,6 @@ with draft on AKS. This command assumes the 'setup-gh' command has been run prop f.StringVarP(&gwCmd.dest, "destination", "d", currentDirDefaultFlagValue, "specify the path to the project directory") f.StringVarP(&gwCmd.deployType, "deploy-type", "", "", "specify the k8s deployment type (helm, kustomize, manifests)") - f.StringVarP(&gwCmd.fleet, "fleet", "f", "", "specify if this is a fleet deployment (yes, no)") f.StringArrayVarP(&gwCmd.flagVariables, "variable", "", []string{}, "pass template variables (e.g. --variable CLUSTERNAME=testCluster --variable DOCKERFILE=./Dockerfile)") gwCmd.templateWriter = &writers.LocalFSWriter{} @@ -63,17 +61,7 @@ func (gwc *generateWorkflowCmd) generateWorkflows() error { var err error flagVariablesMap = flagVariablesToMap(gwc.flagVariables) - if gwc.fleet == "" { - selection := &promptui.Select{ - Label: "Is this a fleet deployment?", - Items: []string{"yes", "no"}, - } - _, gwc.fleet, err = selection.Run() - if err != nil { - return err - } - } - flagVariablesMap["FLEET"] = gwc.fleet + if gwc.deployType == "" { selection := &promptui.Select{ Label: "Select k8s Deployment Type", diff --git a/cmd/setup-gh.go b/cmd/setup-gh.go index 524497f7..30130a27 100644 --- a/cmd/setup-gh.go +++ b/cmd/setup-gh.go @@ -103,10 +103,6 @@ func fillSetUpConfig(sc *providers.SetUpCmd) error { return fmt.Errorf("getting subscription ID: %w", err) } - sc.Fleet = getFleet() - if err != nil { - return fmt.Errorf("getting fleet: %w", err) - } } else { sc.SubscriptionID = getSubscriptionID() } @@ -253,19 +249,6 @@ func getAzSubscriptionId(subLabels []providers.SubLabel, currentSub providers.Su return subLabel.ID, nil } -func getFleet() string { - selection := &promptui.Select{ - Label: "Is this for a fleet deployment?", - Items: []string{"Yes", "No"}, - } - _, selectResponse, err := selection.Run() - if err != nil { - return err.Error() - } - - return selectResponse -} - func init() { rootCmd.AddCommand(newSetUpCmd()) } diff --git a/pkg/providers/azure.go b/pkg/providers/azure.go index 65efbb42..156cd927 100644 --- a/pkg/providers/azure.go +++ b/pkg/providers/azure.go @@ -167,7 +167,17 @@ func (sc *SetUpCmd) CreateServicePrincipal() error { } func (sc *SetUpCmd) assignSpRole(ctx context.Context) error { + if err := sc.assignRole(ctx, "b24988ac-6180-42a0-ab88-20f7382dd24c"); err != nil { // Contributor role ID + return err + } + if err := sc.assignRole(ctx, "5af6afb3-c06c-4fa4-8848-71a8aee05683"); err != nil { // Azure Kubernetes Fleet Manager RBAC Writer role ID + return err + } + log.Debug("Roles assigned successfully!") + return nil +} +func (sc *SetUpCmd) assignRole(ctx context.Context, roleId string) error { roleAssignClient, err := createRoleAssignmentClient(sc.SubscriptionID) if err != nil { return fmt.Errorf("creating role assignment client: %w", err) @@ -175,16 +185,6 @@ func (sc *SetUpCmd) assignSpRole(ctx context.Context) error { scope := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s", sc.SubscriptionID, sc.ResourceGroupName) objectID := sc.spObjectId - var roleId string - if sc.Fleet == "Yes" { - log.Debug("Assigning Azure Kubernetes Fleet Manager RBAC Writer role to service principal...") - roleId = "5af6afb3-c06c-4fa4-8848-71a8aee05683" // Azure Kubernetes Fleet Manager RBAC Writer - - } else { - log.Debug("Assigning contributor role to service principal...") - roleId = "b24988ac-6180-42a0-ab88-20f7382dd24c" // Contributor role ID - - } raUid := uuid.New().String() fullAssignmentId := fmt.Sprintf("/%s/providers/Microsoft.Authorization/roleAssignments/%s", scope, raUid) @@ -204,7 +204,6 @@ func (sc *SetUpCmd) assignSpRole(ctx context.Context) error { return fmt.Errorf("creating role assignment: %w", err) } - log.Debug("Role assigned successfully!") return nil } diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index 7e425e79..46a80839 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -47,6 +47,8 @@ env: DOCKER_FILE: {{ .Config.GetVariableValue "DOCKERFILE" }} BUILD_CONTEXT_PATH: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} NAMESPACE: {{ .Config.GetVariableValue "NAMESPACE" }} + FLEET: {{ .Config.GetVariableValue "FLEET" }} + FLEET_NAME: {{ .Config.GetVariableValue "FLEET_NAME" }} {{` jobs: buildImage: @@ -78,7 +80,7 @@ jobs: runs-on: ubuntu-latest needs: [buildImage] steps: - # Checks out the repository this file is in + # Checks out the reposcditory this file is in - uses: actions/checkout@v3 # Logs in with your Azure credentials @@ -95,8 +97,17 @@ jobs: with: kubelogin-version: 'v0.0.25' + # gets credentials for a fleet + - name: Get fleet credentials + if: env.FLEET == 'true' + run: | + az fleet get-credentials -g ${{ env.CLUSTER_RESOURCE_GROUP }} -n ${{ env.FLEET_NAME }} + export KUBECONFIG=/home/runner/.kube/config + echo "KUBECONFIG=/home/runner/.kube/config" >> $GITHUB_ENV + # Retrieves your Azure Kubernetes Service cluster's kubeconfig file - name: Get K8s context + if: env.FLEET != 'true' uses: azure/aks-set-context@v3 with: resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} @@ -106,6 +117,7 @@ jobs: # Checks if the AKS cluster is private - name: Is private cluster + if: env.FLEET != 'true' id: isPrivate run: | result=$(az aks show --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.CLUSTER_NAME }} --query "apiServerAccessProfile.enablePrivateCluster") @@ -113,6 +125,7 @@ jobs: # Deploys application based on given manifest file - name: Deploys application + if: env.FLEET != 'true' uses: Azure/k8s-deploy@v4 with: action: deploy @@ -123,4 +136,9 @@ jobs: name: ${{ env.CLUSTER_NAME }} private-cluster: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER == 'true' }} namespace: ${{ env.NAMESPACE }} + - name: Deploys fleet application + if: env.FLEET == 'true' + run: | + kubectl config current-context + /usr/bin/kubectl apply --validate=false --request-timeout=60s -f ${{ env.DEPLOYMENT_MANIFEST_PATH }}/configmap.yaml,${{ env.DEPLOYMENT_MANIFEST_PATH }}/deployment.yaml,${{ env.DEPLOYMENT_MANIFEST_PATH }}/service.yaml --namespace ${{ env.NAMESPACE }} `}} \ No newline at end of file diff --git a/template/workflows/manifests/draft.yaml b/template/workflows/manifests/draft.yaml index c7dac3ef..e0d19868 100644 --- a/template/workflows/manifests/draft.yaml +++ b/template/workflows/manifests/draft.yaml @@ -70,3 +70,17 @@ variables: value: "default" description: "the Kubernetes namespace" versions: ">=0.0.1" + - name: "FLEET" + type: "boolean" + kind: "boolean" + default: + value: false + description: "specifies whether or not this is a fleet deployment" + versions: ">=0.0.1" + - name: "FLEET_NAME" + type: "string" + kind: "fleetName" + default: + value: "" + description: "name of the fleet to to deploy to, leave blank for no fleet" + versions: ">=0.0.1" From 67fc3a1a3f9fee36a133b3237f2c0560af9af1ac Mon Sep 17 00:00:00 2001 From: audrastump Date: Thu, 14 Nov 2024 15:19:38 -0800 Subject: [PATCH 04/15] more cleaning --- cmd/generate-workflow.go | 7 ------- cmd/setup-gh.go | 1 - pkg/providers/azure.go | 1 - .../.github/workflows/azure-kubernetes-service.yml | 2 +- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/cmd/generate-workflow.go b/cmd/generate-workflow.go index 06970421..24fea243 100644 --- a/cmd/generate-workflow.go +++ b/cmd/generate-workflow.go @@ -47,7 +47,6 @@ with draft on AKS. This command assumes the 'setup-gh' command has been run prop f.StringVarP(&gwCmd.dest, "destination", "d", currentDirDefaultFlagValue, "specify the path to the project directory") f.StringVarP(&gwCmd.deployType, "deploy-type", "", "", "specify the k8s deployment type (helm, kustomize, manifests)") - f.StringArrayVarP(&gwCmd.flagVariables, "variable", "", []string{}, "pass template variables (e.g. --variable CLUSTERNAME=testCluster --variable DOCKERFILE=./Dockerfile)") gwCmd.templateWriter = &writers.LocalFSWriter{} return cmd @@ -83,15 +82,9 @@ func (gwc *generateWorkflowCmd) generateWorkflows() error { } t.Config.VariableMapToDraftConfig(flagVariablesMap) - for key, value := range t.Config.GetVariableMap() { - fmt.Printf("%s: %s\n", key, value) - } if err = prompts.RunPromptsFromConfigWithSkips(t.Config); err != nil { return err } - for key, value := range t.Config.GetVariableMap() { - fmt.Printf("%s: %s\n", key, value) - } if err := cmdhelpers.UpdateProductionDeployments(gwc.deployType, gwc.dest, t.Config, gwc.templateWriter); err != nil { return fmt.Errorf("update production deployments: %w", err) } diff --git a/cmd/setup-gh.go b/cmd/setup-gh.go index 30130a27..8c0fdb44 100644 --- a/cmd/setup-gh.go +++ b/cmd/setup-gh.go @@ -102,7 +102,6 @@ func fillSetUpConfig(sc *providers.SetUpCmd) error { if err != nil { return fmt.Errorf("getting subscription ID: %w", err) } - } else { sc.SubscriptionID = getSubscriptionID() } diff --git a/pkg/providers/azure.go b/pkg/providers/azure.go index 156cd927..8b0d0842 100644 --- a/pkg/providers/azure.go +++ b/pkg/providers/azure.go @@ -44,7 +44,6 @@ func InitiateAzureOIDCFlow(ctx context.Context, sc *SetUpCmd, s spinner.Spinner) } if AzAppExists(sc.AppName) { - log.Debug(sc.AppName) return errors.New("app already exists") } else if err := sc.createAzApp(); err != nil { return err diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index 46a80839..1e413d1c 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -80,7 +80,7 @@ jobs: runs-on: ubuntu-latest needs: [buildImage] steps: - # Checks out the reposcditory this file is in + # Checks out the repository this file is in - uses: actions/checkout@v3 # Logs in with your Azure credentials From 1d7f034e15265d9ae1102888088f13607e78be80 Mon Sep 17 00:00:00 2001 From: Audra Stump <71152145+audrastump@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:24:11 -0800 Subject: [PATCH 05/15] Update generate-workflow.go --- cmd/generate-workflow.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/generate-workflow.go b/cmd/generate-workflow.go index 24fea243..949d8d76 100644 --- a/cmd/generate-workflow.go +++ b/cmd/generate-workflow.go @@ -8,10 +8,10 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/Azure/draft/pkg/cmdhelpers" "github.com/Azure/draft/pkg/handlers" "github.com/Azure/draft/pkg/prompts" "github.com/Azure/draft/pkg/templatewriter" + "github.com/Azure/draft/pkg/cmdhelpers" "github.com/Azure/draft/pkg/templatewriter/writers" ) @@ -82,9 +82,11 @@ func (gwc *generateWorkflowCmd) generateWorkflows() error { } t.Config.VariableMapToDraftConfig(flagVariablesMap) + if err = prompts.RunPromptsFromConfigWithSkips(t.Config); err != nil { return err } + if err := cmdhelpers.UpdateProductionDeployments(gwc.deployType, gwc.dest, t.Config, gwc.templateWriter); err != nil { return fmt.Errorf("update production deployments: %w", err) } From 28fdd7b9590fdb18c6189b677f164aeebe9b74b9 Mon Sep 17 00:00:00 2001 From: audrastump Date: Thu, 14 Nov 2024 15:26:08 -0800 Subject: [PATCH 06/15] revert changes --- cmd/generate-workflow.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/generate-workflow.go b/cmd/generate-workflow.go index 949d8d76..c47bb0b4 100644 --- a/cmd/generate-workflow.go +++ b/cmd/generate-workflow.go @@ -82,11 +82,11 @@ func (gwc *generateWorkflowCmd) generateWorkflows() error { } t.Config.VariableMapToDraftConfig(flagVariablesMap) - + if err = prompts.RunPromptsFromConfigWithSkips(t.Config); err != nil { return err } - + if err := cmdhelpers.UpdateProductionDeployments(gwc.deployType, gwc.dest, t.Config, gwc.templateWriter); err != nil { return fmt.Errorf("update production deployments: %w", err) } From 4ee7be7125b321b950bd4293e0eca4f9ba540632 Mon Sep 17 00:00:00 2001 From: audrastump Date: Thu, 14 Nov 2024 15:48:32 -0800 Subject: [PATCH 07/15] removed unnecessary changes --- .github/workflows/integration-linux.yml | 2 ++ test/integration/swift/helm.yaml | 4 ++++ test/integration/swift/kustomize.yaml | 4 ++++ test/integration/swift/manifest.yaml | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/.github/workflows/integration-linux.yml b/.github/workflows/integration-linux.yml index 16a968c5..23a3d5d0 100644 --- a/.github/workflows/integration-linux.yml +++ b/.github/workflows/integration-linux.yml @@ -444,6 +444,8 @@ jobs: npm install -g ajv-cli@5.0.0 ajv validate -s test/update_dry_run_schema.json -d test/temp/update_dry_run.json - run: ./draft -v update -d ./langtest/ -a webapp_routing --variable ingress-tls-cert-keyvault-uri=test.cert.keyvault.uri --variable ingress-use-osm-mtls=true --variable ingress-host=host1 + - name: print manifests + run: cat ./langtest/manifests/* - name: start minikube id: minikube uses: medyagh/setup-minikube@master diff --git a/test/integration/swift/helm.yaml b/test/integration/swift/helm.yaml index eecb1c58..c750d8be 100644 --- a/test/integration/swift/helm.yaml +++ b/test/integration/swift/helm.yaml @@ -10,6 +10,10 @@ deployVariables: value: "testapp" - name: "IMAGENAME" value: "host.minikube.internal:5001/testapp" + - name: "CPULIMIT" + value: "3" + - name: "MEMLIMIT" + value: "2Gi" languageVariables: - name: "VERSION" value: "5.5" diff --git a/test/integration/swift/kustomize.yaml b/test/integration/swift/kustomize.yaml index 254bbb98..e03493e8 100644 --- a/test/integration/swift/kustomize.yaml +++ b/test/integration/swift/kustomize.yaml @@ -10,6 +10,10 @@ deployVariables: value: "testapp" - name: "IMAGENAME" value: "host.minikube.internal:5001/testapp" + - name: "CPULIMIT" + value: "3" + - name: "MEMLIMIT" + value: "2Gi" languageVariables: - name: "VERSION" value: "5.5" diff --git a/test/integration/swift/manifest.yaml b/test/integration/swift/manifest.yaml index 91b7fbdb..1c1a4609 100644 --- a/test/integration/swift/manifest.yaml +++ b/test/integration/swift/manifest.yaml @@ -10,6 +10,10 @@ deployVariables: value: "testapp" - name: "IMAGENAME" value: "host.minikube.internal:5001/testapp" + - name: "CPULIMIT" + value: "3" + - name: "MEMLIMIT" + value: "2Gi" languageVariables: - name: "VERSION" value: "5.5" From 994553863b7748405928e32e9e42679d2b9aca74 Mon Sep 17 00:00:00 2001 From: audrastump Date: Mon, 18 Nov 2024 11:12:19 -0800 Subject: [PATCH 08/15] removed kubeconfig env --- .../.github/workflows/azure-kubernetes-service.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index 1e413d1c..869c1488 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -47,7 +47,6 @@ env: DOCKER_FILE: {{ .Config.GetVariableValue "DOCKERFILE" }} BUILD_CONTEXT_PATH: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} NAMESPACE: {{ .Config.GetVariableValue "NAMESPACE" }} - FLEET: {{ .Config.GetVariableValue "FLEET" }} FLEET_NAME: {{ .Config.GetVariableValue "FLEET_NAME" }} {{` jobs: @@ -99,15 +98,14 @@ jobs: # gets credentials for a fleet - name: Get fleet credentials - if: env.FLEET == 'true' + if: ${{ env.FLEET_NAME != '' }} run: | az fleet get-credentials -g ${{ env.CLUSTER_RESOURCE_GROUP }} -n ${{ env.FLEET_NAME }} - export KUBECONFIG=/home/runner/.kube/config echo "KUBECONFIG=/home/runner/.kube/config" >> $GITHUB_ENV # Retrieves your Azure Kubernetes Service cluster's kubeconfig file - name: Get K8s context - if: env.FLEET != 'true' + if: ${{ env.FLEET_NAME == '' }} uses: azure/aks-set-context@v3 with: resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} @@ -117,7 +115,7 @@ jobs: # Checks if the AKS cluster is private - name: Is private cluster - if: env.FLEET != 'true' + if: ${{ env.FLEET_NAME == '' }} id: isPrivate run: | result=$(az aks show --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.CLUSTER_NAME }} --query "apiServerAccessProfile.enablePrivateCluster") @@ -125,7 +123,7 @@ jobs: # Deploys application based on given manifest file - name: Deploys application - if: env.FLEET != 'true' + if: ${{ env.FLEET_NAME == '' }} uses: Azure/k8s-deploy@v4 with: action: deploy @@ -137,7 +135,7 @@ jobs: private-cluster: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER == 'true' }} namespace: ${{ env.NAMESPACE }} - name: Deploys fleet application - if: env.FLEET == 'true' + if: ${{ env.FLEET_NAME != '' }} run: | kubectl config current-context /usr/bin/kubectl apply --validate=false --request-timeout=60s -f ${{ env.DEPLOYMENT_MANIFEST_PATH }}/configmap.yaml,${{ env.DEPLOYMENT_MANIFEST_PATH }}/deployment.yaml,${{ env.DEPLOYMENT_MANIFEST_PATH }}/service.yaml --namespace ${{ env.NAMESPACE }} From c3059bf39c9bc375bdc7cf1f195bcf792324d136 Mon Sep 17 00:00:00 2001 From: audrastump Date: Mon, 18 Nov 2024 11:20:51 -0800 Subject: [PATCH 09/15] updated --- cmd/setup-gh.go | 1 + pkg/providers/azure.go | 16 +++++++++------- .../workflows/azure-kubernetes-service.yml | 2 +- template/workflows/manifests/draft.yaml | 9 +-------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cmd/setup-gh.go b/cmd/setup-gh.go index 8c0fdb44..b8e77921 100644 --- a/cmd/setup-gh.go +++ b/cmd/setup-gh.go @@ -77,6 +77,7 @@ application and service principle, and will configure that application to trust f.StringVarP(&sc.SubscriptionID, "subscription-id", "s", emptyDefaultFlagValue, "specify the Azure subscription ID") f.StringVarP(&sc.ResourceGroupName, "resource-group", "r", emptyDefaultFlagValue, "specify the Azure resource group name") f.StringVarP(&sc.Repo, "gh-repo", "g", emptyDefaultFlagValue, "specify the github repository link") + sc.Provider = provider return cmd } diff --git a/pkg/providers/azure.go b/pkg/providers/azure.go index 8b0d0842..b1be5e93 100644 --- a/pkg/providers/azure.go +++ b/pkg/providers/azure.go @@ -28,7 +28,6 @@ type SetUpCmd struct { tenantId string appObjectId string spObjectId string - Fleet string AzClient AzClient } @@ -61,7 +60,7 @@ func InitiateAzureOIDCFlow(ctx context.Context, sc *SetUpCmd, s spinner.Spinner) return err } - if err := sc.assignSpRole(ctx); err != nil { + if err := sc.assignSpRoles(ctx); err != nil { return err } @@ -165,12 +164,15 @@ func (sc *SetUpCmd) CreateServicePrincipal() error { return nil } -func (sc *SetUpCmd) assignSpRole(ctx context.Context) error { - if err := sc.assignRole(ctx, "b24988ac-6180-42a0-ab88-20f7382dd24c"); err != nil { // Contributor role ID - return err +func (sc *SetUpCmd) assignSpRoles(ctx context.Context) error { + var spRoles = []string{ + "b24988ac-6180-42a0-ab88-20f7382dd24c", // Contributor role ID + "5af6afb3-c06c-4fa4-8848-71a8aee05683", // Azure Kubernetes Fleet Manager RBAC Writer role ID } - if err := sc.assignRole(ctx, "5af6afb3-c06c-4fa4-8848-71a8aee05683"); err != nil { // Azure Kubernetes Fleet Manager RBAC Writer role ID - return err + for _, role := range spRoles { + if err := sc.assignRole(ctx, role); err != nil { + return err + } } log.Debug("Roles assigned successfully!") return nil diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index 869c1488..2d1c41cd 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -47,7 +47,7 @@ env: DOCKER_FILE: {{ .Config.GetVariableValue "DOCKERFILE" }} BUILD_CONTEXT_PATH: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} NAMESPACE: {{ .Config.GetVariableValue "NAMESPACE" }} - FLEET_NAME: {{ .Config.GetVariableValue "FLEET_NAME" }} + FLEET_NAME: {{ .Config.GetVariableValue "FLEETNAME" }} {{` jobs: buildImage: diff --git a/template/workflows/manifests/draft.yaml b/template/workflows/manifests/draft.yaml index e0d19868..b8fe737d 100644 --- a/template/workflows/manifests/draft.yaml +++ b/template/workflows/manifests/draft.yaml @@ -70,14 +70,7 @@ variables: value: "default" description: "the Kubernetes namespace" versions: ">=0.0.1" - - name: "FLEET" - type: "boolean" - kind: "boolean" - default: - value: false - description: "specifies whether or not this is a fleet deployment" - versions: ">=0.0.1" - - name: "FLEET_NAME" + - name: "FLEETNAME" type: "string" kind: "fleetName" default: From d8b247f6676f9c86a0d057576516eb870cc205cc Mon Sep 17 00:00:00 2001 From: audrastump Date: Mon, 18 Nov 2024 11:24:51 -0800 Subject: [PATCH 10/15] tidied yaml file --- .../manifests/.github/workflows/azure-kubernetes-service.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index 2d1c41cd..d97d52c0 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -101,7 +101,6 @@ jobs: if: ${{ env.FLEET_NAME != '' }} run: | az fleet get-credentials -g ${{ env.CLUSTER_RESOURCE_GROUP }} -n ${{ env.FLEET_NAME }} - echo "KUBECONFIG=/home/runner/.kube/config" >> $GITHUB_ENV # Retrieves your Azure Kubernetes Service cluster's kubeconfig file - name: Get K8s context From c023901a506588066311d2ae1701e219a9593f30 Mon Sep 17 00:00:00 2001 From: Audra Stump <71152145+audrastump@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:25:32 -0800 Subject: [PATCH 11/15] Update setup-gh.go --- cmd/setup-gh.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/setup-gh.go b/cmd/setup-gh.go index b8e77921..8c0fdb44 100644 --- a/cmd/setup-gh.go +++ b/cmd/setup-gh.go @@ -77,7 +77,6 @@ application and service principle, and will configure that application to trust f.StringVarP(&sc.SubscriptionID, "subscription-id", "s", emptyDefaultFlagValue, "specify the Azure subscription ID") f.StringVarP(&sc.ResourceGroupName, "resource-group", "r", emptyDefaultFlagValue, "specify the Azure resource group name") f.StringVarP(&sc.Repo, "gh-repo", "g", emptyDefaultFlagValue, "specify the github repository link") - sc.Provider = provider return cmd } From 01888bf80666059bfa2001500c39b360f38b80a3 Mon Sep 17 00:00:00 2001 From: audrastump Date: Tue, 19 Nov 2024 11:49:59 -0800 Subject: [PATCH 12/15] made changes in wf helpers --- pkg/cmdhelpers/workflow_helpers.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/cmdhelpers/workflow_helpers.go b/pkg/cmdhelpers/workflow_helpers.go index 0c06f25a..1fd9db55 100644 --- a/pkg/cmdhelpers/workflow_helpers.go +++ b/pkg/cmdhelpers/workflow_helpers.go @@ -6,6 +6,7 @@ import ( "io/fs" "os" "path" + "strings" "gopkg.in/yaml.v3" appsv1 "k8s.io/api/apps/v1" @@ -162,7 +163,17 @@ func (w *Workflows) CreateWorkflowFiles(deployType string, draftConfig *config.D srcDir := path.Join(parentDirName, val.Name()) log.Debugf("source directory for workflow template: %s", srcDir) + for _, variable := range draftConfig.Variables { + if variable.Name == "aksResourceID" && strings.Contains(variable.Value, "Microsoft.ContainerService/fleets") { + parts := strings.Split(variable.Value, "/") + for i, part := range parts { + if part == "fleets" && i+1 < len(parts) { + draftConfig.SetVariable("FLEETNAME", parts[i+1]) + } + } + } + } if err := draftConfig.ApplyDefaultVariables(); err != nil { return fmt.Errorf("create workflow files: %w", err) } From d6ffeb203bb947dea39a0c3b33c9d7e66b42550f Mon Sep 17 00:00:00 2001 From: audrastump Date: Wed, 20 Nov 2024 14:05:58 -0800 Subject: [PATCH 13/15] test devhub integration --- pkg/cmdhelpers/workflow_helpers.go | 11 -------- .../workflows/azure-kubernetes-service.yml | 27 ++++++++++--------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/pkg/cmdhelpers/workflow_helpers.go b/pkg/cmdhelpers/workflow_helpers.go index 1fd9db55..0c06f25a 100644 --- a/pkg/cmdhelpers/workflow_helpers.go +++ b/pkg/cmdhelpers/workflow_helpers.go @@ -6,7 +6,6 @@ import ( "io/fs" "os" "path" - "strings" "gopkg.in/yaml.v3" appsv1 "k8s.io/api/apps/v1" @@ -163,17 +162,7 @@ func (w *Workflows) CreateWorkflowFiles(deployType string, draftConfig *config.D srcDir := path.Join(parentDirName, val.Name()) log.Debugf("source directory for workflow template: %s", srcDir) - for _, variable := range draftConfig.Variables { - if variable.Name == "aksResourceID" && strings.Contains(variable.Value, "Microsoft.ContainerService/fleets") { - parts := strings.Split(variable.Value, "/") - for i, part := range parts { - if part == "fleets" && i+1 < len(parts) { - draftConfig.SetVariable("FLEETNAME", parts[i+1]) - } - } - } - } if err := draftConfig.ApplyDefaultVariables(); err != nil { return fmt.Errorf("create workflow files: %w", err) } diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index d97d52c0..f028e777 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -19,13 +19,13 @@ # - ACR_RESOURCE_GROUP (resource group of your ACR) # - AZURE_CONTAINER_REGISTRY (name of your container registry / ACR) # - CLUSTER_RESOURCE_GROUP (where your cluster is deployed) -# - CLUSTER_NAME (name of your AKS cluster) # - CONTAINER_NAME (name of the container image you would like to push up to your ACR) # - DEPLOYMENT_MANIFEST_PATH (path to the manifest yaml for your deployment) # - DOCKER_FILE (path to your Dockerfile) # - BUILD_CONTEXT_PATH (path to the context of your Dockerfile) # - NAMESPACE (namespace to deploy your application) -# +# - RESOURCE_TYPE (type of resource to deploy to, either 'fleet' or 'managed cluster') +# - RESOURCE_NAME (name of the resource to deploy to - fleet name or managed cluster name) # For more information on GitHub Actions for Azure, refer to https://github.com/Azure/Actions # For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples # For more options with the actions used below please refer to https://github.com/Azure/login @@ -42,12 +42,13 @@ env: AZURE_CONTAINER_REGISTRY: {{ .Config.GetVariableValue "AZURECONTAINERREGISTRY" }} CONTAINER_NAME: {{ .Config.GetVariableValue "CONTAINERNAME" }} CLUSTER_RESOURCE_GROUP: {{ .Config.GetVariableValue "CLUSTERRESOURCEGROUP" }} - CLUSTER_NAME: {{ .Config.GetVariableValue "CLUSTERNAME" }} DEPLOYMENT_MANIFEST_PATH: {{ .Config.GetVariableValue "DEPLOYMENTMANIFESTPATH" }} DOCKER_FILE: {{ .Config.GetVariableValue "DOCKERFILE" }} BUILD_CONTEXT_PATH: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} NAMESPACE: {{ .Config.GetVariableValue "NAMESPACE" }} - FLEET_NAME: {{ .Config.GetVariableValue "FLEETNAME" }} + RESOURCE_TYPE: { { .Config.GetVariableValue "RESOURCETYPE" } } + RESOURCE_NAME: {{ .Config.GetVariableValue "RESOURCENAME" }} + {{` jobs: buildImage: @@ -98,31 +99,31 @@ jobs: # gets credentials for a fleet - name: Get fleet credentials - if: ${{ env.FLEET_NAME != '' }} + if: ${{ env.RESOURCE_TYPE != 'fleet' }} run: | - az fleet get-credentials -g ${{ env.CLUSTER_RESOURCE_GROUP }} -n ${{ env.FLEET_NAME }} + az fleet get-credentials -g ${{ env.CLUSTER_RESOURCE_GROUP }} -n ${{ env.RESOURCE_NAME }} # Retrieves your Azure Kubernetes Service cluster's kubeconfig file - name: Get K8s context - if: ${{ env.FLEET_NAME == '' }} + if: ${{ env.RESOURCE_NAME == 'fleet' }} uses: azure/aks-set-context@v3 with: resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} - cluster-name: ${{ env.CLUSTER_NAME }} + cluster-name: ${{ env.RESOURCE_NAME }} admin: 'false' use-kubelogin: 'true' # Checks if the AKS cluster is private - name: Is private cluster - if: ${{ env.FLEET_NAME == '' }} + if: ${{ env.RESOURCE_TYPE == 'fleet' }} id: isPrivate run: | - result=$(az aks show --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.CLUSTER_NAME }} --query "apiServerAccessProfile.enablePrivateCluster") + result=$(az aks show --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.RESOURCE_NAME }} --query "apiServerAccessProfile.enablePrivateCluster") echo "PRIVATE_CLUSTER=$result" >> "$GITHUB_OUTPUT" # Deploys application based on given manifest file - name: Deploys application - if: ${{ env.FLEET_NAME == '' }} + if: ${{ env.RESOURCE_TYPE == 'fleet' }} uses: Azure/k8s-deploy@v4 with: action: deploy @@ -130,11 +131,11 @@ jobs: images: | ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} - name: ${{ env.CLUSTER_NAME }} + name: ${{ env.RESOURCE_NAME }} private-cluster: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER == 'true' }} namespace: ${{ env.NAMESPACE }} - name: Deploys fleet application - if: ${{ env.FLEET_NAME != '' }} + if: ${{ env.RESOURCE_TYPE != 'fleet' }} run: | kubectl config current-context /usr/bin/kubectl apply --validate=false --request-timeout=60s -f ${{ env.DEPLOYMENT_MANIFEST_PATH }}/configmap.yaml,${{ env.DEPLOYMENT_MANIFEST_PATH }}/deployment.yaml,${{ env.DEPLOYMENT_MANIFEST_PATH }}/service.yaml --namespace ${{ env.NAMESPACE }} From 3c36c79093bb3a39444b6fe64684efdd873e146b Mon Sep 17 00:00:00 2001 From: audrastump Date: Wed, 20 Nov 2024 15:24:23 -0800 Subject: [PATCH 14/15] removed fleet input --- template/workflows/manifests/draft.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/template/workflows/manifests/draft.yaml b/template/workflows/manifests/draft.yaml index b8fe737d..c7dac3ef 100644 --- a/template/workflows/manifests/draft.yaml +++ b/template/workflows/manifests/draft.yaml @@ -70,10 +70,3 @@ variables: value: "default" description: "the Kubernetes namespace" versions: ">=0.0.1" - - name: "FLEETNAME" - type: "string" - kind: "fleetName" - default: - value: "" - description: "name of the fleet to to deploy to, leave blank for no fleet" - versions: ">=0.0.1" From 430b471947346984a1306d0d155f5cba92afd279 Mon Sep 17 00:00:00 2001 From: audrastump Date: Tue, 26 Nov 2024 16:00:17 -0800 Subject: [PATCH 15/15] added resource type changes, deployment changes based on devhub --- .../workflows/azure-kubernetes-service.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml index f028e777..f1e05734 100644 --- a/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml +++ b/template/workflows/manifests/.github/workflows/azure-kubernetes-service.yml @@ -46,7 +46,7 @@ env: DOCKER_FILE: {{ .Config.GetVariableValue "DOCKERFILE" }} BUILD_CONTEXT_PATH: {{ .Config.GetVariableValue "BUILDCONTEXTPATH" }} NAMESPACE: {{ .Config.GetVariableValue "NAMESPACE" }} - RESOURCE_TYPE: { { .Config.GetVariableValue "RESOURCETYPE" } } + RESOURCE_TYPE: {{ .Config.GetVariableValue "RESOURCETYPE" }} RESOURCE_NAME: {{ .Config.GetVariableValue "RESOURCENAME" }} {{` @@ -99,13 +99,13 @@ jobs: # gets credentials for a fleet - name: Get fleet credentials - if: ${{ env.RESOURCE_TYPE != 'fleet' }} + if: ${{ env.RESOURCE_TYPE == 'fleets' }} run: | az fleet get-credentials -g ${{ env.CLUSTER_RESOURCE_GROUP }} -n ${{ env.RESOURCE_NAME }} # Retrieves your Azure Kubernetes Service cluster's kubeconfig file - name: Get K8s context - if: ${{ env.RESOURCE_NAME == 'fleet' }} + if: ${{ env.RESOURCE_TYPE != 'fleets' }} uses: azure/aks-set-context@v3 with: resource-group: ${{ env.CLUSTER_RESOURCE_GROUP }} @@ -115,7 +115,7 @@ jobs: # Checks if the AKS cluster is private - name: Is private cluster - if: ${{ env.RESOURCE_TYPE == 'fleet' }} + if: ${{ env.RESOURCE_TYPE != 'fleets' }} id: isPrivate run: | result=$(az aks show --resource-group ${{ env.CLUSTER_RESOURCE_GROUP }} --name ${{ env.RESOURCE_NAME }} --query "apiServerAccessProfile.enablePrivateCluster") @@ -123,7 +123,7 @@ jobs: # Deploys application based on given manifest file - name: Deploys application - if: ${{ env.RESOURCE_TYPE == 'fleet' }} + if: ${{ env.RESOURCE_TYPE != 'fleets' }} uses: Azure/k8s-deploy@v4 with: action: deploy @@ -135,8 +135,10 @@ jobs: private-cluster: ${{ steps.isPrivate.outputs.PRIVATE_CLUSTER == 'true' }} namespace: ${{ env.NAMESPACE }} - name: Deploys fleet application - if: ${{ env.RESOURCE_TYPE != 'fleet' }} + if: ${{ env.RESOURCE_TYPE == 'fleets' }} run: | kubectl config current-context - /usr/bin/kubectl apply --validate=false --request-timeout=60s -f ${{ env.DEPLOYMENT_MANIFEST_PATH }}/configmap.yaml,${{ env.DEPLOYMENT_MANIFEST_PATH }}/deployment.yaml,${{ env.DEPLOYMENT_MANIFEST_PATH }}/service.yaml --namespace ${{ env.NAMESPACE }} + for manifest in $(echo "${{ env.DEPLOYMENT_MANIFEST_PATH }}" | tr '\n' ' '); do + /usr/bin/kubectl apply --validate=false --request-timeout=60s -f ./$manifest --namespace ${{ env.NAMESPACE }} + done `}} \ No newline at end of file