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 303f492 commit 121e31e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type DockerMachineStatus struct {
// +optional
Ready bool `json:"ready"`

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

// LoadBalancerConfigured denotes that the machine has been
// added to the load balancer
// +optional
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 @@ -264,6 +264,28 @@ func (r *DockerMachineReconciler) reconcileNormal(ctx context.Context, machine *
// Update the BootstrapExecSucceededCondition condition
conditions.MarkTrue(dockerMachine, infrav1.BootstrapExecSucceededCondition)

// 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,
},
}

// Usually a cloud provider will do this, but there is no docker-cloud provider.
// Requeue if there is an error, as this is likely momentary load balancer
// state changes during control plane provisioning.
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 121e31e

Please sign in to comment.