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

🐛 Make topology markers also valid for type definitions #692

Merged

Conversation

chrischdi
Copy link
Member

This PR allows setting listMapKey, listType, mapType and structType at both type and field level to allow setting them at typed slices too.

Currently the markers are only valid at the field level.

The markers are important for defining CRDs which should get used in combination with Server-Side Apply (xref SSA).

Fixes: #435

Example

When a struct references a typed slice it is currently not possible to set the markers.
Example:

type BarSpec struct {
	Foos Foos `json:"foos,omitempty"`
}

type Foos []Foo
  • When setting it at field level, controller-gen will throw errors because the detected type is empty / ""
    /tmp/test-ct/api/v1beta1/bar_types.go:32:2: must apply listType to an array, found
    /tmp/test-ct/api/v1beta1/bar_types.go:32:2: must apply listMapKey to an array, found
    
  • At type level the markers are currently ignored.

After this PR, setting the markers will be possible at type level too, where the type information will be available:

type BarSpec struct {
	Foos Foos `json:"foos,omitempty"`
}

// +listType=map
// +listMapKey=id
type Foos []Foo

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 15, 2022
@FillZpp
Copy link
Contributor

FillZpp commented Jun 16, 2022

@chrischdi Thanks. Please add some test cases in integration test, and you may also have to test the case that the markers defined on both type and field, like this:

type BarSpec struct {
        // +listType=map
        // +listMapKey=id
	Foos Foos `json:"foos,omitempty"`
}

// +listType=map
// +listMapKey=id
type Foos []Foo

@chrischdi chrischdi force-pushed the pr-topology-markers-to-type branch from 2ec1219 to 9e2b90e Compare June 20, 2022 07:24
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 20, 2022
@chrischdi
Copy link
Member Author

Hi @FillZpp , thank you for the feedback 👍

I added a test case similar to

// +listType=map
// +listMapKey=id
type Foos []Foo

However it is not possible to add:

type BarSpec struct {
	// +listType=map
	// +listMapKey=name
	// +listMapKey=secondary
	Foos Foos `json:"foos,omitempty"`
}

Because this will fail at the following marker checks:

The information if it is an array or not is not available there (it is empty string in this case), which is why this PR introduces the possibility to set the markers at the type definition instead.

@chrischdi chrischdi force-pushed the pr-topology-markers-to-type branch from 9e2b90e to 3ea6625 Compare June 20, 2022 07:33
@FillZpp
Copy link
Contributor

FillZpp commented Jun 24, 2022

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, chrischdi

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 Jun 27, 2022
@alvaroaleman
Copy link
Member

/cherrypick release-0.9

@k8s-infra-cherrypick-robot

@alvaroaleman: once the present PR merges, I will cherry-pick it on top of release-0.9 in a new PR and assign it to you.

In response to this:

/cherrypick release-0.9

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-infra-cherrypick-robot

@alvaroaleman: new pull request created: #693

In response to this:

/cherrypick release-0.9

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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.

Flaky behaviour using custom slice types and listType marker
5 participants