Skip to content

Commit

Permalink
Add rewrites map to mirrors struct, initialize empty map for k3d side…
Browse files Browse the repository at this point in the history
… of config

- This will allow for passing through mirror config via the config block
- This wont allow rewrites to be configured as part of a k3d config file, only via registries.yaml (inline or not)
  • Loading branch information
maxsargentdev committed Feb 9, 2023
1 parent 64ba96a commit 59af952
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/client/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func RegistryConnectNetworks(ctx context.Context, runtime runtimes.Runtime, regi
// RegistryGenerateK3sConfig generates the k3s specific registries.yaml configuration for multiple registries
func RegistryGenerateK3sConfig(ctx context.Context, registries []*k3d.Registry) (*k3s.Registry, error) {
regConf := &k3s.Registry{}
rewritesConf := make(map[string]string)

for _, reg := range registries {
internalAddress := fmt.Sprintf("%s:%s", reg.Host, reg.ExposureOpts.Port.Port())
Expand All @@ -205,18 +206,21 @@ func RegistryGenerateK3sConfig(ctx context.Context, registries []*k3d.Registry)
Endpoints: []string{
fmt.Sprintf("http://%s", internalAddress),
},
Rewrites: rewritesConf,
}

regConf.Mirrors[internalAddress] = k3s.Mirror{
Endpoints: []string{
fmt.Sprintf("http://%s", internalAddress),
},
Rewrites: rewritesConf, // stub out rewrites so we dont override with nil
}

if reg.Options.Proxy.RemoteURL != "" {
regConf.Mirrors[reg.Options.Proxy.RemoteURL] = k3s.Mirror{
Endpoints: []string{fmt.Sprintf("http://%s", internalAddress)},
}

}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/types/k3s/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type Mirror struct {
// with host specified.
// The scheme, host and path from the endpoint URL will be used.
Endpoints []string `toml:"endpoint" json:"endpoint"`
// Rewrites are rewrite rules for a registry. Rewrites change the tag of an
// image based on a regular expression. When using mirrors this can be helpful
// structure / organization of the mirror differs to the upstream.
Rewrites map[string]string `toml:"rewrite" json:"rewrite"`
}

// AuthConfig contains the config related to authentication to a specific registry
Expand Down

0 comments on commit 59af952

Please sign in to comment.