Skip to content

Commit

Permalink
Merge branch 'main' into divolgin/sc-111175/support-for-installing-be…
Browse files Browse the repository at this point in the history
…hind-a-proxy
  • Loading branch information
divolgin authored Sep 4, 2024
2 parents aeb5b0c + fa660c6 commit 5901ad9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cmd/kots/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ func InstallCmd() *cobra.Command {
}()

upstream := pull.RewriteUpstream(args[0])
preferredChannelSlug, err := extractPreferredChannelSlug(upstream)
preferredChannelSlug, err := extractPreferredChannelSlug(log, upstream)
if err != nil {
return errors.Wrap(err, "failed to extract preferred channel slug")
}

license, err = kotslicense.VerifyAndUpdateLicense(log, license, preferredChannelSlug, isAirgap)
if err != nil {
return errors.Wrap(err, "failed to verify and update license")
Expand Down
9 changes: 5 additions & 4 deletions cmd/kots/cli/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ func PullCmd() *cobra.Command {
}

upstream := pull.RewriteUpstream(args[0])
preferredChannelSlug, err := extractPreferredChannelSlug(upstream)
if err != nil {
return errors.Wrap(err, "failed to extract preferred channel slug")
}

log := logger.NewCLILogger(cmd.OutOrStdout())
log.Initialize()

preferredChannelSlug, err := extractPreferredChannelSlug(log, upstream)
if err != nil {
return errors.Wrap(err, "failed to extract preferred channel slug")
}

// If we are passed a multi-channel license, verify that the requested channel is in the license
// so that we can warn the user immediately if it is not.
license, err = kotslicense.VerifyAndUpdateLicense(log, license, preferredChannelSlug, false)
Expand Down
7 changes: 6 additions & 1 deletion cmd/kots/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/replicatedapp"
"github.com/replicatedhq/kots/pkg/util"
)
Expand Down Expand Up @@ -53,7 +54,7 @@ func splitEndpointAndNamespace(endpoint string) (string, string) {
return registryEndpoint, registryNamespace
}

func extractPreferredChannelSlug(upstreamURI string) (string, error) {
func extractPreferredChannelSlug(log *logger.CLILogger, upstreamURI string) (string, error) {
u, err := url.ParseRequestURI(upstreamURI)
if err != nil {
return "", errors.Wrap(err, "failed to parse uri")
Expand All @@ -67,5 +68,9 @@ func extractPreferredChannelSlug(upstreamURI string) (string, error) {
if replicatedUpstream.Channel != nil {
return *replicatedUpstream.Channel, nil
}

if log != nil {
log.ActionWithoutSpinner("No channel specified in upstream URI, falling back to channel slug 'stable'.")
}
return "stable", nil
}
4 changes: 2 additions & 2 deletions cmd/kots/cli/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Test_extractPreferredChannelSlug(t *testing.T) {
args{
upstreamURI: "replicated://app-slug",
},
"stable", // default channel
"stable",
false,
},
{
Expand All @@ -133,7 +133,7 @@ func Test_extractPreferredChannelSlug(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := extractPreferredChannelSlug(tt.args.upstreamURI)
got, err := extractPreferredChannelSlug(nil, tt.args.upstreamURI)
if (err != nil) != tt.wantErr {
t.Errorf("extractPreferredChannelSlug() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
23 changes: 19 additions & 4 deletions pkg/license/multichannel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package license

import (
"fmt"
"strings"

"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/replicatedapp"
Expand Down Expand Up @@ -40,11 +43,17 @@ func VerifyAndUpdateLicense(log *logger.CLILogger, license *kotsv1beta1.License,
return nil, nil
}
if isAirgap {
if !canInstallFromChannel(preferredChannelSlug, license) {
return nil, errors.New("requested channel not found in supplied license")
if canInstallFromChannel(preferredChannelSlug, license) {
return license, nil
}
validChannels := []string{}
for _, channel := range license.Spec.Channels {
validChannels = append(validChannels, fmt.Sprintf("%s/%s", license.Spec.AppSlug, channel.ChannelSlug))
}
return license, nil
log.Errorf("Channel slug %q is not allowed by license. Please use one of the following: %s", preferredChannelSlug, strings.Join(validChannels, ", "))
return license, errors.New(fmt.Sprintf("channel slug %q is not allowed by license", preferredChannelSlug))
}

log.ActionWithSpinner("Checking for license update")
// we fetch the latest license to ensure that the license is up to date, before proceeding
updatedLicense, err := replicatedapp.GetLatestLicense(license, "")
Expand All @@ -53,8 +62,14 @@ func VerifyAndUpdateLicense(log *logger.CLILogger, license *kotsv1beta1.License,
return nil, errors.Wrap(err, "failed to get latest license")
}
log.FinishSpinner()

if canInstallFromChannel(preferredChannelSlug, updatedLicense.License) {
return updatedLicense.License, nil
}
return nil, errors.New("requested channel not found in latest license")
validChannels := []string{}
for _, channel := range license.Spec.Channels {
validChannels = append(validChannels, fmt.Sprintf("%s/%s", license.Spec.AppSlug, channel.ChannelSlug))
}
log.Errorf("Channel slug %q is not allowed by license. Please use one of the following: %s", preferredChannelSlug, strings.Join(validChannels, ", "))
return updatedLicense.License, errors.New(fmt.Sprintf("channel slug %q is not allowed by latest license", preferredChannelSlug))
}

0 comments on commit 5901ad9

Please sign in to comment.