diff --git a/controller/linodemachine_controller.go b/controller/linodemachine_controller.go index d4b6e82eb..ad9ce3043 100644 --- a/controller/linodemachine_controller.go +++ b/controller/linodemachine_controller.go @@ -355,17 +355,25 @@ func (r *LinodeMachineReconciler) reconcileCreate( return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForRunningDelay}, nil } + addrs, err := r.buildInstanceAddrs(ctx, machineScope, linodeInstance.ID) + if err != nil { + logger.Error(err, "Failed to get instance ip addresses") + + if reconciler.RecordDecayingCondition(machineScope.LinodeMachine, + ConditionPreflightReady, string(cerrs.CreateMachineError), err.Error(), + reconciler.DefaultMachineControllerPreflightTimeout(r.ReconcileTimeout)) { + return ctrl.Result{}, err + } + + return ctrl.Result{RequeueAfter: reconciler.DefaultMachineControllerWaitForRunningDelay}, nil + } + machineScope.LinodeMachine.Status.Addresses = addrs + conditions.MarkTrue(machineScope.LinodeMachine, ConditionPreflightReady) } machineScope.LinodeMachine.Spec.ProviderID = util.Pointer(fmt.Sprintf("linode://%d", linodeInstance.ID)) - addrs, err := r.buildInstanceAddrs(ctx, machineScope, linodeInstance.ID) - if err != nil { - return linodeInstance, err - } - machineScope.LinodeMachine.Status.Addresses = addrs - // Set the instance state to signal preflight process is done machineScope.LinodeMachine.Status.InstanceState = util.Pointer(linodego.InstanceOffline) diff --git a/controller/linodemachine_controller_test.go b/controller/linodemachine_controller_test.go index d561c0738..3c6e8a54a 100644 --- a/controller/linodemachine_controller_test.go +++ b/controller/linodemachine_controller_test.go @@ -148,10 +148,26 @@ var _ = Describe("create", Label("machine", "create"), func() { IPv4: []*net.IP{ptr.To(net.IPv4(192, 168, 0, 2))}, Status: linodego.InstanceOffline, }, nil) - mockLinodeClient.EXPECT(). + bootInst := mockLinodeClient.EXPECT(). BootInstance(ctx, 123, 0). After(createInst). Return(nil) + getAddrs := mockLinodeClient.EXPECT(). + GetInstanceIPAddresses(ctx, 123). + After(bootInst). + Return(&linodego.InstanceIPAddressResponse{ + IPv4: &linodego.InstanceIPv4Response{ + Private: []*linodego.InstanceIP{{Address: "192.168.0.2"}}, + }, + }, nil) + mockLinodeClient.EXPECT(). + ListInstanceConfigs(ctx, 123, gomock.Any()). + After(getAddrs). + Return([]linodego.InstanceConfig{{ + Devices: &linodego.InstanceConfigDeviceMap{ + SDA: &linodego.InstanceConfigDevice{DiskID: 100}, + }, + }}, nil) mScope := scope.MachineScope{ Client: k8sClient, @@ -308,7 +324,7 @@ var _ = Describe("create", Label("machine", "create"), func() { Private: []*linodego.InstanceIP{{Address: "192.168.0.2"}}, }, }, nil) - mockLinodeClient.EXPECT(). + createNB := mockLinodeClient.EXPECT(). CreateNodeBalancerNode(ctx, 1, 2, linodego.NodeBalancerNodeCreateOptions{ Label: "mock", Address: "192.168.0.2:6443", @@ -316,6 +332,22 @@ var _ = Describe("create", Label("machine", "create"), func() { }). After(getAddrs). Return(nil, nil) + getAddrs = mockLinodeClient.EXPECT(). + GetInstanceIPAddresses(ctx, 123). + After(createNB). + Return(&linodego.InstanceIPAddressResponse{ + IPv4: &linodego.InstanceIPv4Response{ + Private: []*linodego.InstanceIP{{Address: "192.168.0.2"}}, + }, + }, nil) + mockLinodeClient.EXPECT(). + ListInstanceConfigs(ctx, 123, gomock.Any()). + After(getAddrs). + Return([]linodego.InstanceConfig{{ + Devices: &linodego.InstanceConfigDeviceMap{ + SDA: &linodego.InstanceConfigDevice{DiskID: 100}, + }, + }}, nil) mScope := scope.MachineScope{ Client: k8sClient, @@ -463,7 +495,7 @@ var _ = Describe("create", Label("machine", "create"), func() { Private: []*linodego.InstanceIP{{Address: "192.168.0.2"}}, }, }, nil) - mockLinodeClient.EXPECT(). + createNB := mockLinodeClient.EXPECT(). CreateNodeBalancerNode(ctx, 1, 2, linodego.NodeBalancerNodeCreateOptions{ Label: "mock", Address: "192.168.0.2:6443", @@ -471,6 +503,22 @@ var _ = Describe("create", Label("machine", "create"), func() { }). After(getAddrs). Return(nil, nil) + getAddrs = mockLinodeClient.EXPECT(). + GetInstanceIPAddresses(ctx, 123). + After(createNB). + Return(&linodego.InstanceIPAddressResponse{ + IPv4: &linodego.InstanceIPv4Response{ + Private: []*linodego.InstanceIP{{Address: "192.168.0.2"}}, + }, + }, nil) + mockLinodeClient.EXPECT(). + ListInstanceConfigs(ctx, 123, gomock.Any()). + After(getAddrs). + Return([]linodego.InstanceConfig{{ + Devices: &linodego.InstanceConfigDeviceMap{ + SDA: &linodego.InstanceConfigDevice{DiskID: 100}, + }, + }}, nil) _, err = reconciler.reconcileCreate(ctx, logger, &mScope) Expect(err).NotTo(HaveOccurred()) diff --git a/templates/flavors/base/linodeVPC.yaml b/templates/flavors/base/linodeVPC.yaml index 4ed39878c..7a311127e 100644 --- a/templates/flavors/base/linodeVPC.yaml +++ b/templates/flavors/base/linodeVPC.yaml @@ -3,6 +3,8 @@ apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: LinodeVPC metadata: name: ${VPC_NAME:=${CLUSTER_NAME}} + labels: + cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME} spec: region: ${LINODE_REGION} subnets: