Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no persist toggle #932

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tooling/templatize/cmd/pipeline/run/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ func BindOptions(opts *RawRunOptions, cmd *cobra.Command) error {
return fmt.Errorf("failed to bind options: %w", err)
}
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")
return nil
}

type RawRunOptions struct {
PipelineOptions *options.RawPipelineOptions
DryRun bool
NoPersist bool
}

// validatedRunOptions is a private wrapper that enforces a call of Validate() before Complete() can be invoked.
Expand All @@ -46,6 +48,7 @@ type ValidatedRunOptions struct {
type completedRunOptions struct {
PipelineOptions *options.PipelineOptions
DryRun bool
NoPersist bool
}

type RunOptions struct {
Expand Down Expand Up @@ -77,6 +80,7 @@ func (o *ValidatedRunOptions) Complete() (*RunOptions, error) {
completedRunOptions: &completedRunOptions{
PipelineOptions: completed,
DryRun: o.DryRun,
NoPersist: o.NoPersist,
},
}, nil
}
Expand All @@ -102,5 +106,6 @@ func (o *RunOptions) RunPipeline(ctx context.Context) error {
Region: rolloutOptions.Region,
Step: o.PipelineOptions.Step,
SubsciptionLookupFunc: pipeline.LookupSubscriptionID,
NoPersist: o.NoPersist,
})
}
1 change: 1 addition & 0 deletions tooling/templatize/internal/end2end/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (e *e2eImpl) SetOSArgs() {
"--pipeline-file", e.tmpdir + "/pipeline.yaml",
"--config-file", e.tmpdir + "/config.yaml",
"--deploy-env", "dev",
"--no-persist-tag",
"--region", "westus3",
}
}
Expand Down
19 changes: 8 additions & 11 deletions tooling/templatize/pkg/pipeline/arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (a *armClient) runArmStep(ctx context.Context, options *PipelineRunOptions,
}

// Ensure resourcegroup exists
err = a.ensureResourceGroupExists(ctx, rgName)
err = a.ensureResourceGroupExists(ctx, rgName, options.NoPersist)
if err != nil {
return nil, fmt.Errorf("failed to ensure resource group exists: %w", err)
}
Expand Down Expand Up @@ -85,23 +85,20 @@ func (a *armClient) runArmStep(ctx context.Context, options *PipelineRunOptions,
return nil, nil
}

func (a *armClient) ensureResourceGroupExists(ctx context.Context, rgName string) error {
// Create a new Azure identity client
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return fmt.Errorf("failed to obtain a credential: %w", err)
}

func (a *armClient) ensureResourceGroupExists(ctx context.Context, rgName string, rgNoPersist bool) error {
// Create a new ARM client
client, err := armresources.NewResourceGroupsClient(a.SubscriptionID, cred, nil)
client, err := armresources.NewResourceGroupsClient(a.SubscriptionID, a.creds, nil)
if err != nil {
return fmt.Errorf("failed to create ARM client: %w", err)
}

// Check if the resource group exists
// todo fill tags properly
tags := map[string]*string{
"persist": to.Ptr("true"),
tags := map[string]*string{}

if !rgNoPersist {
// if no-persist is set, don't set the persist tag, needs double negotiate, cause default should be true
tags["persist"] = to.Ptr("true")
}
_, err = client.Get(ctx, rgName, nil)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions tooling/templatize/pkg/pipeline/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type PipelineRunOptions struct {
Region string
Vars config.Variables
SubsciptionLookupFunc subsciptionLookup
NoPersist bool
}

type armOutput map[string]any
Expand Down
Loading