Skip to content

🌱 Add in-place update hooks to API: Fix review findings#1

Merged
alexander-demicev merged 1 commit intoalexander-demicev:inplacehooksfrom
sbueringer:inplacehooks-review
Sep 26, 2025
Merged

🌱 Add in-place update hooks to API: Fix review findings#1
alexander-demicev merged 1 commit intoalexander-demicev:inplacehooksfrom
sbueringer:inplacehooks-review

Conversation

@sbueringer
Copy link

@sbueringer sbueringer commented Sep 26, 2025

Signed-off-by: Stefan Büringer buringerst@vmware.com

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
xref: kubernetes-sigs#12343

@@ -105,7 +105,11 @@ linters:
## Excludes for current clusterctl v1alpha3 and Runtime Hooks v1alpha1 apiVersions (can be fixed once we bump their apiVersion).
# Note: The types in api/runtime/hooks/v1alpha1 are not CRDs, so e.g. SSA markers don't make sense there.
- path: "cmd/clusterctl/api/v1alpha3|api/runtime/hooks/v1alpha1"
Copy link
Author

Choose a reason for hiding this comment

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

The main goal is just to get the marshaling right (pointer, omitempty, omitzero, ...) as these are not regular Kubernetes APIs


// PatchType defines the supported patch types.
// +enum
// +kubebuilder:validation:Enum=JSONPatch;JSONMergePatch
Copy link
Author

Choose a reason for hiding this comment

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

Just to make the linter (KAL) work better

"k8s.io/apimachinery/pkg/runtime"

clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
Copy link
Author

Choose a reason for hiding this comment

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

When implementing my prototype I noticed that it would be better if we directly use v1beta2. It's not 100% consistent with our other hooks but v1beta2 is much better from a marshalling perspective and I don't want to run into trouble because of that

(also we can avoid down conversion in our controllers)

Choose a reason for hiding this comment

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

I had a feeling Fabrizio mentioned we should use v1beta1 here

Copy link
Author

@sbueringer sbueringer Sep 26, 2025

Choose a reason for hiding this comment

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

Yes he did. We just realized later that it's not a good idea (we initially wanted to use v1beta1 to use the same as in the other lifecycle hooks, but it's not worth the downsides)

// current contains the current state of the Machine and related objects.
// +required
Current CanUpdateMachineRequestObjects `json:"current"`
Current CanUpdateMachineRequestObjects `json:"current,omitempty,omitzero"`
Copy link
Author

Choose a reason for hiding this comment

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

API conventions currently recommend to use omitempty + omitzero on all "struct fields" (doesn't matter if optional or required)

BootstrapConfig *runtime.RawExtension `json:"bootstrapConfig,omitempty"`
}

// Patch is a single patch (JSONPatch or JSONMergePatch) which can include multiple operations.
Copy link
Author

Choose a reason for hiding this comment

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

Just moved some structs around a bit for consistent top-down ordering

// machinePatch when applied to the current Machine spec, indicates changes handled in-place.
// +optional
MachinePatch *Patch `json:"machinePatch,omitempty"`
MachinePatch Patch `json:"machinePatch,omitempty,omitzero"`
Copy link
Author

Choose a reason for hiding this comment

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

We don't need the pointers anymore, omitzero handles correct marshalling (also matches regular API conventions for CRD API types)

Also reduces potential for nil pointers

Choose a reason for hiding this comment

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

Copy link
Author

@sbueringer sbueringer Sep 26, 2025

Choose a reason for hiding this comment

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

I think the short answer is, the trade-offs are a bit different for CRDs, not sure how much of the guidance there is for builtin types. I think they are also not yet recommending to use omitzero everywhere, but we are doing it everywhere in core CAPI

We were discussion this with Joel when we refactored everything for v1beta2 and this is inline with what we did there

(just to give some additional context)

// machine is the full MachineSet object.
// +required
MachineSetSpec clusterv1beta1.MachineSetSpec `json:"machineSetSpec"`
MachineSet clusterv1.MachineSet `json:"machineSet,omitempty,omitzero"`
Copy link
Author

Choose a reason for hiding this comment

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

I think we should also use the full objects here (but also here we won't send status)

MachineSetPatch Patch `json:"machineSetPatch,omitempty,omitzero"`

// infrastructureMachineTemplateSpecPatch indicates infra template spec changes handled in-place.
// infrastructureMachineTemplatePatch indicates infra template spec changes handled in-place.
Copy link
Author

Choose a reason for hiding this comment

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

Just consistently dropping Spec from the field names here (the patches should only contain spec changes as documented, I just wouldn't surface it in field names)

@@ -30,10 +30,14 @@ import (
// Prior art: https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/crd/known_types.go.
func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
Copy link
Author

Choose a reason for hiding this comment

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

Signed-off-by: Stefan Büringer buringerst@vmware.com
@alexander-demicev alexander-demicev merged commit d20fd71 into alexander-demicev:inplacehooks Sep 26, 2025
@sbueringer sbueringer deleted the inplacehooks-review branch September 26, 2025 10:04
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.

2 participants