Skip to content

Commit

Permalink
Merge pull request #2159 from liangzai006/master
Browse files Browse the repository at this point in the history
support multi-level image warehouse path push
  • Loading branch information
ks-ci-bot authored Mar 8, 2024
2 parents 57ce3d3 + 7253b4a commit 5b42db3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
9 changes: 8 additions & 1 deletion cmd/kk/apis/kubekey/v1alpha2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (cfg *ClusterSpec) GenerateCertSANs() []string {
if InternalIPv4Address != host.Address && InternalIPv4Address != cfg.ControlPlaneEndpoint.Address {
extraCertSANs = append(extraCertSANs, InternalIPv4Address)
}
if len(nodeAddresses)==2 {
if len(nodeAddresses) == 2 {
InternalIPv6Address := nodeAddresses[1]
extraCertSANs = append(extraCertSANs, InternalIPv6Address)
}
Expand Down Expand Up @@ -310,3 +310,10 @@ func (c *ControlPlaneEndpoint) EnableExternalDNS() bool {
}
return *c.ExternalDNS
}

func (r *RegistryConfig) GetHost() string {
if r.PrivateRegistry == "" {
return ""
}
return strings.Split(r.PrivateRegistry, "/")[0]
}
4 changes: 2 additions & 2 deletions cmd/kk/pkg/bootstrap/os/templates/init_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ func GenerateHosts(runtime connector.ModuleRuntime, kubeConf *common.KubeConf) [

if len(runtime.GetHostsByRole(common.Registry)) > 0 {
if kubeConf.Cluster.Registry.PrivateRegistry != "" {
hostsList = append(hostsList, fmt.Sprintf("%s %s", runtime.GetHostsByRole(common.Registry)[0].GetInternalIPv4Address(), kubeConf.Cluster.Registry.PrivateRegistry))
hostsList = append(hostsList, fmt.Sprintf("%s %s", runtime.GetHostsByRole(common.Registry)[0].GetInternalIPv4Address(), kubeConf.Cluster.Registry.GetHost()))
if runtime.GetHostsByRole(common.Registry)[0].GetInternalIPv6Address() != "" {
hostsList = append(hostsList, fmt.Sprintf("%s %s", runtime.GetHostsByRole(common.Registry)[0].GetInternalIPv6Address(), kubeConf.Cluster.Registry.PrivateRegistry))
hostsList = append(hostsList, fmt.Sprintf("%s %s", runtime.GetHostsByRole(common.Registry)[0].GetInternalIPv6Address(), kubeConf.Cluster.Registry.GetHost()))
}

} else {
Expand Down
6 changes: 3 additions & 3 deletions cmd/kk/pkg/bootstrap/registry/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (g *GenerateCerts) Execute(runtime connector.Runtime) error {

var altName cert.AltNames

dnsList := []string{"localhost", g.KubeConf.Cluster.Registry.PrivateRegistry}
dnsList := []string{"localhost", g.KubeConf.Cluster.Registry.GetHost()}
ipList := []net.IP{net.IPv4(127, 0, 0, 1), net.IPv6loopback}

for _, h := range runtime.GetHostsByRole(common.Registry) {
Expand All @@ -115,13 +115,13 @@ func (g *GenerateCerts) Execute(runtime connector.Runtime) error {
altName.DNSNames = dnsList
altName.IPs = ipList

files := []string{"ca.pem", "ca-key.pem", fmt.Sprintf("%s.pem", g.KubeConf.Cluster.Registry.PrivateRegistry), fmt.Sprintf("%s-key.pem", g.KubeConf.Cluster.Registry.PrivateRegistry)}
files := []string{"ca.pem", "ca-key.pem", fmt.Sprintf("%s.pem", g.KubeConf.Cluster.Registry.GetHost()), fmt.Sprintf("%s-key.pem", g.KubeConf.Cluster.Registry.GetHost())}

// CA
certsList := []*certs.KubekeyCert{KubekeyCertRegistryCA()}

// Certs
certsList = append(certsList, KubekeyCertRegistryServer(g.KubeConf.Cluster.Registry.PrivateRegistry, &altName))
certsList = append(certsList, KubekeyCertRegistryServer(g.KubeConf.Cluster.Registry.GetHost(), &altName))

var lastCACert *certs.KubekeyCert
for _, c := range certsList {
Expand Down
12 changes: 6 additions & 6 deletions cmd/kk/pkg/bootstrap/registry/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func InstallRegistry(i *InstallRegistryModule) []task.Interface {
Template: templates.RegistryConfigTempl,
Dst: "/etc/kubekey/registry/config.yaml",
Data: util.Data{
"Certificate": fmt.Sprintf("%s.pem", i.KubeConf.Cluster.Registry.PrivateRegistry),
"Key": fmt.Sprintf("%s-key.pem", i.KubeConf.Cluster.Registry.PrivateRegistry),
"Certificate": fmt.Sprintf("%s.pem", i.KubeConf.Cluster.Registry.GetHost()),
"Key": fmt.Sprintf("%s-key.pem", i.KubeConf.Cluster.Registry.GetHost()),
},
},
Parallel: true,
Expand Down Expand Up @@ -250,10 +250,10 @@ func InstallHarbor(i *InstallRegistryModule) []task.Interface {
}

generateHarborConfig := &task.RemoteTask{
Name: "GenerateHarborConfig",
Desc: "Generate harbor config",
Hosts: i.Runtime.GetHostsByRole(common.Registry),
Action: new(GenerateHarborConfig),
Name: "GenerateHarborConfig",
Desc: "Generate harbor config",
Hosts: i.Runtime.GetHostsByRole(common.Registry),
Action: new(GenerateHarborConfig),
Parallel: true,
Retry: 1,
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/kk/pkg/bootstrap/registry/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *SyncCertsToAllNodes) Execute(runtime connector.Runtime) error {
}
}

if err := runtime.GetRunner().SudoScp(filepath.Join(dir, fileName), filepath.Join(filepath.Join("/etc/docker/certs.d", s.KubeConf.Cluster.Registry.PrivateRegistry), dstFileName)); err != nil {
if err := runtime.GetRunner().SudoScp(filepath.Join(dir, fileName), filepath.Join(filepath.Join("/etc/docker/certs.d", s.KubeConf.Cluster.Registry.GetHost()), dstFileName)); err != nil {
return errors.Wrap(errors.WithStack(err), "scp registry certs file to /etc/docker/certs.d/ failed")
}

Expand Down Expand Up @@ -144,7 +144,7 @@ func (g *StartRegistryService) Execute(runtime connector.Runtime) error {
}

fmt.Println()
fmt.Println(fmt.Sprintf("Local image registry created successfully. Address: %s", g.KubeConf.Cluster.Registry.PrivateRegistry))
fmt.Println(fmt.Sprintf("Local image registry created successfully. Address: %s", g.KubeConf.Cluster.Registry.GetHost()))
fmt.Println()

return nil
Expand Down Expand Up @@ -221,7 +221,7 @@ type GenerateHarborConfig struct {
}

func (g *GenerateHarborConfig) Execute(runtime connector.Runtime) error {
registryDomain := g.KubeConf.Cluster.Registry.PrivateRegistry
registryDomain := g.KubeConf.Cluster.Registry.GetHost()

if g.KubeConf.Cluster.Registry.Type == "harbor-ha" {
host := runtime.RemoteHost()
Expand All @@ -233,9 +233,9 @@ func (g *GenerateHarborConfig) Execute(runtime connector.Runtime) error {
Dst: "/opt/harbor/harbor.yml",
Data: util.Data{
"Domain": registryDomain,
"Certificate": fmt.Sprintf("%s.pem", g.KubeConf.Cluster.Registry.PrivateRegistry),
"Key": fmt.Sprintf("%s-key.pem", g.KubeConf.Cluster.Registry.PrivateRegistry),
"Password": templates.Password(g.KubeConf, g.KubeConf.Cluster.Registry.PrivateRegistry),
"Certificate": fmt.Sprintf("%s.pem", g.KubeConf.Cluster.Registry.GetHost()),
"Key": fmt.Sprintf("%s-key.pem", g.KubeConf.Cluster.Registry.GetHost()),
"Password": templates.Password(g.KubeConf, g.KubeConf.Cluster.Registry.GetHost()),
},
}
templateAction.Init(nil, nil)
Expand All @@ -256,7 +256,7 @@ func (g *StartHarbor) Execute(runtime connector.Runtime) error {
}

fmt.Println()
fmt.Println(fmt.Sprintf("Local image registry created successfully. Address: %s", g.KubeConf.Cluster.Registry.PrivateRegistry))
fmt.Println(fmt.Sprintf("Local image registry created successfully. Address: %s", g.KubeConf.Cluster.Registry.GetHost()))
fmt.Println()

return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/kk/pkg/images/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *CopyImagesToRegistry) Execute(runtime connector.Runtime) error {
}

auth := new(registry.DockerRegistryEntry)
if config, ok := auths[c.KubeConf.Cluster.Registry.PrivateRegistry]; ok {
if config, ok := auths[c.KubeConf.Cluster.Registry.GetHost()]; ok {
auth = config
}

Expand Down

0 comments on commit 5b42db3

Please sign in to comment.