registry: basic merge of existing registry with generated registry config

pull/453/head
iwilltry42 4 years ago
parent 4a8fcc7329
commit 267e520fce
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 2
      pkg/client/cluster.go
  2. 9
      pkg/client/registry.go
  3. 4
      tests/assets/test_registries.yaml

@ -188,6 +188,8 @@ func ClusterPrep(ctx context.Context, runtime k3drt.Runtime, clusterConfig *conf
if err != nil {
return fmt.Errorf("Failed to generate registry config file for k3s: %+v", err)
}
RegistryMergeConfig(ctx, regConf, clusterConfig.ClusterCreateOpts.Registries.Config)
log.Tracef("Merged registry config: %+v", regConf)
regConfBytes, err := yaml.Marshal(&regConf)
if err != nil {
return fmt.Errorf("Failed to marshal registry configuration: %+v", err)

@ -26,6 +26,7 @@ import (
"fmt"
"github.com/docker/go-connections/nat"
"github.com/imdario/mergo"
"github.com/rancher/k3d/v4/pkg/runtimes"
k3d "github.com/rancher/k3d/v4/pkg/types"
"github.com/rancher/k3d/v4/pkg/types/k3s"
@ -305,3 +306,11 @@ func RegistryGenerateLocalRegistryHostingConfigMapYAML(ctx context.Context, regi
return cmYaml, nil
}
// RegistryMergeConfig merges a source registry config into an existing dest registry cofnig
func RegistryMergeConfig(ctx context.Context, dest, src *k3s.Registry) error {
if err := mergo.MergeWithOverwrite(dest, src); err != nil {
return fmt.Errorf("Failed to merge registry configs: %+v", err)
}
return nil
}

@ -0,0 +1,4 @@
mirrors:
"my.company.registry":
endpoint:
- http://my.company.registry:5000
Loading…
Cancel
Save