Skip to content

Commit a83da94

Browse files
committed
add option out feature for provision preflight disable
1 parent 36e583d commit a83da94

File tree

14 files changed

+435
-77
lines changed

14 files changed

+435
-77
lines changed

cli/azd/cmd/config.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/azure/azure-dev/cli/azd/pkg/alpha"
2020
"github.com/azure/azure-dev/cli/azd/pkg/config"
2121
"github.com/azure/azure-dev/cli/azd/pkg/input"
22+
"github.com/azure/azure-dev/cli/azd/pkg/optionout"
2223
"github.com/azure/azure-dev/cli/azd/pkg/output"
2324
"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
2425
"github.com/spf13/cobra"
@@ -169,6 +170,16 @@ $ azd config set defaults.location eastus`,
169170
ActionResolver: newConfigListAlphaAction,
170171
})
171172

173+
group.Add("list-option-out", &actions.ActionDescriptorOptions{
174+
Command: &cobra.Command{
175+
Short: "Display the list of available features to option out.",
176+
},
177+
HelpOptions: actions.ActionHelpOptions{
178+
Footer: getCmdListOptionOutHelpFooter,
179+
},
180+
ActionResolver: newConfigListOptionOutAction,
181+
})
182+
172183
return group
173184
}
174185

@@ -454,6 +465,12 @@ type configListAlphaAction struct {
454465
args []string
455466
}
456467

468+
type configListOptionOutAction struct {
469+
optionOutFeaturesManager *optionout.FeatureManager
470+
console input.Console
471+
args []string
472+
}
473+
457474
func (a *configListAlphaAction) Run(ctx context.Context) (*actions.ActionResult, error) {
458475
features, err := a.alphaFeaturesManager.ListFeatures()
459476
if err != nil {
@@ -480,6 +497,32 @@ func (a *configListAlphaAction) Run(ctx context.Context) (*actions.ActionResult,
480497
return nil, nil
481498
}
482499

500+
func (o *configListOptionOutAction) Run(ctx context.Context) (*actions.ActionResult, error) {
501+
features, err := o.optionOutFeaturesManager.ListFeatures()
502+
if err != nil {
503+
return nil, err
504+
}
505+
506+
featureKeys := slices.Sorted(maps.Keys(features))
507+
var optionOutOutput []string
508+
for _, optionOutFeatureKey := range featureKeys {
509+
optionOutFeature := features[optionOutFeatureKey]
510+
optionOutOutput = append(optionOutOutput,
511+
strings.Join(
512+
[]string{
513+
fmt.Sprintf("Name: %s", optionOutFeature.Id),
514+
fmt.Sprintf("Description: %s", optionOutFeature.Description),
515+
fmt.Sprintf("Status: %s", optionOutFeature.Status),
516+
},
517+
"\n",
518+
))
519+
}
520+
o.console.Message(ctx, strings.Join(optionOutOutput, "\n\n"))
521+
522+
// No UX output
523+
return nil, nil
524+
}
525+
483526
func newConfigListAlphaAction(
484527
alphaFeaturesManager *alpha.FeatureManager,
485528
console input.Console,
@@ -491,6 +534,17 @@ func newConfigListAlphaAction(
491534
}
492535
}
493536

537+
func newConfigListOptionOutAction(
538+
optionOutFeaturesManager *optionout.FeatureManager,
539+
console input.Console,
540+
args []string) actions.Action {
541+
return &configListOptionOutAction{
542+
optionOutFeaturesManager: optionOutFeaturesManager,
543+
console: console,
544+
args: args,
545+
}
546+
}
547+
494548
func getCmdListAlphaHelpFooter(*cobra.Command) string {
495549
return generateCmdHelpSamplesBlock(map[string]string{
496550
"Displays a list of all available features in the alpha stage": output.WithHighLightFormat(
@@ -510,3 +564,23 @@ func getCmdListAlphaHelpFooter(*cobra.Command) string {
510564
),
511565
})
512566
}
567+
568+
func getCmdListOptionOutHelpFooter(*cobra.Command) string {
569+
return generateCmdHelpSamplesBlock(map[string]string{
570+
"Displays a list of all available features to option out": output.WithHighLightFormat(
571+
"azd config list-option-out",
572+
),
573+
"Option out a specific feature": output.WithHighLightFormat(
574+
"azd config set optionout.<feature-name> on",
575+
),
576+
"Option in a specific feature": output.WithHighLightFormat(
577+
"azd config set optionout.<feature-name> off",
578+
),
579+
"Option out all optionout features": output.WithHighLightFormat(
580+
"azd config set optionout.all on",
581+
),
582+
"Option in all optionout features": output.WithHighLightFormat(
583+
"azd config set optionout.all off",
584+
),
585+
})
586+
}

cli/azd/cmd/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
"github.com/azure/azure-dev/cli/azd/pkg/kubelogin"
5353
"github.com/azure/azure-dev/cli/azd/pkg/kustomize"
5454
"github.com/azure/azure-dev/cli/azd/pkg/lazy"
55+
"github.com/azure/azure-dev/cli/azd/pkg/optionout"
5556
"github.com/azure/azure-dev/cli/azd/pkg/output"
5657
"github.com/azure/azure-dev/cli/azd/pkg/pipeline"
5758
"github.com/azure/azure-dev/cli/azd/pkg/platform"
@@ -530,6 +531,7 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
530531
})
531532
container.MustRegisterSingleton(repository.NewInitializer)
532533
container.MustRegisterSingleton(alpha.NewFeaturesManager)
534+
container.MustRegisterSingleton(optionout.NewFeaturesManager)
533535
container.MustRegisterSingleton(config.NewUserConfigManager)
534536
container.MustRegisterSingleton(config.NewManager)
535537
container.MustRegisterSingleton(config.NewFileConfigManager)

cli/azd/cmd/down.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (a *downAction) Run(ctx context.Context) (*actions.ActionResult, error) {
106106
}
107107

108108
if a.alphaFeatureManager.IsEnabled(azapi.FeatureDeploymentStacks) {
109-
a.console.WarnForFeature(ctx, azapi.FeatureDeploymentStacks)
109+
a.console.WarnForAlphaFeature(ctx, azapi.FeatureDeploymentStacks)
110110
}
111111

112112
destroyOptions := provisioning.NewDestroyOptions(a.flags.forceDelete, a.flags.purgeDelete)

cli/azd/cmd/infra_synth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (a *infraSynthAction) Run(ctx context.Context) (*actions.ActionResult, erro
9292
)
9393
}
9494

95-
a.console.WarnForFeature(ctx, infraSynthFeature)
95+
a.console.WarnForAlphaFeature(ctx, infraSynthFeature)
9696

9797
spinnerMessage := "Synthesizing infrastructure"
9898

cli/azd/internal/cmd/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (da *DeployAction) Run(ctx context.Context) (*actions.ActionResult, error)
246246
if alphaFeatureId, isAlphaFeature := alpha.IsFeatureKey(string(svc.Host)); isAlphaFeature {
247247
// alpha feature on/off detection for host is done during initialization.
248248
// This is just for displaying the warning during deployment.
249-
da.console.WarnForFeature(ctx, alphaFeatureId)
249+
da.console.WarnForAlphaFeature(ctx, alphaFeatureId)
250250
}
251251

252252
var packageResult *project.ServicePackageResult

cli/azd/internal/cmd/provision.go

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/azure/azure-dev/cli/azd/pkg/environment"
2323
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
2424
"github.com/azure/azure-dev/cli/azd/pkg/input"
25+
"github.com/azure/azure-dev/cli/azd/pkg/optionout"
2526
"github.com/azure/azure-dev/cli/azd/pkg/output"
2627
"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
2728
"github.com/azure/azure-dev/cli/azd/pkg/project"
@@ -98,20 +99,21 @@ func NewProvisionCmd() *cobra.Command {
9899
}
99100

100101
type ProvisionAction struct {
101-
flags *ProvisionFlags
102-
provisionManager *provisioning.Manager
103-
projectManager project.ProjectManager
104-
resourceManager project.ResourceManager
105-
env *environment.Environment
106-
envManager environment.Manager
107-
formatter output.Formatter
108-
projectConfig *project.ProjectConfig
109-
writer io.Writer
110-
console input.Console
111-
subManager *account.SubscriptionsManager
112-
importManager *project.ImportManager
113-
alphaFeatureManager *alpha.FeatureManager
114-
portalUrlBase string
102+
flags *ProvisionFlags
103+
provisionManager *provisioning.Manager
104+
projectManager project.ProjectManager
105+
resourceManager project.ResourceManager
106+
env *environment.Environment
107+
envManager environment.Manager
108+
formatter output.Formatter
109+
projectConfig *project.ProjectConfig
110+
writer io.Writer
111+
console input.Console
112+
subManager *account.SubscriptionsManager
113+
importManager *project.ImportManager
114+
alphaFeatureManager *alpha.FeatureManager
115+
optionOutFeatureManager *optionout.FeatureManager
116+
portalUrlBase string
115117
}
116118

117119
func NewProvisionAction(
@@ -128,23 +130,25 @@ func NewProvisionAction(
128130
writer io.Writer,
129131
subManager *account.SubscriptionsManager,
130132
alphaFeatureManager *alpha.FeatureManager,
133+
optionOutFeatureManager *optionout.FeatureManager,
131134
cloud *cloud.Cloud,
132135
) actions.Action {
133136
return &ProvisionAction{
134-
flags: flags,
135-
provisionManager: provisionManager,
136-
projectManager: projectManager,
137-
resourceManager: resourceManager,
138-
env: env,
139-
envManager: envManager,
140-
formatter: formatter,
141-
projectConfig: projectConfig,
142-
writer: writer,
143-
console: console,
144-
subManager: subManager,
145-
importManager: importManager,
146-
alphaFeatureManager: alphaFeatureManager,
147-
portalUrlBase: cloud.PortalUrlBase,
137+
flags: flags,
138+
provisionManager: provisionManager,
139+
projectManager: projectManager,
140+
resourceManager: resourceManager,
141+
env: env,
142+
envManager: envManager,
143+
formatter: formatter,
144+
projectConfig: projectConfig,
145+
writer: writer,
146+
console: console,
147+
subManager: subManager,
148+
importManager: importManager,
149+
alphaFeatureManager: alphaFeatureManager,
150+
optionOutFeatureManager: optionOutFeatureManager,
151+
portalUrlBase: cloud.PortalUrlBase,
148152
}
149153
}
150154

@@ -246,7 +250,11 @@ func (p *ProvisionAction) Run(ctx context.Context) (*actions.ActionResult, error
246250
}
247251

248252
if p.alphaFeatureManager.IsEnabled(azapi.FeatureDeploymentStacks) {
249-
p.console.WarnForFeature(ctx, azapi.FeatureDeploymentStacks)
253+
p.console.WarnForAlphaFeature(ctx, azapi.FeatureDeploymentStacks)
254+
}
255+
256+
if p.optionOutFeatureManager.IsEnabled(provisioning.AzdProvisionValidationFeatureKey) {
257+
p.console.WarnForOptionOutFeature(ctx, provisioning.AzdProvisionValidationFeatureKey)
250258
}
251259

252260
err = p.projectConfig.Invoke(ctx, project.ProjectEventProvision, projectEventArgs, func() error {

cli/azd/internal/tracing/fields/fields.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ const (
105105
AlphaFeaturesKey = attribute.Key("config.features")
106106
)
107107

108+
// Machine-level configuration related attribute.
109+
const (
110+
// Tracks what option out features are enabled on each command
111+
OptionOutFeaturesKey = attribute.Key("config.features")
112+
)
113+
108114
// Environment related attributes
109115
const (
110116
// Hashed environment name

cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
3737
"github.com/azure/azure-dev/cli/azd/pkg/input"
3838
"github.com/azure/azure-dev/cli/azd/pkg/keyvault"
39+
"github.com/azure/azure-dev/cli/azd/pkg/optionout"
3940
"github.com/azure/azure-dev/cli/azd/pkg/output"
4041
"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
4142
"github.com/azure/azure-dev/cli/azd/pkg/password"
@@ -77,6 +78,7 @@ type BicepProvider struct {
7778
portalUrlBase string
7879
subscriptionManager *account.SubscriptionsManager
7980
azureClient *azapi.AzureClient
81+
optionOutFeatureManager *optionout.FeatureManager
8082
}
8183

8284
// Name gets the name of the infra provider
@@ -611,16 +613,18 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*provisioning.DeployResult,
611613
return nil, err
612614
}
613615

614-
err = p.validatePreflight(
615-
ctx,
616-
bicepDeploymentData.Target,
617-
bicepDeploymentData.CompiledBicep.RawArmTemplate,
618-
bicepDeploymentData.CompiledBicep.Parameters,
619-
deploymentTags,
620-
optionsMap,
621-
)
622-
if err != nil {
623-
return nil, err
616+
if !p.optionOutFeatureManager.IsEnabled(provisioning.AzdProvisionValidationFeatureKey) {
617+
err = p.validatePreflight(
618+
ctx,
619+
bicepDeploymentData.Target,
620+
bicepDeploymentData.CompiledBicep.RawArmTemplate,
621+
bicepDeploymentData.CompiledBicep.Parameters,
622+
deploymentTags,
623+
optionsMap,
624+
)
625+
if err != nil {
626+
return nil, err
627+
}
624628
}
625629

626630
cancelProgress := make(chan bool)
@@ -2164,20 +2168,22 @@ func NewBicepProvider(
21642168
cloud *cloud.Cloud,
21652169
subscriptionManager *account.SubscriptionsManager,
21662170
azureClient *azapi.AzureClient,
2171+
optionOutFeatureManager *optionout.FeatureManager,
21672172
) provisioning.Provider {
21682173
return &BicepProvider{
2169-
envManager: envManager,
2170-
env: env,
2171-
console: console,
2172-
azapi: azapi,
2173-
bicepCli: bicepCli,
2174-
resourceService: resourceService,
2175-
deploymentManager: deploymentManager,
2176-
prompters: prompters,
2177-
curPrincipal: curPrincipal,
2178-
keyvaultService: keyvaultService,
2179-
portalUrlBase: cloud.PortalUrlBase,
2180-
subscriptionManager: subscriptionManager,
2181-
azureClient: azureClient,
2174+
envManager: envManager,
2175+
env: env,
2176+
console: console,
2177+
azapi: azapi,
2178+
bicepCli: bicepCli,
2179+
resourceService: resourceService,
2180+
deploymentManager: deploymentManager,
2181+
prompters: prompters,
2182+
curPrincipal: curPrincipal,
2183+
keyvaultService: keyvaultService,
2184+
portalUrlBase: cloud.PortalUrlBase,
2185+
subscriptionManager: subscriptionManager,
2186+
azureClient: azureClient,
2187+
optionOutFeatureManager: optionOutFeatureManager,
21822188
}
21832189
}

0 commit comments

Comments
 (0)