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

🌱 Update contract package to match documentation #7138

Merged
merged 1 commit into from
Nov 3, 2022

Conversation

Jont828
Copy link
Contributor

@Jont828 Jont828 commented Sep 1, 2022

What this PR does / why we need it: As described in #5309, we're going through internal/contract package and updating it to match the specifications in the docs.

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 #7119 #7120

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 1, 2022
@Jont828
Copy link
Contributor Author

Jont828 commented Sep 1, 2022

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.

Looks like a good start - could you add some unit tests to show these fields working?

@Jont828 Jont828 changed the title Update existing types in contract package to match documentation Update contract package to match documentation Sep 1, 2022
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 1, 2022
@sbueringer
Copy link
Member

/ok-to-test

I would take a look once the tests are green / linter is happy

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Sep 2, 2022
@Jont828
Copy link
Contributor Author

Jont828 commented Sep 2, 2022

@sbueringer @killianmuldoon I held off on tests since I had a couple design considerations I wanted to ask about.

  1. I noticed we're created an Int64 type to represent in Int32 fields, was that an intentional change to group them all as Int64?
  2. I think it would be helpful to documents optional fields as well, but currently there isn't a good way to show the difference between an optional field like failureMessage and a required field like ready.
  3. At what point do we want to create additional structs for nested fields? For example, InfrastructureClusterContract returns a field InfrastructureClusterControlPlaneEndpoint which has additional fields so that it would be called as infra.ControlPlaneEndpoint().Host(). Do we want every nested path to have a intermediate struct like infra.Status().Ready() or just have it be infra.Ready()?

@Jont828 Jont828 force-pushed the existing-contracts branch 2 times, most recently from f3822bd to 4f43349 Compare September 6, 2022 21:27
@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 Sep 6, 2022
@sbueringer
Copy link
Member

sbueringer commented Sep 12, 2022

@sbueringer @killianmuldoon I held off on tests since I had a couple design considerations I wanted to ask about.

  1. I noticed we're created an Int64 type to represent in Int32 fields, was that an intentional change to group them all as Int64?
  2. I think it would be helpful to documents optional fields as well, but currently there isn't a good way to show the difference between an optional field like failureMessage and a required field like ready.
  3. At what point do we want to create additional structs for nested fields? For example, InfrastructureClusterContract returns a field InfrastructureClusterControlPlaneEndpoint which has additional fields so that it would be called as infra.ControlPlaneEndpoint().Host(). Do we want every nested path to have a intermediate struct like infra.Status().Ready() or just have it be infra.Ready()?
  • 1 I think this is due to:
    • The contract (control-plane.md) just specifices that e.g. replicas is an int. Not if it's int32 or int64. I think int64 is just safer
    • The unstructured package only has a func for int64: unstructured.NestedInt64
  • 2 I think it's fine to have the same funcs as in the usual cases and if the field is not set we just return an error that wraps errNotFound like we do today in other funcs (e.g. .status.replicas is also not always set)
  • 3 In general we want the full path and everything except the leaf should be a struct

@Jont828 Jont828 changed the title Update contract package to match documentation 🌱 Update contract package to match documentation Sep 14, 2022
@Jont828
Copy link
Contributor Author

Jont828 commented Sep 14, 2022

Gotcha that makes sense to me. I also spoke with @jackfrancis and we were also wondering if there's a way to generate code for this as opposed to manually implementing the paths and structs.

@Jont828 Jont828 marked this pull request as ready for review September 14, 2022 23:21
@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 14, 2022
Copy link
Contributor Author

@Jont828 Jont828 left a comment

Choose a reason for hiding this comment

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

@sbueringer I've worked on implementing the optional types but had some trouble dealing with types that were a list or a map of additional structs. Would definitely appreciate any suggestions on how to proceed!

internal/contract/infrastructure_cluster.go Outdated Show resolved Hide resolved
internal/contract/infrastructure_cluster.go Outdated Show resolved Hide resolved
internal/contract/infrastructure_machine.go Show resolved Hide resolved
@sbueringer
Copy link
Member

I'll take a look early next week

@sbueringer
Copy link
Member

sbueringer commented Sep 21, 2022

Gotcha that makes sense to me. I also spoke with @jackfrancis and we were also wondering if there's a way to generate code for this as opposed to manually implementing the paths and structs.

Somehow forgot to answer. I think it might be possible but I wonder if maintaining the generation code (+ unit tests, ..) is worth it. It's probably also complex code that won't be easy to understand.

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.

Made a first pass, this is a great work of research.
I'm looking forward to get this merged and start cleaning up usage of unstructured all around the codebase

internal/contract/controlplane.go Outdated Show resolved Hide resolved
internal/contract/controlplane.go Outdated Show resolved Hide resolved
internal/contract/infrastructure_cluster.go Outdated Show resolved Hide resolved
internal/contract/infrastructure_cluster.go Outdated Show resolved Hide resolved
internal/contract/infrastructure_machine.go Outdated Show resolved Hide resolved
internal/contract/infrastructure_machine.go Show resolved Hide resolved
internal/contract/types.go Outdated Show resolved Hide resolved
@Jont828
Copy link
Contributor Author

Jont828 commented Oct 10, 2022

@fabriziopandini @sbueringer I squashed and fixed the linting issues, PTAL when you get the chance!

@Jont828
Copy link
Contributor Author

Jont828 commented Oct 12, 2022

@fabriziopandini @sbueringer I think this should be ready for a final pass!

@sbueringer
Copy link
Member

Thx!

I'll take a look as soon as I can, but I can't promise it will happen before KubeCon. Just too much things going on right now.

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.

I'm +1 to merge this code, so we can start using it as a replacement for current unstructured handling across the code base.
/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 17, 2022
@Jont828
Copy link
Contributor Author

Jont828 commented Nov 1, 2022

@fabriziopandini @sbueringer Are we good to merge this or do we need a final pass of reviews?

@sbueringer
Copy link
Member

Looks good to me!

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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 Nov 3, 2022
@sbueringer
Copy link
Member

@Jont828 I edited the PR description so that this PR doesn't close #5309.

While this PR extends the contract package it doesn't refactor controllers to use the contract package (yet).

@k8s-ci-robot k8s-ci-robot merged commit c4644cd into kubernetes-sigs:main Nov 3, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.3 milestone Nov 3, 2022
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the bootstrap provider contract in the contract package
5 participants