Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
Add extra labels for a kind container
Browse files Browse the repository at this point in the history
  • Loading branch information
tczekajlo committed Sep 7, 2021
1 parent 4e69b47 commit 7c37f5e
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions pkg/docker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,6 @@ func (d *Docker) joinKindNodeToKubernetesCluster(container container.ContainerCr
return nil
}

func (d *Docker) getKindNetwork() (string, error) {

inspect, err := d.Client.ContainerInspect(d.Ctx, d.Kind.ControlPlaneHost)
if err != nil {
return "", err
}

return inspect.HostConfig.NetworkMode.NetworkName(), nil
}

// CreateKindNode creates a new container that is used as a kind node.
func (d *Docker) CreateKindNode(hostname string) (container.ContainerCreateCreatedBody, error) {
kindImage := fmt.Sprintf("%s%s", kindImagePrefix, d.Kind.Version)
Expand Down Expand Up @@ -336,7 +326,7 @@ func (d *Docker) CreateKindNode(hostname string) (container.ContainerCreateCreat

}

kindNetwork, err := d.getKindNetwork()
kindControlPlaneContainer, err := d.getKindControlPlaneInfo()
if err != nil {
return container.ContainerCreateCreatedBody{}, err
}
Expand All @@ -348,9 +338,15 @@ func (d *Docker) CreateKindNode(hostname string) (container.ContainerCreateCreat
Hostname: hostname,
Volumes: map[string]struct{}{"/var": {}},
Env: []string{"container=docker"},
Labels: map[string]string{
"io.x-k8s.kind.cluster": kindControlPlaneContainer.Config.Labels["io.x-k8s.kind.cluster"],
"io.x-k8s.kind.role": "worker",
},
},
hostConfig, &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{kindNetwork: {}},
EndpointsConfig: map[string]*network.EndpointSettings{
kindControlPlaneContainer.HostConfig.NetworkMode.NetworkName(): {},
},
},
nil,
hostname,
Expand Down Expand Up @@ -420,3 +416,13 @@ func (d *Docker) SetKind(kind KindSpec) {
func (d *Docker) SetProjectPath(path string) {
d.ProjectPath = path
}

func (d *Docker) getKindControlPlaneInfo() (types.ContainerJSON, error) {

inspect, err := d.Client.ContainerInspect(d.Ctx, d.Kind.ControlPlaneHost)
if err != nil {
return inspect, err
}

return inspect, nil
}

0 comments on commit 7c37f5e

Please sign in to comment.