-
Notifications
You must be signed in to change notification settings - Fork 138
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
OCM-2966 : Feat : Added subscription_type parameter to create cluster command #531
Conversation
cmd/ocm/create/cluster/cmd.go
Outdated
standardSubscriptionType = "standard" | ||
marketplaceRhmSubscriptionType = "marketplace-rhm" | ||
marketplaceGcpSubscriptionType = "marketplace-gcp" |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
cmd/ocm/create/cluster/cmd.go
Outdated
fmt.Sprintf("The subscription billing model for the cluster. Options are %s", | ||
strings.Join(ValidSubscriptionTypes, ",")), |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Let's update the PR name/commit description with the latest convention |
…nteractive marketplace-gcp
… to get billing model
cmd/ocm/create/cluster/cmd.go
Outdated
} | ||
for _, billingModel := range billingModels { | ||
options = append(options, arguments.Option{ | ||
Value: fmt.Sprintf("%s (%s)", billingModel.Id(), billingModel.Description()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to add the description to the value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it before since interactive mode has a ? option to show description, but seems it only shows descriptions of the argument, not the drop down. Removed the description
…t value for subscription type
cmd/ocm/create/cluster/cmd.go
Outdated
return options, nil | ||
} | ||
|
||
func getSubscriptionTypeIdFromDescription(connection *sdk.Connection, value string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using the same approach used for subnets, see https://github.com/openshift-online/ocm-cli/blob/main/cmd/ocm/create/cluster/cmd.go#L885
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used similar methods as subnets
cmd/ocm/create/cluster/cmd.go
Outdated
return "" | ||
} | ||
|
||
func getBillingModel(connection *sdk.Connection, billingModelID string) (*amv1.BillingModelItem, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make this function reusable (as well as getBillingModels) by moving them to its own package under pkg/billing, for example.
This logic doesn't really belong to cmd/ocm/create/cluster/cmd.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to the billing package
cmd/ocm/create/cluster/cmd.go
Outdated
//Standard billing model should always be the first option | ||
if billingModel.Id() == StandardSubscriptionType { | ||
standardOption := arguments.Option{ | ||
Value: fmt.Sprintf("%s (%s)", billingModel.Id(), billingModel.Description()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is duplicated and probably deserves its own function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a function and reused wherever duplicated
return options, err | ||
} | ||
for _, billingModel := range billingModels { | ||
//Standard billing model should always be the first option |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified by using a function to create the option and reusing outside the if else block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify further...
How about this:
if billingModel.ID() == billing.StandardSubscriptionType {
options = append([]arguments.Option{option}, options...)
} else {
options = append(options, option)
}
cmd/ocm/create/cluster/cmd.go
Outdated
return err | ||
// If marketplace-gcp subscription type is used, provider can only be GCP | ||
gcpBillingModel, _ := getBillingModel(connection, marketplaceGcpSubscriptionType) | ||
isGcpSubscriptionType := args.subscriptionType == fmt.Sprintf("%s (%s)", gcpBillingModel.Id(), gcpBillingModel.Description()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isGcpSubscriptionType
not all GCP subscriptions falls into this. I would suggest naming it isGcpMarketplace
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
go.mod
Outdated
@@ -12,7 +12,7 @@ require ( | |||
github.com/nwidger/jsoncolor v0.3.2 | |||
github.com/onsi/ginkgo/v2 v2.11.0 | |||
github.com/onsi/gomega v1.27.8 | |||
github.com/openshift-online/ocm-sdk-go v0.1.356 | |||
github.com/openshift-online/ocm-sdk-go v0.1.367 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to wait the next version as we are changing the BillingModelItem from a struct to a class.
See https://github.com/openshift-online/ocm-api-model/pull/831/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used latest sdk version
cmd/ocm/create/cluster/cmd.go
Outdated
if isGcpSubscriptionType { | ||
fmt.Println("setting ccs to 'true'") | ||
args.ccs.Enabled = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could move this logic outside this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved outside this function and passed a value on whether to prompt for ccs or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tirthct PTAL
cmd/ocm/create/cluster/cmd.go
Outdated
@@ -19,6 +19,7 @@ package cluster | |||
import ( | |||
"encoding/json" | |||
"fmt" | |||
"github.com/openshift-online/ocm-cli/pkg/billing" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order of imports...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
cmd/ocm/create/cluster/cmd.go
Outdated
fmt.Println("setting ccs to 'true'") | ||
args.ccs.Enabled = true | ||
} | ||
err = promptCCS(fs, args.ccs.Enabled == true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promptCCS(fs, args.ccs.Enabled == true) can go in a else block here, no ? This way we could avoid the extra parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to call promtCCS as "service account file" prompt logic is present over there. And that is based on whether args.ccs.Enables is true or false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay... I was not expecting that.
Should we replace "args.ccs.Enabled == true" with args.ccs.Enabled ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified
&args.subscriptionType, | ||
"subscription-type", | ||
billing.StandardSubscriptionType, | ||
fmt.Sprintf("The subscription billing model for the cluster. Options are %s", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing punctuation mark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the options description consistent with https://github.com/openshift-online/ocm-cli/blob/main/cmd/ocm/create/cluster/cmd.go#L294 and https://github.com/openshift-online/ocm-cli/blob/main/cmd/ocm/create/cluster/cmd.go#L301
@@ -27,7 +27,7 @@ import ( | |||
"time" | |||
|
|||
sdk "github.com/openshift-online/ocm-sdk-go" | |||
amsv1 "github.com/openshift-online/ocm-sdk-go/accountsmgmt/v1" | |||
amv1 "github.com/openshift-online/ocm-sdk-go/accountsmgmt/v1" |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed these to keep is consistent with CS (they have used cmv1 instead of cmsv1), but we can revert this back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@gdbranco can you PTAL? |
Changed
Tested