Skip to content

Commit

Permalink
Admin credentials prepared outside, skip this in templatize
Browse files Browse the repository at this point in the history
  • Loading branch information
janboll committed Dec 20, 2024
1 parent 2ac73e3 commit 6557de3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/services-pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions run_pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
;;
Expand Down Expand Up @@ -122,4 +125,4 @@ $TEMPLATIZE pipeline run \
--stamp=${CXSTAMP} \
--pipeline-file=${PIPELINE} \
--step=${PIPELINE_STEP} \
${DRY_RUN}
${DRY_RUN} ${SKIP_AKS_ADMIN_PROVISION}
23 changes: 14 additions & 9 deletions tooling/templatize/cmd/pipeline/run/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
})
}
24 changes: 14 additions & 10 deletions tooling/templatize/pkg/pipeline/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type PipelineRunOptions struct {
Vars config.Variables
SubsciptionLookupFunc subsciptionLookup
NoPersist bool
SkipAKSAdminProvision bool
}

type armOutput map[string]any
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6557de3

Please sign in to comment.