diff --git a/pkg/config/transform.go b/pkg/config/transform.go index 3abdcb16..095ff5e0 100644 --- a/pkg/config/transform.go +++ b/pkg/config/transform.go @@ -27,6 +27,7 @@ import ( "fmt" "io/ioutil" "os" + "strings" "github.com/docker/go-connections/nat" cliutil "github.com/rancher/k3d/v4/cmd/util" // TODO: move parseapiport to pkg @@ -257,18 +258,27 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim if simpleConfig.Registries.Config != "" { var k3sRegistry *k3s.Registry - registryConfigFile, err := os.Open(simpleConfig.Registries.Config) - if err != nil { - return nil, fmt.Errorf("Failed to open registry config file at %s: %+v", simpleConfig.Registries.Config, err) - } - configBytes, err := ioutil.ReadAll(registryConfigFile) - if err != nil { - return nil, fmt.Errorf("Failed to read registry config file at %s: %+v", registryConfigFile.Name(), err) + + if strings.Contains(simpleConfig.Registries.Config, "\n") { // CASE 1: embedded registries.yaml (multiline string) + log.Debugf("Found multiline registries config embedded in SimpleConfig:\n%s", simpleConfig.Registries.Config) + if err := yaml.Unmarshal([]byte(simpleConfig.Registries.Config), &k3sRegistry); err != nil { + return nil, fmt.Errorf("Failed to read embedded registries config: %+v", err) + } + } else { // CASE 2: registries.yaml file referenced by path (single line) + registryConfigFile, err := os.Open(simpleConfig.Registries.Config) + if err != nil { + return nil, fmt.Errorf("Failed to open registry config file at %s: %+v", simpleConfig.Registries.Config, err) + } + configBytes, err := ioutil.ReadAll(registryConfigFile) + if err != nil { + return nil, fmt.Errorf("Failed to read registry config file at %s: %+v", registryConfigFile.Name(), err) + } + + if err := yaml.Unmarshal(configBytes, &k3sRegistry); err != nil { + return nil, fmt.Errorf("Failed to read registry configuration: %+v", err) + } } - if err := yaml.Unmarshal(configBytes, &k3sRegistry); err != nil { - return nil, fmt.Errorf("Failed to read registry configuration: %+v", err) - } log.Tracef("Registry: read config from input:\n%+v", k3sRegistry) clusterCreateOpts.Registries.Config = k3sRegistry } diff --git a/pkg/util/filter.go b/pkg/util/filter.go index 3416e5d1..262fbf73 100644 --- a/pkg/util/filter.go +++ b/pkg/util/filter.go @@ -74,8 +74,9 @@ func FilterNodes(nodes []*k3d.Node, filters []string) ([]*k3d.Node, error) { // if one of the filters is 'all', we only return this and drop all others if submatches["group"] == "all" { - // TODO: filterNodes: only log if really more than one is specified - log.Warnf("Node filter 'all' set, but more were specified in '%+v'", filters) + if len(filters) > 1 { + log.Warnf("Node filter 'all' set, but more were specified in '%+v'", filters) + } return nodes, nil } diff --git a/tests/assets/config_test_simple.yaml b/tests/assets/config_test_simple.yaml index 6f98dc1f..dc8351e8 100644 --- a/tests/assets/config_test_simple.yaml +++ b/tests/assets/config_test_simple.yaml @@ -30,6 +30,11 @@ labels: registries: create: true use: [] + config: | + mirrors: + "my.company.registry": + endpoint: + - http://my.company.registry:5000 options: k3d: diff --git a/tests/common.sh b/tests/common.sh index 37fb218b..ae06586b 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -168,7 +168,7 @@ wait_for_pod_exec() { exec_in_node() { # $1 = container/node name # $2 = command - docker exec "$1" "$2" + docker exec "$1" sh -c "$2" } docker_assert_container_label() { diff --git a/tests/test_config_file.sh b/tests/test_config_file.sh index ef036348..f39f74a3 100755 --- a/tests/test_config_file.sh +++ b/tests/test_config_file.sh @@ -47,6 +47,11 @@ docker_assert_container_label "k3d-$clustername-server-0" "foo=bar" || failed "E info "Ensuring, that we have a registry node present" $EXE node list "k3d-$clustername-registry" || failed "Expected k3d-$clustername-registry to be present" +## merged registries.yaml +info "Ensuring, that the registries.yaml file contains both registries" +exec_in_node "k3d-$clustername-server-0" "cat /etc/rancher/k3s/registries.yaml" | grep -i "my.company.registry" || failed "Expected 'my.company.registry' to be in the /etc/rancher/k3s/registries.yaml" +exec_in_node "k3d-$clustername-server-0" "cat /etc/rancher/k3s/registries.yaml" | grep -i "k3d-$clustername-registry" || failed "Expected 'k3d-$clustername-registry' to be in the /etc/rancher/k3s/registries.yaml" + # Cleanup info "Deleting cluster $clustername..."