@ -25,6 +25,8 @@ import (
"context"
"context"
"fmt"
"fmt"
"time"
"time"
"github.com/docker/go-connections/nat"
)
)
// DefaultClusterName specifies the default name used for newly created clusters
// DefaultClusterName specifies the default name used for newly created clusters
@ -106,19 +108,20 @@ var DefaultObjectLabels = map[string]string{
// List of k3d technical label name
// List of k3d technical label name
const (
const (
LabelClusterName string = "k3d.cluster"
LabelClusterName string = "k3d.cluster"
LabelClusterURL string = "k3d.cluster.url"
LabelClusterURL string = "k3d.cluster.url"
LabelClusterToken string = "k3d.cluster.token"
LabelClusterToken string = "k3d.cluster.token"
LabelImageVolume string = "k3d.cluster.imageVolume"
LabelImageVolume string = "k3d.cluster.imageVolume"
LabelNetworkExternal string = "k3d.cluster.network.external"
LabelNetworkExternal string = "k3d.cluster.network.external"
LabelNetwork string = "k3d.cluster.network"
LabelNetwork string = "k3d.cluster.network"
LabelRole string = "k3d.role"
LabelRole string = "k3d.role"
LabelServerAPIPort string = "k3d.server.api.port"
LabelServerAPIPort string = "k3d.server.api.port"
LabelServerAPIHost string = "k3d.server.api.host"
LabelServerAPIHost string = "k3d.server.api.host"
LabelServerAPIHostIP string = "k3d.server.api.hostIP"
LabelServerAPIHostIP string = "k3d.server.api.hostIP"
LabelRegistryHost string = "k3d.registry.host"
LabelRegistryHost string = "k3d.registry.host"
LabelRegistryHostIP string = "k3d.registry.hostIP"
LabelRegistryHostIP string = "k3d.registry.hostIP"
LabelRegistryPort string = "k3s.registry.port"
LabelRegistryPortExternal string = "k3s.registry.port.external"
LabelRegistryPortInternal string = "k3s.registry.port.internal"
)
)
// DefaultRoleCmds maps the node roles to their respective default commands
// DefaultRoleCmds maps the node roles to their respective default commands
@ -240,7 +243,7 @@ type Cluster struct {
Nodes [ ] * Node ` yaml:"nodes" json:"nodes,omitempty" `
Nodes [ ] * Node ` yaml:"nodes" json:"nodes,omitempty" `
InitNode * Node // init server node
InitNode * Node // init server node
ExternalDatastore * ExternalDatastore ` yaml:"externalDatastore,omitempty" json:"externalDatastore,omitempty" `
ExternalDatastore * ExternalDatastore ` yaml:"externalDatastore,omitempty" json:"externalDatastore,omitempty" `
ExposeAPI ExposedPort ` yaml:"exposeAPI" json:"expos eAPI,omitempty"`
KubeAPI * ExposureOpts ` yaml:"kubeAPI" json:"kub eAPI,omitempty"`
ServerLoadBalancer * Node ` yaml:"serverLoadbalancer,omitempty" json:"serverLoadBalancer,omitempty" `
ServerLoadBalancer * Node ` yaml:"serverLoadbalancer,omitempty" json:"serverLoadBalancer,omitempty" `
ImageVolume string ` yaml:"imageVolume" json:"imageVolume,omitempty" `
ImageVolume string ` yaml:"imageVolume" json:"imageVolume,omitempty" `
}
}
@ -294,7 +297,7 @@ type Node struct {
Env [ ] string ` yaml:"env" json:"env,omitempty" `
Env [ ] string ` yaml:"env" json:"env,omitempty" `
Cmd [ ] string // filled automatically based on role
Cmd [ ] string // filled automatically based on role
Args [ ] string ` yaml:"extraArgs" json:"extraArgs,omitempty" `
Args [ ] string ` yaml:"extraArgs" json:"extraArgs,omitempty" `
Ports [ ] string ` yaml:"portMappings" json:"portMappings,omitempty" `
Ports nat . PortMap ` yaml:"portMappings" json:"portMappings,omitempty" `
Restart bool ` yaml:"restart" json:"restart,omitempty" `
Restart bool ` yaml:"restart" json:"restart,omitempty" `
Labels map [ string ] string // filled automatically
Labels map [ string ] string // filled automatically
Network string // filled automatically
Network string // filled automatically
@ -307,8 +310,14 @@ type Node struct {
// ServerOpts describes some additional server role specific opts
// ServerOpts describes some additional server role specific opts
type ServerOpts struct {
type ServerOpts struct {
IsInit bool ` yaml:"isInitializingServer" json:"isInitializingServer,omitempty" `
IsInit bool ` yaml:"isInitializingServer" json:"isInitializingServer,omitempty" `
ExposeAPI ExposedPort // filled automatically
KubeAPI * ExposureOpts ` yaml:"kubeAPI" json:"kubeAPI" `
}
// ExposureOpts describes settings that the user can set for accessing the Kubernetes API
type ExposureOpts struct {
nat . PortMapping // filled automatically (reference to normal portmapping)
Host string ` yaml:"host,omitempty" json:"host,omitempty" `
}
}
// ExternalDatastore describes an external datastore used for HA/multi-server clusters
// ExternalDatastore describes an external datastore used for HA/multi-server clusters
@ -320,19 +329,6 @@ type ExternalDatastore struct {
Network string ` yaml:"network" json:"network,omitempty" `
Network string ` yaml:"network" json:"network,omitempty" `
}
}
// 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" `
Port string ` yaml:"port" json:"port" `
}
// AgentOpts describes some additional agent role specific opts
// AgentOpts describes some additional agent role specific opts
type AgentOpts struct { }
type AgentOpts struct { }
@ -362,11 +358,12 @@ const (
// Registry describes a k3d-managed registry
// Registry describes a k3d-managed registry
type Registry struct {
type Registry struct {
ClusterRef string // filled automatically -> if created with a cluster
ClusterRef string // filled automatically -> if created with a cluster
Host string ` yaml:"host" json:"host" `
Protocol string ` yaml:"protocol,omitempty" json:"protocol,omitempty" ` // default: http
Image string ` yaml:"image,omitempty" json:"image,omitempty" `
Host string ` yaml:"host" json:"host" `
Port MappedPort ` yaml:"port" json:"port" `
Image string ` yaml:"image,omitempty" json:"image,omitempty" `
Options struct {
ExposureOpts ExposureOpts ` yaml:"expose" json:"expose" `
Options struct {
ConfigFile string ` yaml:"configFile,omitempty" json:"configFile,omitempty" `
ConfigFile string ` yaml:"configFile,omitempty" json:"configFile,omitempty" `
Proxy struct {
Proxy struct {
RemoteURL string ` yaml:"remoteURL" json:"remoteURL" `
RemoteURL string ` yaml:"remoteURL" json:"remoteURL" `