Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📖 Add API conventions #5304

Merged
merged 5 commits into from
Sep 28, 2021

Conversation

sbueringer
Copy link
Member

@sbueringer sbueringer commented Sep 23, 2021

What this PR does / why we need it:
This PR adds API conventions to establish a standard for our APIs going forward. The main focus is optional fields.

Related PRs:

Notes:

  • this PR contains a few cherry-picks from other PRs for now to provide a full picture
  • after this PR and the ones I've cherry-picked all optional fields have omitempty and +optional with the exception of:
    • boolean flags which signal progress in the object lifecycle and replica counters (as mentioned in CONTRIBUTING.md)

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Implements parts of #5239

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 23, 2021
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 23, 2021
@sbueringer sbueringer force-pushed the pr-api-conventions branch 2 times, most recently from 007b384 to ac3cc96 Compare September 23, 2021 14:03
@enxebre
Copy link
Member

enxebre commented Sep 23, 2021

The comment and definition for Replicas field for scalable resources i.e MachineDeployments, MachineSets, MachinePools seems misguiding.

I know we discussed this in the past. But since we are here probably worth using the chance to discuss before promoting to beta.
I think the comment "// This is a pointer to distinguish between explicit zero and unspecified." in replicas is outdated and misguiding. That's never the case since we are defaulting 1, at least for MachineSets and MachineDeployments. in MachinePools I I can't see default marker, so the comment seems even more misguiding.
I see no reason for replicas to be a pointer and I think the only reason this is marked as optional is that required pointers with default breaks client side validation e.g kubectl kubernetes-sigs/controller-tools#567.

I think all ours scalable resources replicas should probably be commented an specified as:
If some one can think of a reason to keep it as a pointer:

	// Number of desired machines. Defaults to 1.
	// +optional
	// +kubebuilder:default=1
         Replicas *int32 `json:"replicas,omitempty"`

Or even better:

	// Number of desired machines. Defaults to 1.
	// +kubebuilder:default=1
         Replicas int32 `json:"replicas,omitempty"`

@sbueringer
Copy link
Member Author

@enxebre It's already enough if the field is either a pointer or it has omitempty or +optional to make it not required in OpenAPI schema. The combination of required in the schema + defaulting breaks client-side kubectl validation because the schema is validated without taking the defaulting into account.

I suspect it is a pointer so that client in controllers can explicitly not set it and an auto-scaler can take over (without the controller overwriting it again in the next reconciliation).

Signed-off-by: Stefan Büringer buringerst@vmware.com
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 23, 2021
@sbueringer sbueringer changed the title [WIP] Add API conventions, fix status fields [WIP] Add API conventions Sep 23, 2021
@sbueringer sbueringer changed the title [WIP] Add API conventions 📖 Add API conventions Sep 23, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 23, 2021
@sbueringer
Copy link
Member Author

@enxebre
Copy link
Member

enxebre commented Sep 23, 2021

@enxebre It's already enough if the field is either a pointer or it has omitempty or +optional to make it not required in OpenAPI schema. The combination of required in the schema + defaulting breaks client-side kubectl validation because the schema is validated without taking the defaulting into account.

Conceptually this field should no be optional, do we agree?
It's only marked optional because we are defaulting a pointer and as you mention otherwise it break client side validation.

So I think it should be required and defaulted with no pointer:

	// Number of desired machines. Defaults to 1.
	// +kubebuilder:default=1
         Replicas int32 `json:"replicas,omitempty"`

Or if we foresee an issue with that, at minimum we should drop the misguiding comment ("// This is a pointer to distinguish between explicit zero and unspecified.") and make sure we are consistent in MachinePools and add the default marker.

i.e:

	// Number of desired machines. Defaults to 1.
	// +optional
	// +kubebuilder:default=1
         Replicas *int32 `json:"replicas,omitempty"`

I suspect it is a pointer so that client in controllers can explicitly not set it and an auto-scaler can take over (without the controller overwriting it again in the next reconciliation).

Not sure I can think of case where the above would be problematic.
Anyway may be this topic is easier to discuss synchronously :)

CONTRIBUTING.md Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Show resolved Hide resolved
Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

thanks for writing this up
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 23, 2021
CONTRIBUTING.md Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 23, 2021
@sbueringer
Copy link
Member Author

/assign @randomvariable
I assume you're probably also interested in this.

Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

/lgtm

@fabriziopandini
Copy link
Member

/lgtm

Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

/lgtm

@fabriziopandini
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants