Skip to content

Comments

Add IBM Cloud Service constants#1612

Closed
cjschaef wants to merge 2 commits intoopenshift:masterfrom
cjschaef:ibmcloud_service_names
Closed

Add IBM Cloud Service constants#1612
cjschaef wants to merge 2 commits intoopenshift:masterfrom
cjschaef:ibmcloud_service_names

Conversation

@cjschaef
Copy link
Member

@cjschaef cjschaef commented Nov 6, 2023

Add constants for the IBM Cloud Services, in relation to the ability to override these service endpoints in operators and the installer.

Related: https://issues.redhat.com/browse/SPLAT-1097

@elmiko
Copy link

elmiko commented Nov 6, 2023

in general i think this is a fine place for these constants that aren't necessarily used by the API and also are not in an ibm sdk package.

curious to hear what @JoelSpeed thinks

@cjschaef cjschaef force-pushed the ibmcloud_service_names branch from ef01862 to 8868604 Compare November 6, 2023 18:47
@JoelSpeed
Copy link
Contributor

Can you provide an example of where these constants will be used?

package cloudprovider

const (
// IBM Cloud Service Name constants.
Copy link

Choose a reason for hiding this comment

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

given @JoelSpeed 's comment, i think it's worthwhile to add a comment here explaining what these are used for/by. eg something

// These constants are used by MAO, MCO, CIO, Installer to identify blah blah blah

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will do

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

@cjschaef cjschaef force-pushed the ibmcloud_service_names branch 2 times, most recently from 7bfbb39 to 12f144f Compare November 6, 2023 20:21
@JoelSpeed
Copy link
Contributor

Given we now have a concrete list of supported constants, why can we not make the API an enum?

@cjschaef
Copy link
Member Author

I will see if I can refactor that, given I would expect to make conversions to/from string, should those helped functions be placed alongside, or somewhere also in library-go, as I'd expect duplicate code in each consuming component.
Or if golang has a nice method to already support conversions, given the primary use is in openshift/api/config/v1/IBMCloudServiceEndpoint resources? I'll start with the former, and see where we go from there.

@elmiko
Copy link

elmiko commented Nov 10, 2023

@cjschaef imo, if we move this to an enum in openshift/api then we should put the helper functions there as well.

edit:
for example, look at these feature set builder helpers https://github.com/openshift/api/blob/master/config/v1/types_feature.go

@JoelSpeed
Copy link
Contributor

Enum in openshift API should be kube compliant, which means PascalCase. For the IBM SDK you need a different format. So I'd expect a conversion util and consts that are IBM SDK compliant to exist where this PR proposes them today.

The conversion util would take in one of the enum values from openshift/api and convert it to the IBM SDK equivalent. It doesn't even need to have any care for wider types since the API enum should use a typed string alias.

@elmiko
Copy link

elmiko commented Nov 10, 2023

So I'd expect a conversion util and consts that are IBM SDK compliant to exist where this PR proposes them today.

just to be clear, you want to see the consts and util funcs here, and then the enum in the api package?

@JoelSpeed
Copy link
Contributor

There should be two sets of constants. In the API, the enum will be constructed based on type aliases for the different services

// +kubebuilder:validation:Enum=VIP;...;...
type IBMCloudServiceName string

const (
  IBMCloudServiceVIP IBMCloudServiceName = "VIP"
...
)

This is what I expect to see in API, here, there should be something similar but for the IBM SDK versions (lower cased), and then a transform

func IBMSDKCloudServiceName(in configv1.IBMCloudServiceName) (string, error) {
  switch in {
    case configv1.IBMCloudServiceVIP:
      return IBMSDKCloudServiceVIP, nil
    ...
    default:
      return "", fmt.Errorf("unknown IBM Cloud service name: %s", in)
  }
}

@cjschaef
Copy link
Member Author

cjschaef commented Nov 10, 2023

Okay, I'll see about getting a new openshift/api PR open, to define the service names, and see about updating (or closing) this PR to ad the transform/helper functions here in library-go

Updated
And to be clear, the lowercasing was not a mandatory need, more of a simplification. So, we could rely on the PascalCase versions and update all downstream references, which would rely on the Enum at that point anyway.

@cjschaef
Copy link
Member Author

cjschaef commented Nov 10, 2023

I opened the openshift/api PR for the enum
openshift/api#1657

I will refactor this PR, which would strictly be the helper functions, as I don't have hard requirements to use all lowercase names, currently, if we will be refactoring downstream PR's as well (MAPI, installer, etc.).

Done

@cjschaef cjschaef force-pushed the ibmcloud_service_names branch from 12f144f to 65ff370 Compare November 10, 2023 21:37
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 10, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: cjschaef
Once this PR has been reviewed and has the lgtm label, please assign deads2k for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Add helper functions for converting IBMCloudServiceName
types to strings and back.

Related: https://issues.redhat.com/browse/SPLAT-1097
Update go mod to pull in PR changes to openshift/api, for the
IBMCloudServiceName enum.
@cjschaef cjschaef force-pushed the ibmcloud_service_names branch from 65ff370 to 0e6fcc0 Compare November 10, 2023 22:47
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 10, 2023

@cjschaef: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/verify 0e6fcc0 link true /test verify
ci/prow/unit 0e6fcc0 link true /test unit
ci/prow/verify-deps 0e6fcc0 link true /test verify-deps

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@cjschaef
Copy link
Member Author

I don't know that these helper functions are required any longer, now that the IBMCloudServiceEndpoint.Name type has changed from string.

I'm going to close this PR, as downsteam uses of the new IBMCloudServiceName should simply be able to to compare against the enum, and no string conversion or name refactoring should be necessary.....I hope.

@cjschaef cjschaef closed this Nov 10, 2023
@cjschaef cjschaef deleted the ibmcloud_service_names branch November 10, 2023 22:56
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