Skip to content

Commit

Permalink
capd: set machine addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Sy Kim <[email protected]>
  • Loading branch information
andrewsykim committed Jun 24, 2020
1 parent 1b92bfe commit 5cbe5d3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ type DockerMachineStatus struct {
// +optional
LoadBalancerConfigured bool `json:"loadBalancerConfigured,omitempty"`

// Addresses contains the associated addresses for the docker machine.
// +optional
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`

// Conditions defines current service state of the DockerMachine.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ spec:
status:
description: DockerMachineStatus defines the observed state of DockerMachine
properties:
addresses:
description: Addresses contains the associated addresses for the docker
machine.
items:
description: MachineAddress contains information for the node's
address.
properties:
address:
description: The machine address.
type: string
type:
description: Machine address type, one of Hostname, ExternalIP
or InternalIP.
type: string
required:
- address
- type
type: object
type: array
conditions:
description: Conditions defines current service state of the DockerMachine.
items:
Expand Down
22 changes: 22 additions & 0 deletions test/infrastructure/docker/controllers/dockermachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,28 @@ func (r *DockerMachineReconciler) reconcileNormal(ctx context.Context, machine *
dockerMachine.Status.Ready = true
conditions.MarkTrue(dockerMachine, infrav1.ContainerProvisionedCondition)

// set address in machine status
machineAddress, err := externalMachine.Address()
if err != nil {
r.Log.Error(err, "failed to patch the Kubernetes node with the machine address")
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
}

dockerMachine.Status.Addresses = []clusterv1.MachineAddress{
{
Type: clusterv1.MachineHostName,
Address: externalMachine.ContainerName(),
},
{
Type: clusterv1.MachineInternalIP,
Address: machineAddress,
},
{
Type: clusterv1.MachineExternalIP,
Address: machineAddress,
},
}

return ctrl.Result{}, nil
}

Expand Down
9 changes: 9 additions & 0 deletions test/infrastructure/docker/docker/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ func (m *Machine) ProviderID() string {
return fmt.Sprintf("docker:////%s", m.ContainerName())
}

func (m *Machine) Address() (string, error) {
ipv4, _, err := m.container.IP(context.TODO())
if err != nil {
return "", err
}

return ipv4, nil
}

// Create creates a docker container hosting a Kubernetes node.
func (m *Machine) Create(ctx context.Context, role string, version *string, mounts []infrav1.Mount) error {
// Create if not exists.
Expand Down

0 comments on commit 5cbe5d3

Please sign in to comment.