From 6557de397b7ae929f8ba68fb3e13c97af3d1b09f Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Boll Date: Fri, 20 Dec 2024 10:16:24 +0100 Subject: [PATCH] Admin credentials prepared outside, skip this in templatize --- .github/workflows/services-pr-check.yml | 2 +- run_pipeline.sh | 7 ++++-- .../templatize/cmd/pipeline/run/options.go | 23 +++++++++++------- tooling/templatize/pkg/pipeline/run.go | 24 +++++++++++-------- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/.github/workflows/services-pr-check.yml b/.github/workflows/services-pr-check.yml index 4f47e950e..6fcef4eb5 100644 --- a/.github/workflows/services-pr-check.yml +++ b/.github/workflows/services-pr-check.yml @@ -78,4 +78,4 @@ - name: 'Deploy Frontend' run: | - ./run_pipeline.sh dev ./frontend/pipeline.yaml deploy -c public -d + ./run_pipeline.sh dev ./frontend/pipeline.yaml deploy -c public -d -a diff --git a/run_pipeline.sh b/run_pipeline.sh index b0354dd48..375e43d30 100755 --- a/run_pipeline.sh +++ b/run_pipeline.sh @@ -45,8 +45,11 @@ fi # Parse optional flags -while getopts "c:dr:x:e:i:o:p:s:" opt; do +while getopts "ac:dr:x:e:i:o:p:s:" opt; do case ${opt} in + a) + SKIP_AKS_ADMIN_PROVISION="--skip-aks-admin-provision" + ;; c) CLOUD=${OPTARG} ;; @@ -122,4 +125,4 @@ $TEMPLATIZE pipeline run \ --stamp=${CXSTAMP} \ --pipeline-file=${PIPELINE} \ --step=${PIPELINE_STEP} \ - ${DRY_RUN} \ No newline at end of file + ${DRY_RUN} ${SKIP_AKS_ADMIN_PROVISION} \ No newline at end of file diff --git a/tooling/templatize/cmd/pipeline/run/options.go b/tooling/templatize/cmd/pipeline/run/options.go index b9669c59d..21341a5a1 100644 --- a/tooling/templatize/cmd/pipeline/run/options.go +++ b/tooling/templatize/cmd/pipeline/run/options.go @@ -24,13 +24,15 @@ func BindOptions(opts *RawRunOptions, cmd *cobra.Command) error { } cmd.Flags().BoolVar(&opts.DryRun, "dry-run", opts.DryRun, "validate the pipeline without executing it") cmd.Flags().BoolVar(&opts.NoPersist, "no-persist-tag", opts.NoPersist, "toggle if persist tag should not be set") + cmd.Flags().BoolVar(&opts.SkipAKSAdminProvision, "skip-aks-admin-provision", opts.SkipAKSAdminProvision, "do not provision the AKS admin") return nil } type RawRunOptions struct { - PipelineOptions *options.RawPipelineOptions - DryRun bool - NoPersist bool + PipelineOptions *options.RawPipelineOptions + DryRun bool + NoPersist bool + SkipAKSAdminProvision bool } // validatedRunOptions is a private wrapper that enforces a call of Validate() before Complete() can be invoked. @@ -46,9 +48,10 @@ type ValidatedRunOptions struct { // completedRunOptions is a private wrapper that enforces a call of Complete() before config generation can be invoked. type completedRunOptions struct { - PipelineOptions *options.PipelineOptions - DryRun bool - NoPersist bool + PipelineOptions *options.PipelineOptions + DryRun bool + NoPersist bool + SkipAKSAdminProvision bool } type RunOptions struct { @@ -78,9 +81,10 @@ func (o *ValidatedRunOptions) Complete() (*RunOptions, error) { return &RunOptions{ completedRunOptions: &completedRunOptions{ - PipelineOptions: completed, - DryRun: o.DryRun, - NoPersist: o.NoPersist, + PipelineOptions: completed, + DryRun: o.DryRun, + NoPersist: o.NoPersist, + SkipAKSAdminProvision: o.SkipAKSAdminProvision, }, }, nil } @@ -107,5 +111,6 @@ func (o *RunOptions) RunPipeline(ctx context.Context) error { Step: o.PipelineOptions.Step, SubsciptionLookupFunc: pipeline.LookupSubscriptionID, NoPersist: o.NoPersist, + SkipAKSAdminProvision: o.SkipAKSAdminProvision, }) } diff --git a/tooling/templatize/pkg/pipeline/run.go b/tooling/templatize/pkg/pipeline/run.go index 279e4e682..f205fa171 100644 --- a/tooling/templatize/pkg/pipeline/run.go +++ b/tooling/templatize/pkg/pipeline/run.go @@ -45,6 +45,7 @@ type PipelineRunOptions struct { Vars config.Variables SubsciptionLookupFunc subsciptionLookup NoPersist bool + SkipAKSAdminProvision bool } type armOutput map[string]any @@ -120,16 +121,19 @@ func RunPipeline(pipeline *Pipeline, ctx context.Context, options *PipelineRunOp func RunResourceGroup(rg *ResourceGroup, ctx context.Context, options *PipelineRunOptions, executionTarget ExecutionTarget, outputs map[string]output) error { logger := logr.FromContextOrDiscard(ctx) - - kubeconfigFile, err := executionTarget.KubeConfig(ctx) - if kubeconfigFile != "" { - defer func() { - if err := os.Remove(kubeconfigFile); err != nil { - logger.V(5).Error(err, "failed to delete kubeconfig file", "kubeconfig", kubeconfigFile) - } - }() - } else if err != nil { - return fmt.Errorf("failed to prepare kubeconfig: %w", err) + var kubeconfigFile string + + if !options.SkipAKSAdminProvision { + kubeconfigFile, err := executionTarget.KubeConfig(ctx) + if kubeconfigFile != "" { + defer func() { + if err := os.Remove(kubeconfigFile); err != nil { + logger.V(5).Error(err, "failed to delete kubeconfig file", "kubeconfig", kubeconfigFile) + } + }() + } else if err != nil { + return fmt.Errorf("failed to prepare kubeconfig: %w", err) + } } for _, step := range rg.Steps {