unify the registry type
This commit is contained in:
parent
621640c901
commit
d042c79df2
@ -113,5 +113,5 @@ func parseCreateRegistryCmd(cmd *cobra.Command, args []string, flags *regCreateF
|
||||
registryName = fmt.Sprintf("%s-%s", k3d.DefaultObjectNamePrefix, args[0])
|
||||
}
|
||||
|
||||
return &k3d.Registry{Host: registryName, Image: flags.Image, Port: exposePort}, clusters
|
||||
return &k3d.Registry{Host: registryName, Image: flags.Image, Port: k3d.MappedPort{InternalPort: k3d.DefaultRegistryPort, ExternalPort: exposePort}}, clusters
|
||||
}
|
||||
|
@ -136,20 +136,17 @@ func ClusterPrep(ctx context.Context, runtime k3drt.Runtime, clusterConfig *conf
|
||||
* Step 3: Registries
|
||||
*/
|
||||
|
||||
// Create managed registry bound to this cluster
|
||||
if clusterConfig.ClusterCreateOpts.Registries.Create != nil {
|
||||
regNode, err := RegistryCreate(ctx, runtime, clusterConfig.ClusterCreateOpts.Registries.Create)
|
||||
if err != nil {
|
||||
if _, err := RegistryCreate(ctx, runtime, clusterConfig.ClusterCreateOpts.Registries.Create); err != nil {
|
||||
return fmt.Errorf("Failed to create registry: %+v", err)
|
||||
}
|
||||
|
||||
clusterConfig.ClusterCreateOpts.Registries.Use = append(clusterConfig.ClusterCreateOpts.Registries.Use, &k3d.ExternalRegistry{
|
||||
Host: regNode.Name,
|
||||
Port: k3d.DefaultRegistryPort,
|
||||
ExternalPort: clusterConfig.ClusterCreateOpts.Registries.Create.Port.Port,
|
||||
})
|
||||
clusterConfig.ClusterCreateOpts.Registries.Use = append(clusterConfig.ClusterCreateOpts.Registries.Use, clusterConfig.ClusterCreateOpts.Registries.Create)
|
||||
}
|
||||
|
||||
log.Debugf("External Registries: %+v", clusterConfig.ClusterCreateOpts.Registries.Use)
|
||||
// Use existing registries (including the new one, if created)
|
||||
log.Debugf("Using Registries: %+v", clusterConfig.ClusterCreateOpts.Registries.Use)
|
||||
|
||||
if len(clusterConfig.ClusterCreateOpts.Registries.Use) > 0 {
|
||||
// ensure that all selected registries exist and connect them to the cluster network
|
||||
@ -164,7 +161,7 @@ func ClusterPrep(ctx context.Context, runtime k3drt.Runtime, clusterConfig *conf
|
||||
}
|
||||
|
||||
// generate the registries.yaml
|
||||
regConf, err := RegistryGenerateK3sConfig(ctx, clusterConfig.ClusterCreateOpts.Registries.Create, clusterConfig.ClusterCreateOpts.Registries.Use)
|
||||
regConf, err := RegistryGenerateK3sConfig(ctx, clusterConfig.ClusterCreateOpts.Registries.Use)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to generate registry config file for k3s: %+v", err)
|
||||
}
|
||||
|
@ -72,9 +72,9 @@ func RegistryCreate(ctx context.Context, runtime runtimes.Runtime, reg *k3d.Regi
|
||||
// setup the node labels
|
||||
registryNode.Labels = map[string]string{
|
||||
k3d.LabelRole: string(k3d.RegistryRole),
|
||||
k3d.LabelRegistryHost: reg.Port.Host, // TODO: docker machine host?
|
||||
k3d.LabelRegistryHostIP: reg.Port.HostIP,
|
||||
k3d.LabelRegistryPort: reg.Port.Port,
|
||||
k3d.LabelRegistryHost: reg.Port.ExternalPort.Host, // TODO: docker machine host?
|
||||
k3d.LabelRegistryHostIP: reg.Port.ExternalPort.HostIP,
|
||||
k3d.LabelRegistryPort: reg.Port.ExternalPort.Port,
|
||||
}
|
||||
for k, v := range k3d.DefaultObjectLabels {
|
||||
registryNode.Labels[k] = v
|
||||
@ -82,7 +82,7 @@ func RegistryCreate(ctx context.Context, runtime runtimes.Runtime, reg *k3d.Regi
|
||||
|
||||
// port
|
||||
registryNode.Ports = []string{
|
||||
fmt.Sprintf("%s:%s:%s/tcp", reg.Port.HostIP, reg.Port.Port, k3d.DefaultRegistryPort),
|
||||
fmt.Sprintf("%s:%s:%s/tcp", reg.Port.ExternalPort.HostIP, reg.Port.ExternalPort.Port, k3d.DefaultRegistryPort),
|
||||
}
|
||||
|
||||
// create the registry node
|
||||
@ -132,12 +132,12 @@ func RegistryConnect(ctx context.Context, runtime runtimes.Runtime, registryNode
|
||||
}
|
||||
|
||||
// RegistryGenerateK3sConfig generates the k3s specific registries.yaml configuration for multiple registries
|
||||
func RegistryGenerateK3sConfig(ctx context.Context, internalRegistries *k3d.Registry, externalRegistries []*k3d.ExternalRegistry) (*k3s.Registry, error) {
|
||||
func RegistryGenerateK3sConfig(ctx context.Context, registries []*k3d.Registry) (*k3s.Registry, error) {
|
||||
regConf := &k3s.Registry{}
|
||||
|
||||
for _, reg := range externalRegistries {
|
||||
internalAddress := fmt.Sprintf("%s:%s", reg.Host, reg.Port)
|
||||
externalAddress := fmt.Sprintf("%s:%s", reg.Host, reg.ExternalPort)
|
||||
for _, reg := range registries {
|
||||
internalAddress := fmt.Sprintf("%s:%s", reg.Host, reg.Port.InternalPort)
|
||||
externalAddress := fmt.Sprintf("%s:%s", reg.Host, reg.Port.ExternalPort.Port)
|
||||
|
||||
// init mirrors if nil
|
||||
if regConf.Mirrors == nil {
|
||||
@ -150,8 +150,8 @@ func RegistryGenerateK3sConfig(ctx context.Context, internalRegistries *k3d.Regi
|
||||
},
|
||||
}
|
||||
|
||||
if reg.Proxy != "" {
|
||||
regConf.Mirrors[k3d.DefaultDockerHubAddress] = k3s.Mirror{
|
||||
if reg.Options.Proxy.RemoteURL != "" {
|
||||
regConf.Mirrors[reg.Options.Proxy.RemoteURL] = k3s.Mirror{
|
||||
Endpoints: []string{fmt.Sprintf("http://%s", internalAddress)},
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,10 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
|
||||
clusterCreateOpts.Registries.Create = &k3d.Registry{
|
||||
Host: fmt.Sprintf("%s-%s-registry", k3d.DefaultObjectNamePrefix, newCluster.Name),
|
||||
Image: fmt.Sprintf("%s:%s", k3d.DefaultRegistryImageRepo, k3d.DefaultRegistryImageTag),
|
||||
Port: regPort,
|
||||
Port: k3d.MappedPort{
|
||||
InternalPort: k3d.DefaultRegistryPort,
|
||||
ExternalPort: regPort,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,9 +126,9 @@ type SimpleConfig struct {
|
||||
Options SimpleConfigOptions `mapstructure:"options" yaml:"options" json:"options,omitempty"`
|
||||
Env []EnvVarWithNodeFilters `mapstructure:"env" yaml:"env" json:"env,omitempty"`
|
||||
Registries struct {
|
||||
Use []*k3d.ExternalRegistry
|
||||
Create bool
|
||||
}
|
||||
Use []*k3d.Registry `mapstructure:"use" yaml:"use,omitempty" json:"use,omitempty"`
|
||||
Create bool `mapstructure:"create" yaml:"create,omitempty" json:"create,omitempty"`
|
||||
} `mapstructure:"registries" yaml:"registries,omitempty" json:"registries,omitempty"`
|
||||
}
|
||||
|
||||
// GetKind implements Config.GetKind
|
||||
|
@ -175,8 +175,8 @@ type ClusterCreateOpts struct {
|
||||
GlobalLabels map[string]string `yaml:"globalLabels,omitempty" json:"globalLabels,omitempty"`
|
||||
GlobalEnv []string `yaml:"globalEnv,omitempty" json:"globalEnv,omitempty"`
|
||||
Registries struct {
|
||||
Create *Registry `yaml:"create,omitempty" json:"create,omitempty"`
|
||||
Use []*ExternalRegistry `yaml:"use,omitempty" json:"use,omitempty"`
|
||||
Create *Registry `yaml:"create,omitempty" json:"create,omitempty"`
|
||||
Use []*Registry `yaml:"use,omitempty" json:"use,omitempty"`
|
||||
} `yaml:"registries,omitempty" json:"registries,omitempty"`
|
||||
}
|
||||
|
||||
@ -320,7 +320,13 @@ type ExternalDatastore struct {
|
||||
Network string `yaml:"network" json:"network,omitempty"`
|
||||
}
|
||||
|
||||
// ExposedPort describes specs needed to expose the API-Server
|
||||
// MappedPort combines an internal port mapped to an exposed port
|
||||
type MappedPort struct {
|
||||
InternalPort string `yaml:"internal,omitempty" json:"internal,omitempty"`
|
||||
ExternalPort ExposedPort `yaml:"expose,omitempty" json:"expose,omitempty"`
|
||||
}
|
||||
|
||||
// ExposedPort describes a port exposed on the host system
|
||||
type ExposedPort struct {
|
||||
Host string `yaml:"host" json:"host,omitempty"`
|
||||
HostIP string `yaml:"hostIP" json:"hostIP,omitempty"`
|
||||
@ -356,10 +362,10 @@ const (
|
||||
|
||||
// Registry describes a k3d-managed registry
|
||||
type Registry struct {
|
||||
ClusterRef string // filled automatically -> if created with a cluster
|
||||
Host string `yaml:"host" json:"host"`
|
||||
Image string `yaml:"image,omitempty" json:"image,omitempty"`
|
||||
Port ExposedPort `yaml:"port" json:"port"`
|
||||
ClusterRef string // filled automatically -> if created with a cluster
|
||||
Host string `yaml:"host" json:"host"`
|
||||
Image string `yaml:"image,omitempty" json:"image,omitempty"`
|
||||
Port MappedPort `yaml:"port" json:"port"`
|
||||
Options struct {
|
||||
ConfigFile string `yaml:"configFile,omitempty" json:"configFile,omitempty"`
|
||||
Proxy struct {
|
||||
@ -369,11 +375,3 @@ type Registry struct {
|
||||
} `yaml:"proxy,omitempty" json:"proxy,omitempty"`
|
||||
} `yaml:"options,omitempty" json:"options,omitempty"`
|
||||
}
|
||||
|
||||
// ExternalRegistry describes a registry that is not managed together with the current cluster -> we only update the registries.yaml
|
||||
type ExternalRegistry struct {
|
||||
Host string `yaml:"host" json:"host"`
|
||||
Port string `yaml:"port" json:"port"`
|
||||
ExternalPort string `yaml:"externalPort" json:"externalPort"`
|
||||
Proxy string `yaml:"proxy,omitempty" json:"proxy,omitempty"` // to use the external registry as a proxy for e.g. docker.io
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user