-
Notifications
You must be signed in to change notification settings - Fork 66
fix(kafka create): reduce number of calls made to AMS API #1596
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
136e35d
feat(kafka create): add billing model flag
rkpattnaik780 4daddcb
feat: add logic to pick the quotacost object
rkpattnaik780 2aa6add
fix: change logic to pick up the quota
rkpattnaik780 9affd6d
fix: handle multiple quota cost objects
rkpattnaik780 8263f52
Merge branch 'main' into reduce_ams_calls
wtrocki ec105c8
fix: mod sum
wtrocki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ type options struct { | |
|
|
||
| marketplaceAcctId string | ||
| marketplace string | ||
| billingModel string | ||
|
|
||
| outputFormat string | ||
| autoUse bool | ||
|
|
@@ -93,7 +94,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { | |
| } | ||
| } | ||
|
|
||
| if opts.bypassChecks && (opts.marketplace != "" || opts.marketplaceAcctId != "") { | ||
| if opts.bypassChecks && (opts.marketplace != "" || opts.marketplaceAcctId != "" || opts.billingModel != "") { | ||
| return f.Localizer.MustLocalizeError("kafka.create.error.bypassChecks.marketplace") | ||
| } | ||
|
|
||
|
|
@@ -111,26 +112,6 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { | |
| return flagutil.InvalidValueError("output", opts.outputFormat, validOutputFormats...) | ||
| } | ||
|
|
||
| if !opts.bypassChecks { | ||
| validMarketplaces, err := accountmgmtutil.GetValidMarketplaces(f.Context, f.Connection) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if opts.marketplace != "" && !flagutil.IsValidInput(opts.marketplace, validMarketplaces...) { | ||
| return flagutil.InvalidValueError(FlagMarketPlace, opts.marketplace, validMarketplaces...) | ||
| } | ||
|
|
||
| validMarketplaceAcctIDs, err := accountmgmtutil.GetValidMarketplaceAcctIDs(f.Context, f.Connection, opts.marketplace) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if opts.marketplaceAcctId != "" && !flagutil.IsValidInput(opts.marketplaceAcctId, validMarketplaceAcctIDs...) { | ||
| return flagutil.InvalidValueError(FlagMarketPlaceAcctID, opts.marketplaceAcctId, validMarketplaceAcctIDs...) | ||
| } | ||
| } | ||
|
|
||
| return runCreate(opts) | ||
| }, | ||
| } | ||
|
|
@@ -147,6 +128,7 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { | |
| flags.BoolVar(&opts.autoUse, "use", true, f.Localizer.MustLocalize("kafka.create.flag.autoUse.description")) | ||
| flags.BoolVarP(&opts.wait, "wait", "w", false, f.Localizer.MustLocalize("kafka.create.flag.wait.description")) | ||
| flags.BoolVarP(&opts.dryRun, "dry-run", "", false, f.Localizer.MustLocalize("kafka.create.flag.dryrun.description")) | ||
| flags.StringVar(&opts.billingModel, "billing-model", "", f.Localizer.MustLocalize("kafka.create.flag.billingModel.description")) | ||
| flags.AddBypassTermsCheck(&opts.bypassChecks) | ||
|
|
||
| _ = cmd.RegisterFlagCompletionFunc(FlagProvider, func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { | ||
|
|
@@ -157,18 +139,6 @@ func NewCreateCommand(f *factory.Factory) *cobra.Command { | |
| return GetCloudProviderRegionCompletionValues(f, opts.provider) | ||
| }) | ||
|
|
||
| _ = cmd.RegisterFlagCompletionFunc(FlagSize, func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { | ||
| return GetKafkaSizeCompletionValues(f, opts.provider, opts.region) | ||
| }) | ||
|
|
||
| _ = cmd.RegisterFlagCompletionFunc(FlagMarketPlaceAcctID, func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { | ||
| return GetMarketplaceAcctIdCompletionValues(f) | ||
| }) | ||
|
|
||
| _ = cmd.RegisterFlagCompletionFunc(FlagMarketPlace, func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { | ||
| return GetMarketplaceCompletionValues(f) | ||
| }) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
|
|
@@ -212,10 +182,21 @@ func runCreate(opts *options) error { | |
| return nil | ||
| } | ||
|
|
||
| userInstanceType, err = accountmgmtutil.GetUserSupportedInstanceType(f.Context, &constants.Kafka.Ams, conn) | ||
| if err != nil || userInstanceType == nil { | ||
| return f.Localizer.MustLocalizeError("kafka.create.error.userInstanceType.notFound") | ||
| err = ValidateBillingModel(opts.billingModel) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = ValidateMarketplaceFlags(opts.billingModel, opts.marketplaceAcctId, opts.marketplace) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| userInstanceType, err = accountmgmtutil.FetchQuotaCost(f, opts.billingModel, opts.marketplaceAcctId, opts.marketplace, &constants.Kafka.Ams) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| } | ||
|
|
||
| var payload *kafkamgmtclient.KafkaRequestPayload | ||
|
|
@@ -225,7 +206,7 @@ func runCreate(opts *options) error { | |
| return f.Localizer.MustLocalizeError("kafka.create.error.noInteractiveMode") | ||
| } | ||
|
|
||
| payload, err = promptKafkaPayload(opts, *userInstanceType) | ||
| payload, err = promptKafkaPayload(opts, userInstanceType) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The interactive mode needs more changes, currently the user will need to specify |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -249,6 +230,8 @@ func runCreate(opts *options) error { | |
| payload.Marketplace.Set(&opts.marketplace) | ||
| payload.BillingCloudAccountId = kafkamgmtclient.NullableString{} | ||
| payload.BillingCloudAccountId.Set(&opts.marketplaceAcctId) | ||
| payload.BillingModel = kafkamgmtclient.NullableString{} | ||
| payload.BillingModel.Set(&opts.billingModel) | ||
| } | ||
|
|
||
| if !opts.bypassChecks { | ||
|
|
@@ -271,7 +254,7 @@ func runCreate(opts *options) error { | |
| return err1 | ||
| } | ||
| if opts.size != "" { | ||
| sizes, err1 := FetchValidKafkaSizes(opts.f, opts.provider, opts.region, *userInstanceType) | ||
| sizes, err1 := FetchValidKafkaSizes(opts.f, opts.provider, opts.region, userInstanceType) | ||
| if err1 != nil { | ||
| return err1 | ||
| } | ||
|
|
@@ -400,7 +383,7 @@ type promptAnswers struct { | |
|
|
||
| // Show a prompt to allow the user to interactively insert the data for their Kafka | ||
| // nolint:funlen | ||
| func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec) (*kafkamgmtclient.KafkaRequestPayload, error) { | ||
| func promptKafkaPayload(opts *options, userQuotaType *accountmgmtutil.QuotaSpec) (*kafkamgmtclient.KafkaRequestPayload, error) { | ||
| f := opts.f | ||
|
|
||
| accountIDNullable := kafkamgmtclient.NullableString{} | ||
|
|
@@ -438,7 +421,7 @@ func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec) | |
| return nil, err | ||
| } | ||
|
|
||
| regionIDs, err := GetEnabledCloudRegionIDs(opts.f, answers.CloudProvider, &userQuotaType) | ||
| regionIDs, err := GetEnabledCloudRegionIDs(opts.f, answers.CloudProvider, userQuotaType) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -474,29 +457,34 @@ func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec) | |
| } | ||
| } | ||
|
|
||
| marketplaces, err := accountmgmtutil.GetValidMarketplaces(f.Context, f.Connection) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if !opts.bypassChecks && len(marketplaces) > 0 { | ||
| if err = promptMarketplaceSelect(f.Localizer, marketplaces, answers); err != nil { | ||
| return nil, err | ||
| } | ||
| if !opts.bypassChecks && opts.billingModel == accountmgmtutil.QuotaMarketplaceType { | ||
|
|
||
| marketplaceAcctIDs, err := accountmgmtutil.GetValidMarketplaceAcctIDs(f.Context, f.Connection, answers.Marketplace) | ||
| marketplaces, err := accountmgmtutil.GetValidMarketplaces(userQuotaType) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if len(marketplaceAcctIDs) > 0 { | ||
| if err = promptMarketplaceAcctIDSelect(f.Localizer, marketplaceAcctIDs, answers); err != nil { | ||
| if len(marketplaces) > 0 { | ||
|
|
||
| if err = promptMarketplaceSelect(f.Localizer, marketplaces, answers); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| marketplaceAcctIDs, err := accountmgmtutil.GetValidMarketplaceAcctIDs(userQuotaType, answers.Marketplace) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| accountIDNullable.Set(&answers.MarketplaceAcctID) | ||
| marketplaceProviderNullable.Set(&answers.Marketplace) | ||
| if len(marketplaceAcctIDs) > 0 { | ||
| if err = promptMarketplaceAcctIDSelect(f.Localizer, marketplaceAcctIDs, answers); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| accountIDNullable.Set(&answers.MarketplaceAcctID) | ||
| marketplaceProviderNullable.Set(&answers.Marketplace) | ||
|
|
||
| } | ||
| } | ||
|
|
||
| payload := &kafkamgmtclient.KafkaRequestPayload{ | ||
|
|
@@ -507,7 +495,7 @@ func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec) | |
| Marketplace: marketplaceProviderNullable, | ||
| } | ||
| printSizeWarningIfNeeded(opts.f, answers.Size, sizes) | ||
| payload.SetPlan(mapAmsTypeToBackendType(&userQuotaType) + "." + answers.Size) | ||
| payload.SetPlan(mapAmsTypeToBackendType(userQuotaType) + "." + answers.Size) | ||
|
|
||
| return payload, nil | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.