Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow to set multiple registry mirrors by environment variable
  • Loading branch information
tldev-de committed Aug 12, 2024
1 parent 45a6d2d commit 6e2fef1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ multiple mirrors. If an image is not found on the first mirror, Kaniko will try
the next mirror(s), and at the end fallback on the default registry.

Mirror can also be defined through `KANIKO_REGISTRY_MIRROR` environment
variable.
variable. Multiple mirrors can be set by separating them with a space.

Expected format is `mirror.gcr.io` or `mirror.gcr.io/path` for example.

Expand Down
3 changes: 2 additions & 1 deletion cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func validateFlags() {

// Allow setting --registry-mirror using an environment variable.
if val, ok := os.LookupEnv("KANIKO_REGISTRY_MIRROR"); ok {
opts.RegistryMirrors.Set(val)
valSlice := strings.Split(val, " ")
opts.RegistryMirrors.SetSlice(valSlice)
}

// Allow setting --no-push using an environment variable.
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (b *multiArg) Type() string {
return "multi-arg type"
}

// This method allows to add a slice to an existing multiArg
func (b *multiArg) SetSlice(value []string) error {
logrus.Debugf("Appending slice to multi args %s", value)
*b = append(*b, value...)
return nil
}

func (b *multiArg) Contains(v string) bool {
for _, s := range *b {
if s == v {
Expand Down
18 changes: 18 additions & 0 deletions pkg/config/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ func TestMultiArg_Set_shouldAppendValue(t *testing.T) {
}
}

func TestMultiArg_SetSlice_shouldAppendValue(t *testing.T) {
var arg multiArg
arg.SetSlice([]string{"value1", "value2"})
if len(arg) != 2 || arg[0] != "value1" {
t.Error("Fist value was not appended")
}
if len(arg) != 2 || arg[1] != "value2" {
t.Error("Fist value was not appended")
}
arg.SetSlice([]string{"value3", "value4"})
if len(arg) != 4 || arg[2] != "value3" {
t.Error("Second value was not appended")
}
if len(arg) != 4 || arg[3] != "value4" {
t.Error("Second value was not appended")
}
}

func Test_KeyValueArg_Set_shouldSplitArgument(t *testing.T) {
arg := make(keyValueArg)
arg.Set("key=value")
Expand Down

0 comments on commit 6e2fef1

Please sign in to comment.