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

🌱 ORC: Generate common parts of resource API #2203

Merged
merged 3 commits into from
Oct 28, 2024

Conversation

mdbooth
Copy link
Contributor

@mdbooth mdbooth commented Oct 22, 2024

Adds a very simple code generator which simply uses a go template to generate the common parts of an ORC resource API.

My preference was to do this with generics, but for now this breaks controller-tools: kubernetes-sigs/controller-tools#844

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 22, 2024
Copy link

netlify bot commented Oct 22, 2024

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit e4e85c3
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/671f60db3260220008a9c7e6
😎 Deploy Preview https://deploy-preview-2203--kubernetes-sigs-cluster-api-openstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

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

/approve
(tiny typo below)

// +kubebuilder:validation:Format:=uuid
ID *string `json:"id,omitempty"`

// Filter contains an resource query which is expected to return a single
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Filter contains an resource query which is expected to return a single
// Filter contains a resource query which is expected to return a single

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lentzi90

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 24, 2024
Copy link
Contributor

@pierreprinetti pierreprinetti left a comment

Choose a reason for hiding this comment

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

This is a great first step. Thank you for setting up this generator! I hope its life will be glorious and short, until we can use generics in the API.

Comment on lines 53 to 54
// Import refers to an existing ORC object which will be imported instead of
// creating a new resource.
Copy link
Contributor

Choose a reason for hiding this comment

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

An existing ORC object? Isn't this the ORC object?

Suggested change
// Import refers to an existing ORC object which will be imported instead of
// creating a new resource.
// Import refers to an existing OpenStack resource which will be imported instead of
// creating a new one.

Filter *{{ .Name }}Filter `json:"filter,omitempty"`
}

// {{ .Name }}Spec defines the desired state of a ORC object.
Copy link
Contributor

Choose a reason for hiding this comment

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

a or an?

//
// Resource may not be specified if the management policy is `unmanaged`.
//
// Resource must be specified when the management policy is `managed`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless an arcane grammar rule applies here, can we use if for both cases for consistency?

Suggested change
// Resource must be specified when the management policy is `managed`.
// Resource must be specified if the management policy is `managed`.


// ManagementPolicy defines how ORC will treat the object. Valid values are
// `managed`: ORC will create, update, and delete the resource; `unmanaged`:
// ORC will import an existing resource, and will not apply updates to it or
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "nor" a word you'd use here?

Suggested change
// ORC will import an existing resource, and will not apply updates to it or
// ORC will import an existing resource, and will not apply updates to it nor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly I can't think of a practical case when I'd use 'nor' outside of formal logic except: neither this not that. It would be weird here.

Comment on lines 92 to 93
// Progressing indicates the state of the OpenStack resource not currently
// reflect the desired state, but that reconciliation is progressing.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it just me or this sentence reads weird?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does.

APIVersion: "v1alpha1",
SpecExtraValidations: []specExtraValidation{
{
Rule: "!has(self.__import__) ? has(self.resource.content) : true",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good first step, but going forward we probably want a more structured way to define required fields in the spec...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This particular one is special because the Image controller is a snowflake. This is a controller-specific validation at the spec level. I don't expect this to be a common pattern.

codegen depends on interfaces generated by controller-gen.
However, controller-gen will fail during code inspection if the
applyconfiguration package does not already exist because it is imported
by the code being inspected. This is a bootstrapping problem.

We ensure the applyconfiguration package exists by adding a doc.go.
@mdbooth mdbooth force-pushed the resource-generator branch from 5d4c506 to d5e31bb Compare October 28, 2024 09:46
@pierreprinetti
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 28, 2024
@mdbooth
Copy link
Contributor Author

mdbooth commented Oct 28, 2024

Just discovered a templating bug in this PR while adding subnet: the spec ends up on the same line as the previous validation. Will fix.

@mdbooth mdbooth force-pushed the resource-generator branch from d5e31bb to e4e85c3 Compare October 28, 2024 10:00
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 28, 2024
@mdbooth
Copy link
Contributor Author

mdbooth commented Oct 28, 2024

/hold cancel

@EmilienM
Copy link
Contributor

/lgtm

@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 28, 2024
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 28, 2024
@k8s-ci-robot k8s-ci-robot merged commit 663ba86 into kubernetes-sigs:main Oct 28, 2024
9 checks passed
@mdbooth mdbooth deleted the resource-generator branch October 28, 2024 12:33
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants