Skip to content

Commit

Permalink
fix: duplicate helm extensions in clusterconfig (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh authored Oct 15, 2024
1 parent cfc970c commit 883aa95
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 21 deletions.
4 changes: 3 additions & 1 deletion cmd/embedded-cluster/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/embedded-cluster/list_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
31 changes: 23 additions & 8 deletions cmd/embedded-cluster/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -44,24 +50,33 @@ 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)
}
versionsMap["Kubernetes"] = versions.K0sVersion
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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions e2e/cluster/lxd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions e2e/kots-release-install/cluster-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ spec:
namespace: goldpinger
version: 6.1.2
order: 11
values: |
image:
repository: proxy.replicated.com/anonymous/bloomberg/goldpinger
2 changes: 1 addition & 1 deletion e2e/kots-release-install/deployment-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion e2e/kots-release-install/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions e2e/kots-release-upgrade/cluster-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion e2e/kots-release-upgrade/deployment-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion e2e/kots-release-upgrade/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 21 additions & 0 deletions e2e/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/charts/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
13 changes: 7 additions & 6 deletions pkg/addons/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 883aa95

Please sign in to comment.