Skip to content

Commit

Permalink
Merge branch 'main' into laverya/sc-107620/allow-pass-annotations-and…
Browse files Browse the repository at this point in the history
…-labels-to-kots
  • Loading branch information
laverya authored Sep 6, 2024
2 parents 5a41725 + 7eb4edd commit 790e9a3
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .image.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# most recent tag is interpolated from the source repository and used to generate a fully qualified image
# name.
MINIO_TAG='0.20240826.153307-r0'
RQLITE_TAG='8.29.4-r0'
RQLITE_TAG='8.30.0-r0'
DEX_TAG='2.41.1-r0'
SCHEMAHERO_TAG='0.17.10'
LVP_TAG='v0.6.7'
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include Makefile.build.mk
CURRENT_USER := $(if $(GITHUB_USER),$(GITHUB_USER),$(shell id -u -n))
MINIO_TAG ?= 0.20240826.153307-r0
RQLITE_TAG ?= 8.29.4-r0
RQLITE_TAG ?= 8.30.0-r0
DEX_TAG ?= 2.41.1-r0
LVP_TAG ?= v0.6.7

Expand Down
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
2 changes: 1 addition & 1 deletion pkg/image/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package image

const (
Minio = "kotsadm/minio:0.20240826.153307-r0"
Rqlite = "kotsadm/rqlite:8.29.4-r0"
Rqlite = "kotsadm/rqlite:8.30.0-r0"
Dex = "kotsadm/dex:2.41.1-r0"
Schemahero = "schemahero/schemahero:0.17.10"
Lvp = "replicated/local-volume-provider:v0.6.7"
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))
}
3 changes: 3 additions & 0 deletions pkg/rewrite/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func Rewrite(rewriteOptions RewriteOptions) error {
IsAirgap: rewriteOptions.IsAirgap,
KotsadmID: k8sutil.GetKotsadmID(clientset),
AppID: rewriteOptions.AppID,
HTTPProxyEnvValue: rewriteOptions.HTTPProxyEnvValue,
HTTPSProxyEnvValue: rewriteOptions.HTTPSProxyEnvValue,
NoProxyEnvValue: rewriteOptions.NoProxyEnvValue,
}
if err = upstream.WriteUpstream(u, writeUpstreamOptions); err != nil {
log.FinishSpinnerWithError()
Expand Down
18 changes: 18 additions & 0 deletions pkg/upstream/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ func buildReplicatedValues(u *types.Upstream, options types.WriteOptions) (map[s
replicatedValues["license"] = string(MustMarshalLicense(u.License))
}

replicatedValues["extraEnv"] = []struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
}{
{
Name: "HTTP_PROXY",
Value: options.HTTPProxyEnvValue,
},
{
Name: "HTTPS_PROXY",
Value: options.HTTPSProxyEnvValue,
},
{
Name: "NO_PROXY",
Value: options.NoProxyEnvValue,
},
}

return replicatedValues, nil
}

Expand Down
75 changes: 66 additions & 9 deletions pkg/upstream/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func Test_configureChart(t *testing.T) {
type Test struct {
name string
isAirgap bool
httpProxy string
httpsProxy string
noProxy string
chartContent map[string]string
want map[string]string
wantErr bool
Expand Down Expand Up @@ -288,8 +291,11 @@ another: value
// Generate dynamic tests using the supported replicated chart names
for _, chartName := range testReplicatedChartNames {
tests = append(tests, Test{
name: "online - a standalone replicated chart",
isAirgap: false,
name: "online - a standalone replicated chart",
isAirgap: false,
httpProxy: "http://10.1.0.1:3128",
httpsProxy: "https://10.1.0.1:3129",
noProxy: "localhost,127.0.0.1",
chartContent: map[string]string{
"replicated/Chart.yaml": fmt.Sprintf(`apiVersion: v1
name: %s
Expand Down Expand Up @@ -376,6 +382,13 @@ some: value
# and this comment as well
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: http://10.1.0.1:3128
- name: HTTPS_PROXY
value: https://10.1.0.1:3129
- name: NO_PROXY
value: localhost,127.0.0.1
isAirgap: false
replicatedID: kotsadm-id
`,
Expand Down Expand Up @@ -459,6 +472,13 @@ some: value
# and this comment as well
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: ""
- name: HTTPS_PROXY
value: ""
- name: NO_PROXY
value: ""
isAirgap: true
replicatedID: kotsadm-id
global:
Expand All @@ -482,8 +502,11 @@ global:
})

tests = append(tests, Test{
name: "online - a guestbook chart with the replicated subchart",
isAirgap: false,
name: "online - a guestbook chart with the replicated subchart",
isAirgap: false,
httpProxy: "http://10.1.0.1:3128",
httpsProxy: "https://10.1.0.1:3129",
noProxy: "localhost,127.0.0.1",
chartContent: map[string]string{
"guestbook/Chart.yaml": `apiVersion: v2
name: guestbook
Expand Down Expand Up @@ -569,6 +592,13 @@ image:
- service/replicated
versionLabel: 1.0.0
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: http://10.1.0.1:3128
- name: HTTPS_PROXY
value: https://10.1.0.1:3129
- name: NO_PROXY
value: localhost,127.0.0.1
isAirgap: false
replicatedID: kotsadm-id
global:
Expand Down Expand Up @@ -675,6 +705,13 @@ image:
- service/replicated
versionLabel: 1.0.0
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: ""
- name: HTTPS_PROXY
value: ""
- name: NO_PROXY
value: ""
isAirgap: true
license: |
apiVersion: kots.io/v1beta1
Expand Down Expand Up @@ -733,8 +770,11 @@ some: value
})

tests = append(tests, Test{
name: "online - a redis chart with the replicated subchart and predefined replicated and global values",
isAirgap: false,
name: "online - a redis chart with the replicated subchart and predefined replicated and global values",
isAirgap: false,
httpProxy: "http://10.1.0.1:3128",
httpsProxy: "https://10.1.0.1:3129",
noProxy: "localhost,127.0.0.1",
chartContent: map[string]string{
"redis/Chart.yaml": `apiVersion: v1
name: redis
Expand Down Expand Up @@ -848,6 +888,13 @@ global:
- service/replicated
versionLabel: 1.0.0
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: http://10.1.0.1:3128
- name: HTTPS_PROXY
value: https://10.1.0.1:3129
- name: NO_PROXY
value: localhost,127.0.0.1
isAirgap: false
replicatedID: kotsadm-id
`, chartName),
Expand Down Expand Up @@ -965,6 +1012,13 @@ global:
- service/replicated
versionLabel: 1.0.0
appID: app-id
extraEnv:
- name: HTTP_PROXY
value: ""
- name: HTTPS_PROXY
value: ""
- name: NO_PROXY
value: ""
isAirgap: true
license: |
apiVersion: kots.io/v1beta1
Expand Down Expand Up @@ -1244,9 +1298,12 @@ some: value
}

writeOptions := types.WriteOptions{
KotsadmID: "kotsadm-id",
AppID: "app-id",
IsAirgap: tt.isAirgap,
KotsadmID: "kotsadm-id",
AppID: "app-id",
IsAirgap: tt.isAirgap,
HTTPProxyEnvValue: tt.httpProxy,
HTTPSProxyEnvValue: tt.httpsProxy,
NoProxyEnvValue: tt.noProxy,
}

got, err := configureChart(chartBytes, upstream, writeOptions)
Expand Down

0 comments on commit 790e9a3

Please sign in to comment.