Skip to content

Commit

Permalink
Merge pull request #3250 from andrewsykim/capd-machine-address
Browse files Browse the repository at this point in the history
🌱 CAPD Machines now reports `status.addresses`
  • Loading branch information
k8s-ci-robot authored Jun 25, 2020
2 parents 2fc37ea + bebff1b commit fd73b18
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 @@ -267,6 +267,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(ctx)
if err != nil {
r.Log.Error(err, "failed to get 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(ctx context.Context) (string, error) {
ipv4, _, err := m.container.IP(ctx)
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 fd73b18

Please sign in to comment.