Skip to content

Commit

Permalink
fix: add tech preview warning for kafka creation(#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki authored May 23, 2022
1 parent 060c1d4 commit f9fb934
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/redhat-developer/app-services-sdk-go/accountmgmt v0.1.0
github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.5.0
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.11.4
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.11.6
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.6.1
github.com/redhat-developer/service-binding-operator v0.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.5.0 h1:cf+K96kW
github.com/redhat-developer/app-services-sdk-go/connectormgmt v0.5.0/go.mod h1:JAedrXf/qLHd7lpOS+bOFh8nrOpp2j0sg4/VG/1um6c=
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0 h1:ExEHQaihnPNxN2nKXB0q5nrmSv4p8b3Idzt7TChxv+Q=
github.com/redhat-developer/app-services-sdk-go/kafkainstance v0.6.0/go.mod h1:hMpejngP3BFnifCDH1gKRG9cU9Q4lr0WiQaW7A1LYo4=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.11.4 h1:piT2sSsH+gLDYLObUqRtm5Yd8LYDZ/Fl+nCHv5dIvw0=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.11.4/go.mod h1:NvNM4Gnw3dPMY6H+fsc1GHWev0ydSGsgjiCP10Bj2/M=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.11.6 h1:ElBvomSBaSKnX9kdvbY7rMLYjoXa2n6T8VnwZEw92do=
github.com/redhat-developer/app-services-sdk-go/kafkamgmt v0.11.6/go.mod h1:NvNM4Gnw3dPMY6H+fsc1GHWev0ydSGsgjiCP10Bj2/M=
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1 h1:xRq5XJzRDs/Z7e/9SDt6zbNRIyesC4LTqN9ajHKwjHo=
github.com/redhat-developer/app-services-sdk-go/registryinstance v0.3.1/go.mod h1:Z/gr/snlpsqYg4vftmcx97vCR3qMQJhALGelDHx4pMA=
github.com/redhat-developer/app-services-sdk-go/registrymgmt v0.6.1 h1:3sUmQ3nAawsYWg7ZCO2Q8HF2J7MW6YA38h/YFL3ao6o=
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/kafka/create/api_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ func validateProviderRegion(input *ValidatorInput, selectedProvider kafkamgmtcli
}

func (input *ValidatorInput) ValidateSize() error {
// Size is not required
if input.size == "" {
return nil
}

sizes, err := GetValidKafkaSizes(input.f, input.provider, input.region, *input.userAMSInstanceType)
sizes, err := FetchValidKafkaSizesLabels(input.f, input.provider, input.region, *input.userAMSInstanceType)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/kafka/create/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GetKafkaSizeCompletionValues(f *factory.Factory, providerID string, regionI
userInstanceType, _ := accountmgmtutil.GetUserSupportedInstanceType(f.Context, &constants.Kafka.Ams, conn)

// Not including quota in this request as it takes very long time to list quota for all regions in suggestion mode
validRegions, _ = GetValidKafkaSizes(f, providerID, regionId, *userInstanceType)
validRegions, _ = FetchValidKafkaSizesLabels(f, providerID, regionId, *userInstanceType)

return validRegions, cobra.ShellCompDirectiveNoSpace
}
30 changes: 24 additions & 6 deletions pkg/cmd/kafka/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ var (
// NewCreateCommand creates a new command for creating kafkas.
func NewCreateCommand(f *factory.Factory) *cobra.Command {
opts := &options{

f: f,
}

Expand Down Expand Up @@ -221,11 +220,17 @@ func runCreate(opts *options) error {
}

if opts.size != "" {
sizes, err1 := FetchValidKafkaSizes(opts.f, opts.provider, opts.region, *userInstanceType)
if err1 != nil {
return err1
}
printSizeWarningIfNeeded(opts.f, opts.size, sizes)
payload.SetPlan(mapAmsTypeToBackendType(userInstanceType) + "." + opts.size)
}
}

f.Logger.Debug("Creating kafka instance", payload.Name, payload.Plan)
f.Logger.Debug("Creating kafka instance", payload.Name, payload.GetPlan())

if opts.dryRun {
f.Logger.Info(f.Localizer.MustLocalize("kafka.create.log.info.dryRun.success"))
return nil
Expand Down Expand Up @@ -392,18 +397,18 @@ func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec)
return nil, err
}

sizes, err := GetValidKafkaSizes(opts.f, answers.CloudProvider, answers.Region, userQuotaType)
sizes, err := FetchValidKafkaSizes(opts.f, answers.CloudProvider, answers.Region, userQuotaType)
if err != nil {
return nil, err
}

if len(sizes) == 1 {
answers.Size = sizes[0]
answers.Size = sizes[0].GetId()
} else {
sizeLabels := GetValidKafkaSizesLabels(sizes)
planPrompt := &survey.Select{
Message: f.Localizer.MustLocalize("kafka.create.input.plan.message"),
Options: sizes,
Help: "",
Options: sizeLabels,
}

err = survey.AskOne(planPrompt, &answers.Size)
Expand All @@ -417,7 +422,20 @@ func promptKafkaPayload(opts *options, userQuotaType accountmgmtutil.QuotaSpec)
Region: &answers.Region,
CloudProvider: &answers.CloudProvider,
}
printSizeWarningIfNeeded(opts.f, answers.Size, sizes)
payload.SetPlan(mapAmsTypeToBackendType(&userQuotaType) + "." + answers.Size)

return payload, nil
}

func printSizeWarningIfNeeded(f *factory.Factory, selectedSize string, sizes []kafkamgmtclient.SupportedKafkaSize) {
for i := range sizes {
if sizes[i].GetId() == selectedSize {
f.Logger.Info(f.Localizer.MustLocalize("kafka.create.log.info.sizeUnit",
localize.NewEntry("DisplaySize", sizes[i].GetDisplayName()), localize.NewEntry("Size", sizes[i].GetId())))
if sizes[i].GetMaturityStatus() == "preview" {
f.Logger.Info(f.Localizer.MustLocalize("kafka.create.log.info.sizePreview"))
}
}
}
}
29 changes: 24 additions & 5 deletions pkg/cmd/kafka/create/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,35 @@ func mapAmsTypeToBackendType(amsType *accountmgmtutil.QuotaSpec) CloudProviderId
}
}

// return list of the valid instance sizes for the specified region and ams instance types
func GetValidKafkaSizes(f *factory.Factory,
func GetValidKafkaSizesLabels(sizes []kafkamgmtclient.SupportedKafkaSize) []string {
var labels []string = make([]string, len(sizes))
for i := range sizes {
labels[i] = sizes[i].GetId()
}

return labels
}

func FetchValidKafkaSizesLabels(f *factory.Factory,
providerID string, regionId string, amsType accountmgmtutil.QuotaSpec) ([]string, error) {
sizes, err := FetchValidKafkaSizes(f, providerID, regionId, amsType)
if err != nil {
return nil, err
}
return GetValidKafkaSizesLabels(sizes), nil

}

// return list of the valid instance sizes for the specified region and ams instance types
func FetchValidKafkaSizes(f *factory.Factory,
providerID string, regionId string, amsType accountmgmtutil.QuotaSpec) ([]kafkamgmtclient.SupportedKafkaSize, error) {

conn, err := f.Connection(connection.DefaultConfigSkipMasAuth)
if err != nil {
return nil, err
}

validSizes := []string{}
validSizes := []kafkamgmtclient.SupportedKafkaSize{}

instanceTypes, _, err := conn.API().
KafkaMgmt().
Expand All @@ -62,7 +81,7 @@ func GetValidKafkaSizes(f *factory.Factory,
if desiredInstanceType == instanceType.GetId() {
instanceSizes := instanceType.GetSizes()
for i := range instanceSizes {
validSizes = append(validSizes, instanceSizes[i].GetId())
validSizes = append(validSizes, instanceSizes[i])
}
}
}
Expand All @@ -72,7 +91,7 @@ func GetValidKafkaSizes(f *factory.Factory,
instanceSizes := instanceType.GetSizes()
for i := range instanceSizes {
if instanceSizes[i].GetQuotaConsumed() <= int32(amsType.Quota) {
validSizes = append(validSizes, instanceSizes[i].GetId())
validSizes = append(validSizes, instanceSizes[i])
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/core/localize/locales/en/cmd/kafka.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ one = "Cloud Region:"
[kafka.create.input.plan.message]
one = 'Instance type:'

[kafka.create.log.info.sizeUnit]
one = 'Kafka instance with size {{.DisplaySize}} is being created. (Size id: {{.Size}})'

[kafka.create.log.info.sizePreview]
one = 'Selected Kafka instance size is a Technology Preview feature. Do not use it for production workloads. For more information, see https://access.redhat.com/support/offerings/techpreview'

[kafka.create.input.cloudRegion.help]
description = 'Help text for Cloud Region'
one = "Geographical region where the Kafka instance will be deployed"
Expand Down

0 comments on commit f9fb934

Please sign in to comment.