Skip to content

Commit a008fad

Browse files
authored
Merge branch 'main' into fix/endless-loop
2 parents e9307f0 + dd0e73c commit a008fad

File tree

77 files changed

+240
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+240
-200
lines changed

cmd/sonobuoy/app/args.go

+49-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const (
5050
e2eSkipFlag = "e2e-skip"
5151
e2eParallelFlag = "e2e-parallel"
5252
e2eRegistryConfigFlag = "e2e-repo-config"
53+
e2eDockerConfigFileFlag = "e2e-docker-config-file"
5354
e2eRegistryFlag = "e2e-repo"
5455
pluginImageFlag = "plugin-image"
5556
filenameFlag = "filename"
@@ -224,7 +225,7 @@ func AddSonobuoyConfigFlag(cfg *SonobuoyConfig, flags *pflag.FlagSet) {
224225
// AddLegacyE2EFlags is a way to add flags which target the e2e plugin specifically
225226
// by leveraging the existing flags. They typically wrap other fields (like the env var
226227
// overrides) and modify those.
227-
func AddLegacyE2EFlags(env *PluginEnvVars, pluginTransforms *map[string][]func(*manifest.Manifest) error, fs *pflag.FlagSet) {
228+
func AddLegacyE2EFlags(cfg *SonobuoyConfig, env *PluginEnvVars, pluginTransforms *map[string][]func(*manifest.Manifest) error, fs *pflag.FlagSet) {
228229
m := &Mode{
229230
env: env,
230231
name: "",
@@ -289,6 +290,15 @@ func AddLegacyE2EFlags(env *PluginEnvVars, pluginTransforms *map[string][]func(*
289290
&envVarModierFlag{plugin: e2ePlugin, field: "KUBE_TEST_REPO", PluginEnvVars: *env}, e2eRegistryFlag,
290291
"Specify a registry to use as the default for pulling Kubernetes test images. Same as providing --e2e-repo-config but specifying the same repo repeatedly.",
291292
)
293+
294+
fs.Var(
295+
&e2eDockerConfigFlag{
296+
plugin: e2ePlugin,
297+
config: cfg,
298+
transforms: *pluginTransforms,
299+
}, e2eDockerConfigFileFlag,
300+
"A docker credentials configuration file used which contains authorization token that can be used to pull images from certain private registries provided by the users",
301+
)
292302
}
293303

294304
// AddRBACModeFlags adds an E2E Argument with the provided default.
@@ -563,9 +573,11 @@ func (f *e2eRepoFlag) Set(str string) error {
563573
}
564574

565575
f.transforms[f.plugin] = append(f.transforms[f.plugin], func(m *manifest.Manifest) error {
566-
m.ConfigMap = map[string]string{
567-
name: string(fData),
576+
if m.ConfigMap == nil {
577+
m.ConfigMap = map[string]string{}
568578
}
579+
m.ConfigMap[name] = string(fData)
580+
569581
m.Spec.Env = append(m.Spec.Env, corev1.EnvVar{
570582
Name: "KUBE_TEST_REPO_LIST",
571583
Value: fmt.Sprintf("/tmp/sonobuoy/config/%v", name),
@@ -575,6 +587,40 @@ func (f *e2eRepoFlag) Set(str string) error {
575587
return nil
576588
}
577589

590+
type e2eDockerConfigFlag struct {
591+
plugin string
592+
filename string
593+
config *SonobuoyConfig
594+
595+
transforms map[string][]func(*manifest.Manifest) error
596+
// Value to put in the configmap as the filename. Defaults to filename.
597+
filenameOverride string
598+
}
599+
600+
func (f *e2eDockerConfigFlag) String() string { return f.filename }
601+
func (f *e2eDockerConfigFlag) Type() string { return "json-filepath" }
602+
func (f *e2eDockerConfigFlag) Set(str string) error {
603+
f.config.E2EDockerConfigFile = str
604+
name := filepath.Base(str)
605+
if len(f.filenameOverride) > 0 {
606+
name = f.filenameOverride
607+
}
608+
fData, err := os.ReadFile(str)
609+
if err != nil {
610+
return errors.Wrapf(err, "failed to read file %q", str)
611+
}
612+
613+
f.transforms[e2ePlugin] = append(f.transforms[e2ePlugin], func(m *manifest.Manifest) error {
614+
if m.ConfigMap == nil {
615+
m.ConfigMap = map[string]string{}
616+
}
617+
m.ConfigMap[name] = string(fData)
618+
return nil
619+
620+
})
621+
return nil
622+
}
623+
578624
// The ssh-key flag needs to store the path to the ssh key but also
579625
// wire up the e2e plugin for using it.
580626
type sshPathFlag struct {

cmd/sonobuoy/app/gen.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ package app
2121
import (
2222
"fmt"
2323
"os"
24+
"strconv"
25+
"strings"
2426
"time"
2527

2628
"github.com/vmware-tanzu/sonobuoy/pkg/client"
@@ -94,7 +96,7 @@ func GenFlagSet(cfg *genFlags, rbac RBACMode) *pflag.FlagSet {
9496

9597
AddPluginSetFlag(&cfg.plugins, genset)
9698
AddPluginEnvFlag(&cfg.pluginEnvs, genset)
97-
AddLegacyE2EFlags(&cfg.pluginEnvs, &cfg.pluginTransforms, genset)
99+
AddLegacyE2EFlags(&cfg.sonobuoyConfig, &cfg.pluginEnvs, &cfg.pluginTransforms, genset)
98100

99101
AddNodeSelectorsFlag(&cfg.nodeSelectors, genset)
100102

@@ -165,6 +167,15 @@ func (g *genFlags) Config() (*client.GenConfig, error) {
165167
k8sVersion = g.k8sVersion.String()
166168
}
167169

170+
if g.sonobuoyConfig.E2EDockerConfigFile != "" {
171+
if err := verifyKubernetesVersion(k8sVersion); err != nil {
172+
return nil, err
173+
}
174+
if g.sonobuoyConfig.ImagePullSecrets == "" {
175+
g.sonobuoyConfig.ImagePullSecrets = "auth-repo-cred"
176+
}
177+
}
178+
168179
return &client.GenConfig{
169180
Config: &g.sonobuoyConfig.Config,
170181
EnableRBAC: rbacEnabled,
@@ -207,6 +218,7 @@ func NewCmdGen() *cobra.Command {
207218
Args: cobra.ExactArgs(0),
208219
}
209220
GenCommand.Flags().AddFlagSet(GenFlagSet(&genflags, EnabledRBACMode))
221+
210222
return GenCommand
211223
}
212224

@@ -261,3 +273,25 @@ func getClient(kubeconfig *Kubeconfig) (*kubernetes.Clientset, error) {
261273

262274
return client, kubeError
263275
}
276+
277+
func verifyKubernetesVersion(k8sVersion string) error {
278+
parts := versionMatchRE.FindStringSubmatch(k8sVersion)
279+
if parts == nil {
280+
return fmt.Errorf("could not parse %q as version", k8sVersion)
281+
}
282+
numbers, _ := parts[1], parts[2]
283+
284+
versionInfo := strings.Split(numbers, ".")
285+
minorVersion := versionInfo[1]
286+
287+
minorVersionInt, err := strconv.ParseInt(minorVersion, 10, 0)
288+
if err != nil {
289+
return err
290+
}
291+
292+
if minorVersionInt < 27 {
293+
err = fmt.Errorf("e2e-docker-config-file is only supported for Kubernetes 1.27 or later")
294+
}
295+
296+
return err
297+
}

cmd/sonobuoy/app/gen_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright the Sonobuoy contributors 2019
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package app
17+
18+
import (
19+
"testing"
20+
)
21+
22+
func TestVerifyKubernetesVersion(t *testing.T) {
23+
testCases := []struct {
24+
desc string
25+
k8sVersion string
26+
expectErr string
27+
}{
28+
{
29+
desc: "Usage of e2e-docker-config-file flag with Kubernetes versions below 1.27 should throw error",
30+
k8sVersion: "1.26-alpha-3",
31+
expectErr: "e2e-docker-config-file is only supported for Kubernetes 1.27 or later",
32+
},
33+
{
34+
desc: "Usage of e2e-docker-config-file flag along with Kubernetes versions 1.27 or later should work as expected",
35+
k8sVersion: "1.27",
36+
},
37+
}
38+
39+
for _, testCase := range testCases {
40+
t.Run(testCase.desc, func(t *testing.T) {
41+
err := verifyKubernetesVersion(testCase.k8sVersion)
42+
if err != nil {
43+
if len(testCase.expectErr) == 0 {
44+
t.Fatalf("Expected nil error but got %v", err)
45+
}
46+
if err.Error() != testCase.expectErr {
47+
t.Fatalf("Expected error %q but got %q", err, testCase.expectErr)
48+
}
49+
}
50+
})
51+
52+
}
53+
}

cmd/sonobuoy/app/images.go

-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ func translateRegistry(imageURL string, customRegistry string, customRegistryLis
451451
if len(customRegistry) > 0 {
452452
return fmt.Sprintf("%s/%s", customRegistry, parts[countParts-1])
453453
}
454-
455454
// For now, if not given a customRegistry, assume they gave the customRegistryList as non-nil.
456455
switch registryAndUser {
457456
case "gcr.io/e2e-test-images":

cmd/sonobuoy/app/root.go

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"errors"
2121
"flag"
2222
"fmt"
23+
"regexp"
2324
"sync"
2425

2526
"github.com/sirupsen/logrus"
@@ -34,6 +35,10 @@ import (
3435
// and cause a panic otherwise.
3536
var once sync.Once
3637

38+
// versionMatchRE splits a version string into numeric and "extra" parts
39+
// source: https://github.com/kubernetes/kubernetes/blob/af1bf4306709020ed2002618e099b3d0acf3c7b5/staging/src/k8s.io/apimachinery/pkg/util/version/version.go#L37
40+
var versionMatchRE = regexp.MustCompile(`^\s*v?([0-9]+(?:\.[0-9]+)*)(.*)*$`)
41+
3742
func NewSonobuoyCommand() *cobra.Command {
3843
cmds := &cobra.Command{
3944
Use: "sonobuoy",
@@ -106,8 +111,10 @@ func prerunChecks(cmd *cobra.Command, args []string) error {
106111
// Getting a list of all flags provided by the user.
107112
flagsSet := map[string]bool{}
108113
flagsDebug := []string{}
114+
flagArgs := map[string]string{}
109115
cmd.Flags().Visit(func(f *pflag.Flag) {
110116
flagsSet[f.Name] = true
117+
flagArgs[f.Name] = f.Value.String()
111118
flagsDebug = append(flagsDebug, fmt.Sprintf("%v=%v", f.Name, f.Value.String()))
112119
})
113120

@@ -135,6 +142,13 @@ func prerunChecks(cmd *cobra.Command, args []string) error {
135142
return fmt.Errorf("%v and %v flags are both set and may collide", e2eRegistryConfigFlag, e2eRegistryFlag)
136143
}
137144

145+
if flagsSet[e2eDockerConfigFileFlag] && flagsSet["kubernetes-version"] {
146+
k8sVersion := flagArgs["kubernetes-version"]
147+
if err := verifyKubernetesVersion(k8sVersion); err != nil {
148+
return err
149+
}
150+
}
151+
138152
return nil
139153
}
140154

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ require (
1616
github.com/spf13/pflag v1.0.5
1717
github.com/spf13/viper v1.14.0
1818
golang.org/x/sync v0.1.0
19-
golang.org/x/term v0.6.0
20-
golang.org/x/text v0.8.0
19+
golang.org/x/term v0.13.0
20+
golang.org/x/text v0.13.0
2121
gopkg.in/yaml.v2 v2.4.0
2222
gopkg.in/yaml.v3 v3.0.1
2323
k8s.io/api v0.27.1
@@ -65,9 +65,9 @@ require (
6565
github.com/spf13/cast v1.5.0 // indirect
6666
github.com/spf13/jwalterweatherman v1.1.0 // indirect
6767
github.com/subosito/gotenv v1.4.1 // indirect
68-
golang.org/x/net v0.8.0 // indirect
68+
golang.org/x/net v0.17.0 // indirect
6969
golang.org/x/oauth2 v0.3.0 // indirect
70-
golang.org/x/sys v0.6.0 // indirect
70+
golang.org/x/sys v0.13.0 // indirect
7171
golang.org/x/time v0.3.0 // indirect
7272
google.golang.org/appengine v1.6.7 // indirect
7373
google.golang.org/protobuf v1.28.1 // indirect

go.sum

+8-8
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v
365365
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
366366
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
367367
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
368-
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
369-
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
368+
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
369+
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
370370
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
371371
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
372372
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -433,11 +433,11 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
433433
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
434434
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
435435
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
436-
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
437-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
436+
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
437+
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
438438
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
439-
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
440-
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
439+
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
440+
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
441441
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
442442
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
443443
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -446,8 +446,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
446446
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
447447
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
448448
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
449-
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
450-
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
449+
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
450+
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
451451
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
452452
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
453453
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

0 commit comments

Comments
 (0)