Skip to content

Commit

Permalink
Only include envoy image in default config if images should be included
Browse files Browse the repository at this point in the history
See: 9f02f27 ("Removes images in k0s config create by default")
Signed-off-by: Tom Wieczorek <[email protected]>
(cherry picked from commit 8d09614)
(cherry picked from commit 35901da)
  • Loading branch information
twz123 authored and github-actions[bot] committed Nov 1, 2023
1 parent a7b301f commit cc74792
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
65 changes: 65 additions & 0 deletions cmd/config/create_test.go
Original file line number Diff line number Diff line change
@@ -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: ")
})
}
}
3 changes: 0 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/k0s.k0sproject.io/v1beta1/nllb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cc74792

Please sign in to comment.