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

feat: add preferred channel slug #4742

Closed
wants to merge 9 commits into from

Conversation

FourSigma
Copy link
Contributor

@FourSigma FourSigma commented Jul 5, 2024

  • Allows KOTS to bootstrap with a preferred channel slug to support multi-channel licenses.

  • When you kubectl kots install my-app beta, KOTS will now store the preferred channel slug beta in a ConfigMap.

  • This will allow KOTS to hit a new upstream endpoint in replicated-app - /license/:appSlug/:channelSlug to download the definitive channel specific license

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Steps to reproduce

Does this PR introduce a user-facing change?


Does this PR require documentation?

@FourSigma FourSigma changed the title add preferred channel slug feat: add preferred channel slug Jul 8, 2024
@FourSigma FourSigma added the type::feature New feature or request label Jul 8, 2024
@@ -163,6 +163,11 @@ func InstallCmd() *cobra.Command {

upstream := pull.RewriteUpstream(args[0])

preferredChannelSlug := ""
if len(args) > 1 {
preferredChannelSlug = args[1]
Copy link
Member

Choose a reason for hiding this comment

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

This should be in the same arg as app slug, as shown in the docs: https://docs.replicated.com/reference/kots-cli-install#examples

kubectl kots install kots-sentry/stable

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member

Choose a reason for hiding this comment

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

@divolgin @sgalsaleh Just confirming. Right now this would result in having a whole new arg that would be redundant (e.g. kubectl kots install kots-sentry/stable stable) . But we can just pluck the channel out of the upstreamURI - created right above on line 164 (maybe with ParseReplicatedURL) ?

Copy link
Member

Choose a reason for hiding this comment

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

yes, and it's optional. should default to "stable"

Copy link
Member

Choose a reason for hiding this comment

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

ah cool 👍 will send along one more update to use the default.

@@ -40,8 +44,37 @@ type LicenseData struct {
License *kotsv1beta1.License
}

func GetPreferredChannelSlug() (string, error) {
Copy link
Member

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 existing GetInstallationParams function:

func GetInstallationParams(configMapName string) (InstallationParams, error) {

Copy link
Member

Choose a reason for hiding this comment

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

Example usage:

instParams, err := kotsutil.GetInstallationParams(kotsadmtypes.KotsadmConfigMap)
if err != nil {
return errors.Wrap(err, "failed to get existing kotsadm config map")
}

Copy link
Member

Choose a reason for hiding this comment

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

Also, if you don't mind, can you just have that GetInstallationParams always use kotsadmtypes.KotsadmConfigMap and not have to accept it as a parameter?

Copy link
Member

Choose a reason for hiding this comment

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

@sgalsaleh safe for me to update RemoveAppVersionLabelFromInstallationParams while im at it?

func RemoveAppVersionLabelFromInstallationParams(configMapName string) error {

Has the same func sig and inline use of configMapName as GetInstallationParams

Copy link
Member

Choose a reason for hiding this comment

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

fyi - went ahead updated RemoveAppVersionLabelFromInstallationParams too (but easy to undo if I shouldn't have).

url := fmt.Sprintf("%s/license/%s", license.Spec.Endpoint, license.Spec.AppSlug)
if channelSlug != "" {
url = fmt.Sprintf("%s/%s", url, channelSlug)
Copy link
Member

Choose a reason for hiding this comment

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

just to confirm, is the idea that this decision will be recorded by replicated.app and this channel will be used automatically by replicated.app for subsequent requests?

Copy link
Member

Choose a reason for hiding this comment

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

@sgalsaleh i think the answer is yes. At least for requests to this endpoint, I'm not sure how this plays out in other areas. But hoping @marccampbell or maybe @divolgin can confirm.

Over on the pending replicated.app pr from Siva he mentioned:

We now check for the existence of a row in the license_instance table. If it exists, we use the channelId from that table to generate the license in L245. This prevents the downstream from switching channels once initialized and recorded on the license_instance table.

And does look like it actually does that. If there was a licenseInstance entry it will use that channel id instead:

license = await stores.licenseStore.getLicenseFromIdAndChannelSlugId(licenseInstance.licenseId, licenseInstance.downstreamChannelId);

Copy link
Member

Choose a reason for hiding this comment

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

Hard to comment on code that has been removed 😄 :

  • Handler still has channel slug in it while client does not?: @Get("/:appSlug/:channelSlug")
  • Instance data is recoded asynchronously and may be delayed.
  • When channel on a license changes, instance can make any number of requests before reporting new channel
    • There is also a distinction between what channel license is assigned to and what channel is currently deployed
  • This should be tested e2e with a channel other than "stable" with a brand new instance

@CLAassistant
Copy link

CLAassistant commented Jul 9, 2024

CLA assistant check
All committers have signed the CLA.

@pandemicsyn pandemicsyn requested review from sgalsaleh and divolgin July 9, 2024 02:21
sgalsaleh
sgalsaleh previously approved these changes Jul 9, 2024
divolgin
divolgin previously approved these changes Jul 9, 2024
@pandemicsyn pandemicsyn dismissed stale reviews from divolgin and sgalsaleh via 729ddf0 July 9, 2024 18:56
sgalsaleh
sgalsaleh previously approved these changes Jul 11, 2024
@pandemicsyn pandemicsyn marked this pull request as draft July 17, 2024 18:15
@pandemicsyn
Copy link
Member

closing in favor of (wip) #4767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type::feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants