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 crd-scope and operator-scope documentation #4035

Merged
merged 1 commit into from
Jul 27, 2024

Conversation

camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Jul 21, 2024

This PR add a required info to let users know what is API and Manager scope as how to manage them.

Closes; #3623

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 21, 2024
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 21, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bavarianbidi, camilamacedo86

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 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 Jul 24, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 24, 2024
@camilamacedo86 camilamacedo86 force-pushed the pr-scope branch 5 times, most recently from b84b225 to e12911f Compare July 24, 2024 07:16
Copy link
Member

@fengshunli fengshunli left a comment

Choose a reason for hiding this comment

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

The --namespaced=false parameter is optional. The default value is false. You can set it to true only when you are trying it out.

Copy link
Member

@fengshunli fengshunli left a comment

Choose a reason for hiding this comment

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

The --namespaced=false parameter is optional. The default value is false. You can set it to true only when you are trying it out.

@camilamacedo86
Copy link
Member Author

camilamacedo86 commented Jul 27, 2024

Hi @fengshunli,

By default, ALL APIs/Custom Resource Definitions (CRDs) are not Cluster scoped. When you use the flag --namespaced=false, it will be ClusterScoped.

  • You can check its definition in:

// Namespaced is true if the API is namespaced.
Namespaced bool `json:"namespaced,omitempty"`

  • Then, you can see the condition to add the ClusterScope Marker, which is ONLY set if --namespaced is false:

{{- else if not .Resource.API.Namespaced }}
// +kubebuilder:resource:scope=Cluster

You can also test this behavior locally to validate it:

  1. Run kubebuilder create api --help
    You will see:
--namespaced           resource is namespaced (default true) <- See HERE
  • To see how it works, create a project with kubebuilder init and then:
kubebuilder create api --group ship --version v1beta1 --kind Frigate

Check the marker in the API:

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Frigate is the Schema for the frigates API
type Frigate struct {
....
  • Next, run with the namespaced flag only:
kubebuilder create api --group ship --version v1beta1 --kind FrigateNamespacedEmpty --namespaced

You will see it still lacks the ClusterScope marker:

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// FrigateNamespacedEmpty is the Schema for the frigatenamespacedempties API
type FrigateNamespacedEmpty struct {
  • Run with --namespaced=true:

kubebuilder create api --group ship --version v1beta1 --kind FrigateNamespacedTrue --namespaced=true

It still lacks the ClusterScope marker (default behavior):

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// FrigateNamespacedTrue is the Schema for the frigatenamespacedtrues API
type FrigateNamespacedTrue struct {
....
  • Finally, run with --namespaced=false:

kubebuilder create api --group ship --version v1beta1 --kind FrigateNamespacedFalse --namespaced=false

Now, it includes the ClusterScope marker:

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster // SEE HERE

// FrigateNamespacedFalse is the Schema for the frigatenamespacedfalses API
type FrigateNamespacedFalse struct {
....

I hope this helps!

@camilamacedo86
Copy link
Member Author

We have an approval already/lgtm
Also, we can always accept contributions for improvements in follow up PRs
So, moving forward with this one

@camilamacedo86 camilamacedo86 added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 27, 2024
@k8s-ci-robot k8s-ci-robot merged commit eb97367 into kubernetes-sigs:master Jul 27, 2024
18 checks passed
@camilamacedo86 camilamacedo86 deleted the pr-scope branch July 28, 2024 09:20
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants