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 ClusterClass variable and patch types #5418

Merged

Conversation

sbueringer
Copy link
Member

Signed-off-by: Stefan Büringer [email protected]

What this PR does / why we need it:
This PR adds the patch and variable types as discussed in: #5212

It intentionally does not contain any webhook or controller code changes.

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 11, 2021
@sbueringer sbueringer changed the title ✨ Add ClusterClass variable and patch types [WIP] ✨ Add ClusterClass variable and patch types Oct 11, 2021
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 11, 2021
@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch from 3ced181 to 22ffd68 Compare October 11, 2021 19:55
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 11, 2021
@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch from 22ffd68 to 325c44c Compare October 11, 2021 20:01
Makefile Outdated Show resolved Hide resolved
@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch from 325c44c to 909885d Compare October 11, 2021 20:20
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 11, 2021
@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch from 909885d to 8563f84 Compare October 11, 2021 20:30
@sbueringer sbueringer changed the title [WIP] ✨ Add ClusterClass variable and patch types ✨ Add ClusterClass variable and patch types Oct 11, 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 Oct 11, 2021
@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch 2 times, most recently from e0ad631 to a851a7f Compare October 12, 2021 08:56
// VariableTopology can be used to customize the Cluster through
// patches. It must comply to the corresponding
// VariableDefinitionClass defined in the ClusterClass.
type VariableTopology struct {
Copy link
Member

Choose a reason for hiding this comment

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

I see that there is a naming scheme, but maybe consider calling it TopologyVariable as that makes it easier to understand what it actually is.

Copy link
Member Author

@sbueringer sbueringer Oct 13, 2021

Choose a reason for hiding this comment

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

I could change it, the problem is getting consensus again on the struct names. Same applies to the other suggestions.

I see (at least 3 options):

  1. keep the current names
  2. your suggestions
  3. just drop the Topology and Class suffixes entirely

(I would prefer option 3)

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I'm personally for keeping current names because those name were discussed at length in the proposal/in the google doc predating the proposal and they are nicely consistent with the suffix used for all the Topology/Class types.

Copy link
Member Author

@sbueringer sbueringer Oct 14, 2021

Choose a reason for hiding this comment

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

I'm also absolutely fine with the current implementation. And as you said we already discussed it on the proposal and I would also really like to avoid loosing too much time by waiting for consensus again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Further discussed in Slack and Zoom.

Result is the following:

spec:
  variables: # []ClusterClassVariable
  - name: clusterIdentityName
    required: true
    schema: # VariableSchema
      openAPIV3Schema: # JSONSchemaProps
        type: string
        default: cluster-identity
  patches: # []ClusterClassPatch
  - name: clusterName
    definitions: # []PatchDefinition
    - selector: # PatchSelector
        apiVersion: controlplane.cluster.x-k8s.io/v1beta1
        kind: KubeadmControlPlaneTemplate
        matchResources: # PatchSelectorMatch
          machineDeploymentClass: # PatchSelectorMatchMachineDeploymentClass
            names:
            - default-worker
      jsonPatches: # []JSONPatchDefinition
      - op: replace
        path: "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration/controllerManager/extraArgs/cluster-name"
        valueFrom: # JSONPatchDefinitionValue
          variable: builtin.cluster.name
spec:
  topology:
    variables: # []ClusterVariable
    - name: clusterIdentityName
      value: cluster-identity

Reasoning (re-stating some of Fabrizio's points for completeness):

  • We should strive for names that mean something.
  • Topology/ClusterClass Kinds that already exist and have been released before this proposal are ok. And they cannot be changed anymore without going through the full deprecation cycle.
  • Essentially we have two kinds of new structs in this PR:
    • Structs which are specific to the API type where they are used
      • These structs have been prefixed: ClusterClassVariable, ClusterClassPatch and ClusterVariable
    • Structs which are generic and could be reused in other types in the future (at least in theory)
      • In those case we optimized for semantic, understandability, not too-long names. Those are:
        • VariableSchema, JSONSchemaProps
        • PatchDefinition, PatchSelector, PatchSelectorMatch, PatchSelectorMatchMachineDeploymentClass
        • JSONPatchDefinition, JSONPatchDefinitionValue

Note: We don't want to establish any hard rules here. That's just the reasoning for the current case/PR.

Copy link
Member

Choose a reason for hiding this comment

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

+1 to the proposed solution

Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to drop the Definition so we have JSONPatch and JSONPatchValue? The objects themselves are a definition of something, so it feels redundant.
The rest looks good.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, but I'm not sure we should. The valueFrom part does not exist in the usual definitions of what a JSON patch is supposed to look like. So it's maybe good to signal with JSONPatchDefinition (related to the other PatchDefinition we have) that it's not just a regular JSON patch.

But I would be fine with both.

@fabriziopandini @vincepri WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Ok to drop definition from JSONPatchDefinition and JSONPatchDefinitionValue

@vincepri
Copy link
Member

/hold

for review

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 13, 2021
@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch from e27c834 to 1061a4f Compare October 13, 2021 09:33
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.

Overall lgtm pending discussion on fuzzers for JSON fields and type names

@killianmuldoon
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 14, 2021
@vincepri
Copy link
Member

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 19, 2021
@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch from 8506454 to c3e542c Compare October 20, 2021 15:02
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 20, 2021
@neolit123
Copy link
Member

Current (suffix): VariableTopology, VariablesClass, VariableDefinitionClass, VariableDefinitionSchemaClass, PatchClass
Proposed (prefix): TopologyVariable, ClassVariables, ClassVariableDefinition, ClassVariableDefinitionSchema, ClassPatch

the common way is to have the type at the end - e.g. "StorageClass"
https://kubernetes.io/docs/concepts/storage/storage-classes/

@sbueringer
Copy link
Member Author

sbueringer commented Oct 20, 2021

Current (suffix): VariableTopology, VariablesClass, VariableDefinitionClass, VariableDefinitionSchemaClass, PatchClass
Proposed (prefix): TopologyVariable, ClassVariables, ClassVariableDefinition, ClassVariableDefinitionSchema, ClassPatch

the common way is to have the type at the end - e.g. "StorageClass" https://kubernetes.io/docs/concepts/storage/storage-classes/

I agree for the top-level API type names, if something is a Template or a Class. But it seems to me that non-top-level non-generic structs in the core API are prefixed (sometimes by the top-level type, sometimes by the "context"):

The Kubernetes core APIs follow the prefix pattern, a few examples: PodSpec, PodStatus, PodTemplateSpec, NodeCondition, EndpointSubset, EndPointAddress, EndpointPort, DownwardAPIVolumeSource, CSIVolumeSource, ...

@neolit123
Copy link
Member

neolit123 commented Oct 20, 2021

i might be confusing what Class means here, but i agree with the k8s guide:

The Kubernetes core APIs follow the prefix pattern, a few examples: PodSpec, PodStatus, PodTemplateSpec

Pod is the object and Spec, Status are the types (or object specifics) which are more commonly suffixes.

having Class as an object is a bit confusing in general.

@sbueringer
Copy link
Member Author

i might be confusing what Class means here, but i agree with the k8s guide:

The Kubernetes core APIs follow the prefix pattern, a few examples: PodSpec, PodStatus, PodTemplateSpec

Pod is the object and Spec, Status are the types (or object specifics) which are more commonly suffixes.

having Class as an object is a bit confusing in general.

Yes, there are also a lot more not only Status and Spec (full list of core structs)

@sbueringer
Copy link
Member Author

Thx everyone for the discussion. I summarized the struct renaming in: #5418 (comment) (and adjusted the implementation and proposal accordingly)

Additionally we dropped the ".variables.definitions[].{name,required,schema}" layer. Initially the idea was to use it to make variables extensible so we can later on consume variables from somewhere else. This was inconsistent with ".patches[].definitions[].{selector,jsonPatches}" (e.g. patches was an array, variables was not). We've kept definitions in Patches as we want to be able to have multiple {selector,jsonPatches} in a patch.

We would now (probably) solve consuming external variables and patches by adding something like variablesFrom, patchesFrom.

PTAL @schrej @fabriziopandini @vincepri @neolit123

@fabriziopandini
Copy link
Member

great job!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 22, 2021
@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch from d4a72e4 to 1563423 Compare October 22, 2021 11:53
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 22, 2021
@sbueringer
Copy link
Member Author

s/JSONPatchDefinition/JSONPatch/ + squashed

@fabriziopandini
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 22, 2021
Copy link
Member

@schrej schrej left a comment

Choose a reason for hiding this comment

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

lgtm

@sbueringer
Copy link
Member Author

/assign @vincepri

@sbueringer sbueringer force-pushed the pr-add-clusterclass-patch-types branch from 1563423 to 1022e26 Compare October 25, 2021 14:17
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 25, 2021
in.Default = &apiextensionsv1.JSON{Raw: []byte("true")}

// Not every random string is a valid JSON number, so we're setting a valid JSON number.
number := json.Number("1")
Copy link
Member

Choose a reason for hiding this comment

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

Could we use an actual random number?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we could

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 25, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 25, 2021
@k8s-ci-robot k8s-ci-robot merged commit cb67b6f into kubernetes-sigs:main Oct 25, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.4 milestone Oct 25, 2021
@sbueringer sbueringer deleted the pr-add-clusterclass-patch-types branch October 25, 2021 14:40
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants