diff --git a/pkg/apis/config/v1alpha4/types.go b/pkg/apis/config/v1alpha4/types.go index cd831b3f15..69db1c4d37 100644 --- a/pkg/apis/config/v1alpha4/types.go +++ b/pkg/apis/config/v1alpha4/types.go @@ -142,6 +142,14 @@ type Node struct { // The node-level patches will be applied after the cluster-level patches // have been applied. (See Cluster.KubeadmConfigPatchesJSON6902) KubeadmConfigPatchesJSON6902 []PatchJSON6902 `yaml:"kubeadmConfigPatchesJSON6902,omitempty"` + + // Docker networks to attach to. Defaults to the Docker default ("bridge"). + Networks []string + + // Loopback IP. + Loopback string + + Routes []string } // NodeRole defines possible role for nodes in a Kubernetes cluster managed by `kind` diff --git a/pkg/cluster/constants/constants.go b/pkg/cluster/constants/constants.go index 14668501db..fb9c0734ce 100644 --- a/pkg/cluster/constants/constants.go +++ b/pkg/cluster/constants/constants.go @@ -20,9 +20,6 @@ package constants // DefaultClusterName is the default cluster Context name const DefaultClusterName = "kind" -const NodeLoopbackKey = "io.k8s.sigs.kind.loopback" -const NodeRoutesKey = "io.k8s.sigs.kind.routes" - /* node role value constants */ const ( // ControlPlaneNodeRoleValue identifies a node that hosts a Kubernetes diff --git a/pkg/cluster/internal/create/actions/loopback/loopback.go b/pkg/cluster/internal/create/actions/loopback/loopback.go index 8b44b0c19b..fa1e7cd4bd 100644 --- a/pkg/cluster/internal/create/actions/loopback/loopback.go +++ b/pkg/cluster/internal/create/actions/loopback/loopback.go @@ -19,9 +19,10 @@ package loopback import ( "fmt" - "sigs.k8s.io/kind/pkg/errors" - "sigs.k8s.io/kind/pkg/internal/cluster/create/actions" "strings" + + "sigs.k8s.io/kind/pkg/cluster/internal/create/actions" + "sigs.k8s.io/kind/pkg/errors" ) // kubeadmInitAction implements action for executing the kubadm init diff --git a/pkg/cluster/internal/providers/docker/constants.go b/pkg/cluster/internal/providers/docker/constants.go index 40fd79d9d7..b34f182f45 100644 --- a/pkg/cluster/internal/providers/docker/constants.go +++ b/pkg/cluster/internal/providers/docker/constants.go @@ -22,3 +22,5 @@ const clusterLabelKey = "io.x-k8s.kind.cluster" // nodeRoleLabelKey is applied to each "node" docker container for categorization // of nodes by role const nodeRoleLabelKey = "io.x-k8s.kind.role" +const nodeLoopbackKey = "io.x-k8s.kind.loopback" +const nodeRoutesKey = "io.x-k8s.kind.routes" diff --git a/pkg/cluster/internal/providers/docker/node.go b/pkg/cluster/internal/providers/docker/node.go index ad95d0834e..64b3f0efdc 100644 --- a/pkg/cluster/internal/providers/docker/node.go +++ b/pkg/cluster/internal/providers/docker/node.go @@ -52,7 +52,7 @@ func (n *node) Role() (string, error) { func (n *node) Loopback() (string, error) { cmd := exec.Command("docker", "inspect", - "--format", fmt.Sprintf(`{{ index .Config.Labels "%s"}}`, constants.NodeLoopbackKey), + "--format", fmt.Sprintf(`{{ index .Config.Labels "%s"}}`, nodeLoopbackKey), n.name, ) lines, err := exec.OutputLines(cmd) @@ -67,7 +67,7 @@ func (n *node) Loopback() (string, error) { func (n *node) Routes() (string, error) { cmd := exec.Command("docker", "inspect", - "--format", fmt.Sprintf(`{{ index .Config.Labels "%s"}}`, constants.NodeRoutesKey), + "--format", fmt.Sprintf(`{{ index .Config.Labels "%s"}}`, nodeRoutesKey), n.name, ) lines, err := exec.OutputLines(cmd) diff --git a/pkg/cluster/internal/providers/docker/provision.go b/pkg/cluster/internal/providers/docker/provision.go index 5757bdf1ba..5f87d6a708 100644 --- a/pkg/cluster/internal/providers/docker/provision.go +++ b/pkg/cluster/internal/providers/docker/provision.go @@ -244,8 +244,8 @@ func runArgsForNode(node *config.Node, clusterIPFamily config.ClusterIPFamily, n "--name", name, // ... and set the container name // label the node with the role ID "--label", fmt.Sprintf("%s=%s", nodeRoleLabelKey, node.Role), - "--label", fmt.Sprintf("%s=%s", constants.NodeLoopbackKey, node.Loopback), - "--label", fmt.Sprintf("%s=%s", constants.NodeRoutesKey, strings.Join(node.Routes, ",")), + "--label", fmt.Sprintf("%s=%s", nodeLoopbackKey, node.Loopback), + "--label", fmt.Sprintf("%s=%s", nodeRoutesKey, strings.Join(node.Routes, ",")), // running containers in a container requires privileged // NOTE: we could try to replicate this with --cap-add, and use less // privileges, but this flag also changes some mounts that are necessary diff --git a/pkg/cluster/internal/providers/podman/node.go b/pkg/cluster/internal/providers/podman/node.go index 5285dd2244..c6ab2112ca 100644 --- a/pkg/cluster/internal/providers/podman/node.go +++ b/pkg/cluster/internal/providers/podman/node.go @@ -50,6 +50,14 @@ func (n *node) Role() (string, error) { return lines[0], nil } +func (n *node) Loopback() (string, error) { + return "", errors.New("unimplemented") +} + +func (n *node) Routes() (string, error) { + return "", errors.New("unimplemented") +} + func (n *node) IP() (ipv4 string, ipv6 string, err error) { // retrieve the IP address of the node using podman inspect cmd := exec.Command("podman", "inspect",