From cc74792ace4ef596a22d5ad6ce195a4755319b21 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Tue, 31 Oct 2023 17:08:03 +0100 Subject: [PATCH] Only include envoy image in default config if images should be included See: 9f02f276f ("Removes images in k0s config create by default") Signed-off-by: Tom Wieczorek (cherry picked from commit 8d09614c41540375eedae3712bd9f78b9a65da13) (cherry picked from commit 35901da65422fb712f4bb57c4d1707cd30c4fe46) --- cmd/config/create.go | 1 + cmd/config/create_test.go | 65 ++++++++++++++++++++++ docs/configuration.md | 3 - pkg/apis/k0s.k0sproject.io/v1beta1/nllb.go | 2 +- 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 cmd/config/create_test.go diff --git a/cmd/config/create.go b/cmd/config/create.go index 8665c710de9b..d7282c320e4c 100644 --- a/cmd/config/create.go +++ b/cmd/config/create.go @@ -36,6 +36,7 @@ func NewCreateCmd() *cobra.Command { config := v1beta1.DefaultClusterConfig() if !includeImages { config.Spec.Images = nil + config.Spec.Network.NodeLocalLoadBalancing.EnvoyProxy.Image = nil } cfg, err := yaml.Marshal(config) diff --git a/cmd/config/create_test.go b/cmd/config/create_test.go new file mode 100644 index 000000000000..952241d4e029 --- /dev/null +++ b/cmd/config/create_test.go @@ -0,0 +1,65 @@ +/* +Copyright 2023 k0s authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package config_test + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/k0sproject/k0s/cmd/config" +) + +func TestCreateCmd_Images(t *testing.T) { + for _, test := range []struct { + name string + args []string + check func(t *testing.T, cfg, needle string) + }{ + { + "default", []string{}, + func(t *testing.T, cfg, needle string) { t.Helper(); assert.NotContains(t, cfg, needle) }, + }, + + { + "include_images", []string{"--include-images"}, + func(t *testing.T, cfg, needle string) { t.Helper(); assert.Contains(t, cfg, needle) }, + }, + } { + t.Run(test.name, func(t *testing.T) { + underTest := config.NewCreateCmd() + + var out strings.Builder + var err strings.Builder + underTest.SetArgs(test.args) + underTest.SetOut(&out) + underTest.SetErr(&err) + + assert.NoError(t, underTest.Execute()) + + assert.Empty(t, err.String(), "Something has been written to stderr") + // This is a very broad check if there's some ImageSpec in the output. May + // produce false positives if something similar gets added to the config in + // the future. Can be refined then. + cfg := out.String() + test.check(t, cfg, "quay.io/k0sproject") + test.check(t, cfg, "image: ") + test.check(t, cfg, "version: ") + }) + } +} diff --git a/docs/configuration.md b/docs/configuration.md index 46e33d4debfb..30869eb56f8d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -96,9 +96,6 @@ spec: enabled: false envoyProxy: apiServerBindPort: 7443 - image: - image: docker.io/envoyproxy/envoy-distroless - version: v1.24.1 konnectivityServerBindPort: 7132 type: EnvoyProxy podCIDR: 10.244.0.0/16 diff --git a/pkg/apis/k0s.k0sproject.io/v1beta1/nllb.go b/pkg/apis/k0s.k0sproject.io/v1beta1/nllb.go index 12e41e9b4c6f..c93bb1b9d3e8 100644 --- a/pkg/apis/k0s.k0sproject.io/v1beta1/nllb.go +++ b/pkg/apis/k0s.k0sproject.io/v1beta1/nllb.go @@ -116,7 +116,7 @@ func (n *NodeLocalLoadBalancing) IsEnabled() bool { type EnvoyProxy struct { // image specifies the OCI image that's being used for the Envoy Pod. // +optional - Image *ImageSpec `json:"image"` + Image *ImageSpec `json:"image,omitempty"` // imagePullPolicy specifies the pull policy being used for the Envoy Pod. // Defaults to the default image pull policy.