From 883aa95c69e032064414fb22e94adcef9d215e9a Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Tue, 15 Oct 2024 09:23:01 -0500 Subject: [PATCH] fix: duplicate helm extensions in clusterconfig (#1306) --- cmd/embedded-cluster/install.go | 4 ++- cmd/embedded-cluster/list_images.go | 8 ++++- cmd/embedded-cluster/metadata.go | 31 +++++++++++++++----- e2e/cluster/lxd/cluster.go | 2 ++ e2e/kots-release-install/cluster-config.yaml | 3 ++ e2e/kots-release-install/deployment-2.yaml | 2 +- e2e/kots-release-install/deployment.yaml | 2 +- e2e/kots-release-upgrade/cluster-config.yaml | 5 ++++ e2e/kots-release-upgrade/deployment-2.yaml | 2 +- e2e/kots-release-upgrade/deployment.yaml | 2 +- e2e/version_test.go | 21 +++++++++++++ operator/pkg/charts/reconcile.go | 2 +- pkg/addons/registry/registry.go | 13 ++++---- 13 files changed, 76 insertions(+), 21 deletions(-) diff --git a/cmd/embedded-cluster/install.go b/cmd/embedded-cluster/install.go index ca60edb34..aa7058391 100644 --- a/cmd/embedded-cluster/install.go +++ b/cmd/embedded-cluster/install.go @@ -560,7 +560,9 @@ func installAndWaitForK0s(c *cli.Context, provider *defaults.Provider, applier * func runOutro(c *cli.Context, provider *defaults.Provider, applier *addons.Applier, cfg *k0sconfig.ClusterConfig) error { os.Setenv("KUBECONFIG", provider.PathToKubeConfig()) - metadata, err := gatherVersionMetadata(cfg) + // This metadata should be the same as the artifact from the release without the vendor customizations + defaultCfg := config.RenderK0sConfig() + metadata, err := gatherVersionMetadata(defaultCfg, false) if err != nil { return fmt.Errorf("unable to gather release metadata: %w", err) } diff --git a/cmd/embedded-cluster/list_images.go b/cmd/embedded-cluster/list_images.go index 38f021e41..7d9188d10 100644 --- a/cmd/embedded-cluster/list_images.go +++ b/cmd/embedded-cluster/list_images.go @@ -11,9 +11,15 @@ var listImagesCommand = &cli.Command{ Name: "list-images", Usage: "List images embedded in the cluster", Hidden: true, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "omit-release-metadata", + Usage: "Omit the release metadata from the output", + }, + }, Action: func(c *cli.Context) error { k0sCfg := config.RenderK0sConfig() - metadata, err := gatherVersionMetadata(k0sCfg) + metadata, err := gatherVersionMetadata(k0sCfg, !c.Bool("omit-release-metadata")) if err != nil { return fmt.Errorf("failed to gather version metadata: %w", err) } diff --git a/cmd/embedded-cluster/metadata.go b/cmd/embedded-cluster/metadata.go index d5e987913..d75b144cd 100644 --- a/cmd/embedded-cluster/metadata.go +++ b/cmd/embedded-cluster/metadata.go @@ -25,9 +25,15 @@ var metadataCommand = &cli.Command{ Name: "metadata", Usage: "Print metadata about this release", Hidden: true, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "omit-release-metadata", + Usage: "Omit the release metadata from the output", + }, + }, Action: func(c *cli.Context) error { k0sCfg := config.RenderK0sConfig() - metadata, err := gatherVersionMetadata(k0sCfg) + metadata, err := gatherVersionMetadata(k0sCfg, !c.Bool("omit-release-metadata")) if err != nil { return fmt.Errorf("failed to gather version metadata: %w", err) } @@ -44,14 +50,21 @@ var metadataCommand = &cli.Command{ // embedded cluster. Release metadata involves the default versions of the // components that are included in the release plus the default values used // when deploying them. -func gatherVersionMetadata(k0sCfg *k0sconfig.ClusterConfig) (*types.ReleaseMetadata, error) { +func gatherVersionMetadata(k0sCfg *k0sconfig.ClusterConfig, withChannelRelease bool) (*types.ReleaseMetadata, error) { applier := addons.NewApplier( addons.WithoutPrompt(), addons.OnlyDefaults(), addons.Quiet(), ) - versionsMap, err := applier.Versions(config.AdditionalCharts()) + additionalCharts := []eckinds.Chart{} + additionalRepos := []eckinds.Repository{} + if withChannelRelease { + additionalCharts = config.AdditionalCharts() + additionalRepos = config.AdditionalRepositories() + } + + versionsMap, err := applier.Versions(additionalCharts) if err != nil { return nil, fmt.Errorf("unable to get versions: %w", err) } @@ -59,9 +72,11 @@ func gatherVersionMetadata(k0sCfg *k0sconfig.ClusterConfig) (*types.ReleaseMetad versionsMap["Installer"] = versions.Version versionsMap["Troubleshoot"] = versions.TroubleshootVersion - channelRelease, err := release.GetChannelRelease() - if err == nil && channelRelease != nil { - versionsMap[defaults.BinaryName()] = channelRelease.VersionLabel + if withChannelRelease { + channelRelease, err := release.GetChannelRelease() + if err == nil && channelRelease != nil { + versionsMap[defaults.BinaryName()] = channelRelease.VersionLabel + } } sha, err := goods.K0sBinarySHA256() @@ -93,8 +108,8 @@ func gatherVersionMetadata(k0sCfg *k0sconfig.ClusterConfig) (*types.ReleaseMetad chtconfig, repconfig, err := applier.GenerateHelmConfigs( k0sCfg, - config.AdditionalCharts(), - config.AdditionalRepositories(), + additionalCharts, + additionalRepos, ) if err != nil { return nil, fmt.Errorf("unable to apply addons: %w", err) diff --git a/e2e/cluster/lxd/cluster.go b/e2e/cluster/lxd/cluster.go index 06ef2b964..ce627cba8 100644 --- a/e2e/cluster/lxd/cluster.go +++ b/e2e/cluster/lxd/cluster.go @@ -66,6 +66,7 @@ type ClusterInput struct { T *testing.T WithProxy bool id string + AdditionalFiles []File } // File holds information about a file that must be uploaded to a node. @@ -464,6 +465,7 @@ func CopyFilesToNode(in *ClusterInput, node string) { Mode: 0755, }, } + files = append(files, in.AdditionalFiles...) for _, file := range files { CopyFileToNode(in, node, file) } diff --git a/e2e/kots-release-install/cluster-config.yaml b/e2e/kots-release-install/cluster-config.yaml index c4a610822..02b6fef2c 100644 --- a/e2e/kots-release-install/cluster-config.yaml +++ b/e2e/kots-release-install/cluster-config.yaml @@ -68,3 +68,6 @@ spec: namespace: goldpinger version: 6.1.2 order: 11 + values: | + image: + repository: proxy.replicated.com/anonymous/bloomberg/goldpinger diff --git a/e2e/kots-release-install/deployment-2.yaml b/e2e/kots-release-install/deployment-2.yaml index 41f9315c1..8b1d67023 100644 --- a/e2e/kots-release-install/deployment-2.yaml +++ b/e2e/kots-release-install/deployment-2.yaml @@ -17,7 +17,7 @@ spec: spec: containers: - name: nginx - image: nginx:1.24-alpine + image: proxy.replicated.com/anonymous/nginx:1.24-alpine resources: limits: memory: '32Mi' diff --git a/e2e/kots-release-install/deployment.yaml b/e2e/kots-release-install/deployment.yaml index f3107a402..27fd581fd 100644 --- a/e2e/kots-release-install/deployment.yaml +++ b/e2e/kots-release-install/deployment.yaml @@ -20,7 +20,7 @@ spec: spec: containers: - name: nginx - image: nginx:1.24-alpine + image: proxy.replicated.com/anonymous/nginx:1.24-alpine resources: limits: memory: '64Mi' diff --git a/e2e/kots-release-upgrade/cluster-config.yaml b/e2e/kots-release-upgrade/cluster-config.yaml index de97003d9..f839de906 100644 --- a/e2e/kots-release-upgrade/cluster-config.yaml +++ b/e2e/kots-release-upgrade/cluster-config.yaml @@ -73,10 +73,15 @@ spec: namespace: goldpinger version: 6.1.2 order: 11 + values: | + image: + repository: proxy.replicated.com/anonymous/bloomberg/goldpinger - chartname: oci://registry-1.docker.io/bitnamicharts/memcached name: memcached namespace: memcached values: | + global: + imageRegistry: proxy.replicated.com/anonymous volumePermissions: resources: requests: diff --git a/e2e/kots-release-upgrade/deployment-2.yaml b/e2e/kots-release-upgrade/deployment-2.yaml index fac9ade28..c812dafc4 100644 --- a/e2e/kots-release-upgrade/deployment-2.yaml +++ b/e2e/kots-release-upgrade/deployment-2.yaml @@ -17,7 +17,7 @@ spec: spec: containers: - name: nginx - image: nginx:1.25-alpine + image: proxy.replicated.com/anonymous/nginx:1.25-alpine resources: limits: memory: '32Mi' diff --git a/e2e/kots-release-upgrade/deployment.yaml b/e2e/kots-release-upgrade/deployment.yaml index 0187d2345..0a7182143 100644 --- a/e2e/kots-release-upgrade/deployment.yaml +++ b/e2e/kots-release-upgrade/deployment.yaml @@ -20,7 +20,7 @@ spec: spec: containers: - name: nginx - image: nginx:1.25-alpine + image: proxy.replicated.com/anonymous/nginx:1.25-alpine resources: limits: memory: '64Mi' diff --git a/e2e/version_test.go b/e2e/version_test.go index d3e6aaba7..6f69a81df 100644 --- a/e2e/version_test.go +++ b/e2e/version_test.go @@ -9,6 +9,7 @@ import ( "github.com/replicatedhq/embedded-cluster/e2e/cluster/lxd" "github.com/replicatedhq/embedded-cluster/kinds/types" + "github.com/stretchr/testify/require" ) func TestVersion(t *testing.T) { @@ -19,6 +20,13 @@ func TestVersion(t *testing.T) { CreateRegularUser: true, Image: "debian/12", EmbeddedClusterPath: "../output/bin/embedded-cluster", + AdditionalFiles: []lxd.File{ + { + SourcePath: "../output/bin/embedded-cluster-original", + DestPath: "/usr/local/bin/embedded-cluster-original", + Mode: 0755, + }, + }, }) defer tc.Cleanup() t.Logf("%s: validating 'embedded-cluster version' in node 0", time.Now().Format(time.RFC3339)) @@ -42,6 +50,19 @@ func TestVersion(t *testing.T) { return } + t.Logf("%s: validating 'embedded-cluster version metadata --omit-release-metadata' in node 0", time.Now().Format(time.RFC3339)) + line = []string{"embedded-cluster", "version", "metadata", "--omit-release-metadata"} + embedMetadata, _, err := tc.RunRegularUserCommandOnNode(t, 0, line) + if err != nil { + t.Fatalf("fail to run metadata command on node %s: %v", tc.Nodes[0], err) + } + line = []string{"embedded-cluster-original", "version", "metadata"} + noembedMetadata, _, err := tc.RunRegularUserCommandOnNode(t, 0, line) + if err != nil { + t.Fatalf("fail to run metadata command on node %s: %v", tc.Nodes[0], err) + } + require.Equal(t, noembedMetadata, embedMetadata, "metadata should be the same") + t.Logf("%s: validating 'embedded-cluster version metadata' in node 0", time.Now().Format(time.RFC3339)) line2 := []string{"embedded-cluster", "version", "metadata"} stdout, stderr, err = tc.RunRegularUserCommandOnNode(t, 0, line2) diff --git a/operator/pkg/charts/reconcile.go b/operator/pkg/charts/reconcile.go index 8ebe60f1e..f93254c9f 100644 --- a/operator/pkg/charts/reconcile.go +++ b/operator/pkg/charts/reconcile.go @@ -10,7 +10,7 @@ import ( v1beta2 "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1" "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1" "github.com/replicatedhq/embedded-cluster/operator/pkg/release" - "sigs.k8s.io/controller-runtime" + controllerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/pkg/addons/registry/registry.go b/pkg/addons/registry/registry.go index bcfd2d820..5debd2aa5 100644 --- a/pkg/addons/registry/registry.go +++ b/pkg/addons/registry/registry.go @@ -123,8 +123,13 @@ func (o *Registry) GenerateHelmConfig(provider *defaults.Provider, k0sCfg *k0sv1 // use a static cluster IP for the registry service based on the cluster CIDR range serviceCIDR := k0sv1beta1.DefaultNetwork().ServiceCIDR - if k0sCfg.Spec != nil && k0sCfg.Spec.Network != nil && k0sCfg.Spec.Network.ServiceCIDR != "" { - serviceCIDR = k0sCfg.Spec.Network.ServiceCIDR + + if !onlyDefaults { + if k0sCfg.Spec != nil && k0sCfg.Spec.Network != nil && k0sCfg.Spec.Network.ServiceCIDR != "" { + serviceCIDR = k0sCfg.Spec.Network.ServiceCIDR + } + + values["tlsSecretName"] = tlsSecretName } registryServiceIP, err := helpers.GetLowerBandIP(serviceCIDR, registryLowerBandIPIndex) @@ -135,10 +140,6 @@ func (o *Registry) GenerateHelmConfig(provider *defaults.Provider, k0sCfg *k0sv1 "clusterIP": registryServiceIP.String(), } - if !onlyDefaults { - values["tlsSecretName"] = tlsSecretName - } - valuesStringData, err := yaml.Marshal(values) if err != nil { return nil, nil, fmt.Errorf("unable to marshal helm values: %w", err)