From bebff1b83d6f9e10e55415c3624865339dc1e878 Mon Sep 17 00:00:00 2001 From: Andrew Sy Kim Date: Wed, 24 Jun 2020 14:30:06 -0400 Subject: [PATCH] capd: set machine addresses Signed-off-by: Andrew Sy Kim --- .../api/v1alpha3/dockermachine_types.go | 4 ++++ .../api/v1alpha3/zz_generated.deepcopy.go | 5 +++++ ...cture.cluster.x-k8s.io_dockermachines.yaml | 19 ++++++++++++++++ .../controllers/dockermachine_controller.go | 22 +++++++++++++++++++ test/infrastructure/docker/docker/machine.go | 9 ++++++++ 5 files changed, 59 insertions(+) diff --git a/test/infrastructure/docker/api/v1alpha3/dockermachine_types.go b/test/infrastructure/docker/api/v1alpha3/dockermachine_types.go index f5d60d91588e..8fb81a1187c1 100644 --- a/test/infrastructure/docker/api/v1alpha3/dockermachine_types.go +++ b/test/infrastructure/docker/api/v1alpha3/dockermachine_types.go @@ -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"` diff --git a/test/infrastructure/docker/api/v1alpha3/zz_generated.deepcopy.go b/test/infrastructure/docker/api/v1alpha3/zz_generated.deepcopy.go index 6213b8e12067..e3a0e5704c56 100644 --- a/test/infrastructure/docker/api/v1alpha3/zz_generated.deepcopy.go +++ b/test/infrastructure/docker/api/v1alpha3/zz_generated.deepcopy.go @@ -243,6 +243,11 @@ func (in *DockerMachineSpec) DeepCopy() *DockerMachineSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DockerMachineStatus) DeepCopyInto(out *DockerMachineStatus) { *out = *in + if in.Addresses != nil { + in, out := &in.Addresses, &out.Addresses + *out = make([]apiv1alpha3.MachineAddress, len(*in)) + copy(*out, *in) + } if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions *out = make(apiv1alpha3.Conditions, len(*in)) diff --git a/test/infrastructure/docker/config/crd/bases/infrastructure.cluster.x-k8s.io_dockermachines.yaml b/test/infrastructure/docker/config/crd/bases/infrastructure.cluster.x-k8s.io_dockermachines.yaml index 5f16c8af64f6..fee2052298de 100644 --- a/test/infrastructure/docker/config/crd/bases/infrastructure.cluster.x-k8s.io_dockermachines.yaml +++ b/test/infrastructure/docker/config/crd/bases/infrastructure.cluster.x-k8s.io_dockermachines.yaml @@ -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: diff --git a/test/infrastructure/docker/controllers/dockermachine_controller.go b/test/infrastructure/docker/controllers/dockermachine_controller.go index f7e45c42a622..714a5f20bfb5 100644 --- a/test/infrastructure/docker/controllers/dockermachine_controller.go +++ b/test/infrastructure/docker/controllers/dockermachine_controller.go @@ -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(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. diff --git a/test/infrastructure/docker/docker/machine.go b/test/infrastructure/docker/docker/machine.go index 7dbc9889296b..7d478ca13f0c 100644 --- a/test/infrastructure/docker/docker/machine.go +++ b/test/infrastructure/docker/docker/machine.go @@ -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.