Skip to content

Conversation

@alansy-nscale
Copy link
Contributor

@alansy-nscale alansy-nscale commented Oct 10, 2025

Description

This PR fixes an issue where the .status.phase field was not persisted when creating a resource using client.Create(...). This occurs because the Kubernetes client does not persist the status sub-resource during creation by default. To address this, a separate status patch call is now made after the resource is created. Additionally, to prevent intermediate validation errors, the phase is defaulted to Pending when it is empty.

@spjmurray
Copy link
Contributor

The comment does a good job of saying what it does, but it doesn't tell me why it's a problem. If it's not even been reconciled yet, then no power phase makes sense to me...

@alansy-nscale
Copy link
Contributor Author

Shouldn’t it default to Pending even if the underlying instance hasn't been created yet? It's like the instance is scheduled but not provisioned. Otherwise, I could make the field optional and leave it empty until it's reconciled.

@spjmurray
Copy link
Contributor

Just throwing ideas around! So nothing else works this way is my concern. While not written down anywhere, the assumption is if the resource doesn't have a reconcile status, then it hasn't been seen by the controller yet, and thus every other status element is implicitly invalid. Then there is the whole split brain stuff to consider: the user is in control of the spec via the API, the controller is in control of the status.

I've already fixed the field making it optional in the CRD.

@alansy-nscale
Copy link
Contributor Author

I've already fixed the field making it optional in the CRD.

Do you mean you've made the status field optional? If so, should we still return the phase in the API response as Pending, or make it a pointer to an InstanceLifecyclePhase so that we can return nil?

@spjmurray
Copy link
Contributor

To be fair, at this point in time, it's Unknown, so perhaps a new state is what we desire?

@alansy-nscale
Copy link
Contributor Author

Not sure if I've got this right, but I've just added a new Unknown state in the API response. That said, I'd still prefer keeping it as Pending, since we've already accepted the request and the instance is waiting to be created.

Conditions []unikornv1core.Condition `json:"conditions,omitempty"`
// Phase is the current lifecycle phase of the server.
Phase InstanceLifecyclePhase `json:"phase,omitempty"`
Phase *InstanceLifecyclePhase `json:"phase,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, as this is really a string, the zero value of "" will trigger nothing to be generated. But mistakes can happen I guess, so the difference between set but empty, and not set may be handy. Although it causes the code to be a bit more messy :/

// REVIEW_ME: Do we want to track who started the server, and when?
updated := current.DeepCopy()
updated.Status.Phase = unikornv1.InstanceLifecyclePhasePending
updated.Status.Phase = ptr.To(unikornv1.InstanceLifecyclePhasePending)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hah, I thought you'd not use this API, I am pleasantly surprised 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants