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

OCM-2966 : Feat : Added subscription_type parameter to create cluster command #531

Merged
merged 11 commits into from
Sep 12, 2023

Conversation

tirthct
Copy link
Contributor

@tirthct tirthct commented Jul 31, 2023

Changed

  • Added subscription_type parameter to create cluster command
  • Added validation to have one of the specific options for the command
  • Defaulted subscription_type to standard

Tested

  • Cluster should be created based on the subscription_type parameter passed in cli : tested

Comment on lines 49 to 51
standardSubscriptionType = "standard"
marketplaceRhmSubscriptionType = "marketplace-rhm"
marketplaceGcpSubscriptionType = "marketplace-gcp"

This comment was marked as resolved.

Comment on lines 315 to 316
fmt.Sprintf("The subscription billing model for the cluster. Options are %s",
strings.Join(ValidSubscriptionTypes, ",")),

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@cristianoveiga
Copy link
Contributor

Let's update the PR name/commit description with the latest convention

@tirthct tirthct changed the title OCM-2966 : Added subscription_type parameter to create cluster command OCM-2966 : Feat : Added subscription_type parameter to create cluster command Sep 6, 2023
}
for _, billingModel := range billingModels {
options = append(options, arguments.Option{
Value: fmt.Sprintf("%s (%s)", billingModel.Id(), billingModel.Description()),
Copy link
Contributor

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?

Copy link
Contributor Author

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

return options, nil
}

func getSubscriptionTypeIdFromDescription(connection *sdk.Connection, value string) string {
Copy link
Contributor

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

Copy link
Contributor Author

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

return ""
}

func getBillingModel(connection *sdk.Connection, billingModelID string) (*amv1.BillingModelItem, error) {
Copy link
Contributor

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

Copy link
Contributor Author

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

//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()),
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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)
		}

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())
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used latest sdk version

Comment on lines 1143 to 1145
if isGcpSubscriptionType {
fmt.Println("setting ccs to 'true'")
args.ccs.Enabled = true
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

@cristianoveiga cristianoveiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tirthct PTAL

@@ -19,6 +19,7 @@ package cluster
import (
"encoding/json"
"fmt"
"github.com/openshift-online/ocm-cli/pkg/billing"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order of imports...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

fmt.Println("setting ccs to 'true'")
args.ccs.Enabled = true
}
err = promptCCS(fs, args.ccs.Enabled == true)
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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 ?

Copy link
Contributor Author

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing punctuation mark

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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.

Copy link
Contributor Author

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

Copy link
Contributor

@cristianoveiga cristianoveiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tirthct
Copy link
Contributor Author

tirthct commented Sep 12, 2023

@gdbranco can you PTAL?

@gdbranco gdbranco merged commit 59c8a6d into openshift-online:main Sep 12, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants