Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 CAPD Machines now reports status.addresses #3250

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Copy link
Member

@fabriziopandini fabriziopandini Jun 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code for reconciling network addresses (L280-301) should go before the block of code that reconcile ProviderID (L267-268), otherwise, in case of errors the network won't be set due to the test at L172

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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