Skip to content

Commit

Permalink
rebase fix and address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulait committed Apr 24, 2024
1 parent 436f206 commit bb49160
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
20 changes: 14 additions & 6 deletions controller/linodemachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
54 changes: 51 additions & 3 deletions controller/linodemachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -308,14 +324,30 @@ 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",
Mode: linodego.ModeAccept,
}).
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,
Expand Down Expand Up @@ -463,14 +495,30 @@ 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",
Mode: linodego.ModeAccept,
}).
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())
Expand Down
2 changes: 2 additions & 0 deletions templates/flavors/base/linodeVPC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bb49160

Please sign in to comment.