Skip to content

Commit

Permalink
Rename MachineCreated status condition to MachineLaunched (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored Mar 29, 2023
1 parent ec51fba commit d544d21
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/v1alpha5/machine_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ type MachineStatus struct {

func (in *Machine) StatusConditions() apis.ConditionManager {
return apis.NewLivingConditionSet(
MachineCreated,
MachineLaunched,
MachineRegistered,
MachineInitialized,
).Manage(in)
}

var (
MachineCreated apis.ConditionType = "MachineCreated"
MachineLaunched apis.ConditionType = "MachineLaunched"
MachineRegistered apis.ConditionType = "MachineRegistered"
MachineInitialized apis.ConditionType = "MachineInitialized"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/machine/garbagecollect/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconc
return m.Status.ProviderID
})...)
machines := lo.Filter(lo.ToSlicePtr(machineList.Items), func(m *v1alpha5.Machine, _ int) bool {
return m.StatusConditions().GetCondition(v1alpha5.MachineCreated).IsTrue() &&
c.clock.Since(m.StatusConditions().GetCondition(v1alpha5.MachineCreated).LastTransitionTime.Inner.Time) > time.Second*10 &&
return m.StatusConditions().GetCondition(v1alpha5.MachineLaunched).IsTrue() &&
c.clock.Since(m.StatusConditions().GetCondition(v1alpha5.MachineLaunched).LastTransitionTime.Inner.Time) > time.Second*10 &&
!cloudProviderProviderIDs.Has(m.Status.ProviderID)
})

Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/machine/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (l *Launch) Reconcile(ctx context.Context, machine *v1alpha5.Machine) (reco
})
return reconcile.Result{}, nil
}
machine.StatusConditions().MarkFalse(v1alpha5.MachineCreated, "LinkFailed", truncateMessage(err.Error()))
machine.StatusConditions().MarkFalse(v1alpha5.MachineLaunched, "LinkFailed", truncateMessage(err.Error()))
return reconcile.Result{}, fmt.Errorf("linking machine, %w", err)
}
logging.FromContext(ctx).Debugf("linked machine")
Expand All @@ -70,14 +70,14 @@ func (l *Launch) Reconcile(ctx context.Context, machine *v1alpha5.Machine) (reco
logging.FromContext(ctx).Error(err)
return reconcile.Result{}, client.IgnoreNotFound(l.kubeClient.Delete(ctx, machine))
}
machine.StatusConditions().MarkFalse(v1alpha5.MachineCreated, "LaunchFailed", truncateMessage(err.Error()))
machine.StatusConditions().MarkFalse(v1alpha5.MachineLaunched, "LaunchFailed", truncateMessage(err.Error()))
return reconcile.Result{}, fmt.Errorf("creating machine, %w", err)
}
logging.FromContext(ctx).Debugf("created machine")
}
l.cache.SetDefault(client.ObjectKeyFromObject(machine).String(), created)
PopulateMachineDetails(machine, created)
machine.StatusConditions().MarkTrue(v1alpha5.MachineCreated)
machine.StatusConditions().MarkTrue(v1alpha5.MachineLaunched)
return reconcile.Result{}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/machine/launch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ = Describe("Launch", func() {
_, err := cloudProvider.Get(ctx, machine.Status.ProviderID)
Expect(err).ToNot(HaveOccurred())
})
It("should add the MachineCreated status condition after creating the Machine", func() {
It("should add the MachineLaunched status condition after creating the Machine", func() {
machine := test.Machine(v1alpha5.Machine{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
Expand All @@ -67,7 +67,7 @@ var _ = Describe("Launch", func() {
ExpectReconcileSucceeded(ctx, machineController, client.ObjectKeyFromObject(machine))

machine = ExpectExists(ctx, env.Client, machine)
Expect(ExpectStatusConditionExists(machine, v1alpha5.MachineCreated).Status).To(Equal(v1.ConditionTrue))
Expect(ExpectStatusConditionExists(machine, v1alpha5.MachineLaunched).Status).To(Equal(v1.ConditionTrue))
})
It("should link an instance with the karpenter.sh/linked annotation", func() {
cloudProviderMachine := &v1alpha5.Machine{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/machine/liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (l *Liveness) Reconcile(ctx context.Context, machine *v1alpha5.Machine) (re
}

func (l *Liveness) launchTTL(ctx context.Context, machine *v1alpha5.Machine) (reconcile.Result, error) {
if machine.StatusConditions().GetCondition(v1alpha5.MachineCreated).IsTrue() {
if machine.StatusConditions().GetCondition(v1alpha5.MachineLaunched).IsTrue() {
return reconcile.Result{}, nil
}
if machine.CreationTimestamp.IsZero() || l.clock.Since(machine.CreationTimestamp.Time) < launchTTL {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/machine/liveness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var _ = Describe("Liveness", func() {
ExpectApplied(ctx, env.Client, provisioner, machine)
ExpectReconcileFailed(ctx, machineController, client.ObjectKeyFromObject(machine))
machine = ExpectExists(ctx, env.Client, machine)
Expect(machine.StatusConditions().GetCondition(v1alpha5.MachineCreated).IsTrue()).To(BeFalse())
Expect(machine.StatusConditions().GetCondition(v1alpha5.MachineLaunched).IsTrue()).To(BeFalse())

// If the node hasn't registered in the creation timeframe, then we deprovision the Machine
fakeClock.Step(time.Minute * 3)
Expand Down
4 changes: 2 additions & 2 deletions pkg/test/expectations/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func ExpectMachineDeployedWithOffset(offset int, ctx context.Context, c client.C

// Make the machine ready in the status conditions
machine.PopulateMachineDetails(m, resolved)
m.StatusConditions().MarkTrue(v1alpha5.MachineCreated)
m.StatusConditions().MarkTrue(v1alpha5.MachineLaunched)
m.StatusConditions().MarkTrue(v1alpha5.MachineRegistered)

// Mock the machine launch and node joining at the apiserver
Expand Down Expand Up @@ -330,7 +330,7 @@ func ExpectMakeMachinesReady(ctx context.Context, c client.Client, machines ...*
func ExpectMakeMachinesReadyWithOffset(offset int, ctx context.Context, c client.Client, machines ...*v1alpha5.Machine) {
for i := range machines {
machines[i] = ExpectExistsWithOffset(offset+1, ctx, c, machines[i])
machines[i].StatusConditions().MarkTrue(v1alpha5.MachineCreated)
machines[i].StatusConditions().MarkTrue(v1alpha5.MachineLaunched)
machines[i].StatusConditions().MarkTrue(v1alpha5.MachineRegistered)
machines[i].StatusConditions().MarkTrue(v1alpha5.MachineInitialized)
ExpectAppliedWithOffset(offset+1, ctx, c, machines[i])
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func NewFromNode(node *v1.Node) *v1alpha5.Machine {
if _, ok := node.Labels[v1alpha5.LabelNodeInitialized]; ok {
m.StatusConditions().MarkTrue(v1alpha5.MachineInitialized)
}
m.StatusConditions().MarkTrue(v1alpha5.MachineCreated)
m.StatusConditions().MarkTrue(v1alpha5.MachineLaunched)
m.StatusConditions().MarkTrue(v1alpha5.MachineRegistered)
return m
}

0 comments on commit d544d21

Please sign in to comment.