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

Adds function for parsing list #103

Merged
merged 2 commits into from
Jul 21, 2020

Conversation

somtochiama
Copy link
Member

No description provided.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 7, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @somtochiama. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jul 7, 2020
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 7, 2020
@somtochiama
Copy link
Member Author

/assign @justinsb

@@ -403,3 +411,30 @@ func (r *Reconciler) IsKustomizeOptionUsed() bool {
func (r *Reconciler) SetSink(sink Sink) {
r.options.sink = sink
}

func parseListKind(infos *manifest.Objects) error{
for i, item := range infos.Items{
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: gofmt needed, I think


func parseListKind(infos *manifest.Objects) error{
for i, item := range infos.Items{
if item.Kind == "List" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we should check the group also. The easy way is to check the APIGroup (which sadly includes the version, but I think that's OK)

func parseListKind(infos *manifest.Objects) error{
for i, item := range infos.Items{
if item.Kind == "List" {
fmt.Println("haaa!")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: please remove debug code :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

😅 Will do

fmt.Println("haaa!")
obj := item.UnstructuredObject()

err := obj.EachListItem(func(obj runtime.Object) error{
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice find on EachListItem 👍

obj := item.UnstructuredObject()

err := obj.EachListItem(func(obj runtime.Object) error{
castItem := obj.(*unstructured.Unstructured)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: renaming castItem to itemUnstructured may be clearer (similarly, you might rename obj to itemObject). (I do like rust's ability to redefine variables with the same name but with a different type, avoids these problems)

return err
}

infos.Items = append(infos.Items[:i], infos.Items[i+1:]...)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think leigh was suggesting that it might be easier to just keep a second list:

var out []*manifest.Object

if IsList(obj) {
  out = append(out, extract(obj))
} else {
  out = append(out, obj)
}
return manifest.NewManifest(out)
}

I'm not sure what happens to the iteration when you concurrently modify infos!

@justinsb
Copy link
Contributor

Looks great - thanks @somtochiama

/approve
/lgtm
/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 21, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, SomtochiAma

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 Jul 21, 2020
@k8s-ci-robot k8s-ci-robot merged commit d8f3ce5 into kubernetes-sigs:master Jul 21, 2020
vanou pushed a commit to vanou/kubebuilder-declarative-pattern that referenced this pull request Jul 21, 2020
@somtochiama somtochiama deleted the handle-list-kind branch August 20, 2020 07:25
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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. 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.

None yet

3 participants