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

Implement basic functionality of gwctl describe namespace #2836

Merged

Conversation

Devaansh-Kumar
Copy link
Contributor

@Devaansh-Kumar Devaansh-Kumar commented Mar 2, 2024

What type of PR is this?
Add one of the following kinds:
/area gwctl
/kind feature
/cc @gauravkghildiyal

What this PR does / why we need it:
Implement gwctl describe namespace command

Which issue(s) this PR fixes:
Fixes #2795

Does this PR introduce a user-facing change?:

Implemented command `gwctl describe namespace`

@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. area/gwctl do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 2, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @Devaansh-Kumar. 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.

@Devaansh-Kumar
Copy link
Contributor Author

@gauravkghildiyal I have implemented the command as close as I could according to your guidlines.
The output for a sample test case come out as:
Screenshot from 2024-03-04 22-47-28

However I have one question about the format of output: If kubectl apply is used instead of kubectl create to create a namespace from a yaml file, then the annotation kubectl.kubernetes.io/last-applied-configuration is set which might not look very good in the output:
image

Do you think it is alright to leave it as it is?

@Devaansh-Kumar Devaansh-Kumar marked this pull request as ready for review March 4, 2024 17:57
@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 Mar 4, 2024
@gauravkghildiyal
Copy link
Member

/assign

Copy link
Member

@gauravkghildiyal gauravkghildiyal 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 almost there Devaansh! Just a couple of suggestions and we should be good. Thanks you!

On the topic of whether to exclude last-applied-configuration, I think leaving that should be just fine. We will always have the possibility of some line spreading across multiple lines (based on the width of the output screen) but that should normally not be reason enough to remove that field entirely.

@@ -246,11 +247,15 @@ func (b *BackendNode) ID() backendID {
)
}

// HTTPRouteNode models the relationships and dependencies of a Namespace.
// NamespaceNode models the relationships and dependencies of a Namespace.
type NamespaceNode struct {
// NamespaceName identifies the Namespace.
NamespaceName string
Copy link
Member

Choose a reason for hiding this comment

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

Lets replace the NamespaceName with the actual corev1.Namespace resource. This would make this node consistent with how the other nodes are defined -- where nodes are simply wrappers over the underlying base resource. This would also mean that we don't need to define each field of the Namepace individually in the node here.

This means that now:

  1. We can modify the ResourceModel.addNamespace() to accept namespaces ...corev1.Namespace and not need a separate addNamespaceWithLabelsAnnotationsStatus
  2. Within Discoverer.discoverNamespaces(), we would fetch all corev1.Namespace resources. Then, while iterating over the existing resources, once we figure out the namespace of the resource, we call addNamespace() and pass in the corev1.Namespace that we would have already fetched.

Copy link
Contributor Author

@Devaansh-Kumar Devaansh-Kumar Mar 6, 2024

Choose a reason for hiding this comment

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

Ok I understood what you are asking for

DirectlyAttachedPolicies []policymanager.ObjRef `json:",omitempty"`
}

func (nsp *NamespacesPrinter) PrintDescribeView(resourceModel *resourcediscovery.ResourceModel) {
Copy link
Member

Choose a reason for hiding this comment

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

Lets add a test for this as well. (You can use some other tests like those for gateway and httproute for examples on how they can be written)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I was planning to add that in a seperate PR, but I will do it in this one PR itself now.


resourceModel, err := discoverer.DiscoverResourcesForNamespace(filter)
if err != nil {
panic(err)
Copy link
Member

Choose a reason for hiding this comment

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

Forgot to call this out. @pottekkat is working on fixing the panics that we currently have in the codebase. Lets try to ensure that the new code we're adding tries to properly write to the correct output stream (instead of panic'ing)

Ref #2825 for relevant changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood, I need to just replace panic(err) with

fmt.Fprintf(os.Stderr, "relevant error message: %v\n", err)
os.Exit(1) 

wherever I have made code changes right?

@Devaansh-Kumar
Copy link
Contributor Author

Devaansh-Kumar commented Mar 6, 2024

@gauravkghildiyal I have made the suggested changes, please review them

@gauravkghildiyal
Copy link
Member

Thanks @Devaansh-Kumar!

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Devaansh-Kumar, gauravkghildiyal

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 Mar 8, 2024
@gauravkghildiyal
Copy link
Member

@Devaansh-Kumar

Please use the provided template in the PR description to unblock the automatic merge

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, please enter a release note below:
-->
```release-note

```

@gauravkghildiyal
Copy link
Member

/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. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 8, 2024
@gauravkghildiyal
Copy link
Member

Looks like there's a couple of tests as well that will need to be fixed as part of the change. :) (Shouldn't likely be very problematic)

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 8, 2024
@Devaansh-Kumar
Copy link
Contributor Author

@gauravkghildiyal I have fixed the failing test in httproute_test.go. The pull-gateway-api-test is now passing.

@gauravkghildiyal
Copy link
Member

Thanks!

Please take not of #2836 (comment), and also rebase

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 2024
@gauravkghildiyal
Copy link
Member

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 10, 2024
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 10, 2024
@Devaansh-Kumar
Copy link
Contributor Author

@gauravkghildiyal I have rebased and updated the PR message

@gauravkghildiyal
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 11, 2024
@k8s-ci-robot k8s-ci-robot merged commit 8e7ffc3 into kubernetes-sigs:main Mar 11, 2024
8 checks passed
hanxiaop pushed a commit to hanxiaop/gateway-api that referenced this pull request Mar 13, 2024
…-sigs#2836)

* Implement basic functionality of gwctl describe namespace

* Finalized printing of gwctl describe namespace command

* Added test for gwctl describe namespace and modified ResourceModel.addNamespace() function to accept corev1.Namespace

* Fixed failing httproutes test and Makefile
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. area/gwctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement gwctl describe namespaces
3 participants