2023-12-06 00:25:49 +00:00
|
|
|
package spegel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2024-01-31 18:09:43 +00:00
|
|
|
"github.com/containerd/containerd/remotes/docker"
|
2023-12-06 00:25:49 +00:00
|
|
|
"github.com/k3s-io/k3s/pkg/daemons/config"
|
|
|
|
"github.com/rancher/wharfie/pkg/registries"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InjectMirror configures TLS for the registry mirror client, and adds the mirror address as an endpoint
|
|
|
|
// to all configured registries.
|
|
|
|
func (c *Config) InjectMirror(nodeConfig *config.Node) error {
|
|
|
|
mirrorAddr := net.JoinHostPort(c.InternalAddress, c.RegistryPort)
|
2024-01-31 18:09:43 +00:00
|
|
|
mirrorURL := "https://" + mirrorAddr + "/v2"
|
2023-12-06 00:25:49 +00:00
|
|
|
registry := nodeConfig.AgentConfig.Registry
|
|
|
|
|
|
|
|
if registry.Configs == nil {
|
|
|
|
registry.Configs = map[string]registries.RegistryConfig{}
|
|
|
|
}
|
|
|
|
registry.Configs[mirrorAddr] = registries.RegistryConfig{
|
|
|
|
TLS: ®istries.TLSConfig{
|
|
|
|
CAFile: c.ServerCAFile,
|
|
|
|
CertFile: c.ClientCertFile,
|
|
|
|
KeyFile: c.ClientKeyFile,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if registry.Mirrors == nil {
|
|
|
|
registry.Mirrors = map[string]registries.Mirror{}
|
|
|
|
}
|
|
|
|
for host, mirror := range registry.Mirrors {
|
2024-01-31 18:09:43 +00:00
|
|
|
// Don't handle wildcard or local registry entries
|
|
|
|
if host != "*" && !docker.IsLocalhost(host) {
|
|
|
|
mirror.Endpoints = append([]string{mirrorURL}, mirror.Endpoints...)
|
2023-12-06 00:25:49 +00:00
|
|
|
registry.Mirrors[host] = mirror
|
|
|
|
}
|
|
|
|
}
|
2024-01-31 18:09:43 +00:00
|
|
|
registry.Mirrors[mirrorAddr] = registries.Mirror{
|
|
|
|
Endpoints: []string{mirrorURL},
|
|
|
|
}
|
2023-12-06 00:25:49 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|