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

Web: Define fetch kube resource web api endpoint #46741

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kimlisa
Copy link
Contributor

@kimlisa kimlisa commented Sep 18, 2024

part of #46742

Opens a new web api endpoint where we can fetch kube sub resources such as namespaces, pods, secrets, etc (we are currently only utilizing namespace for now though)

Added all the boilerplate code like adding types etc.

@kimlisa kimlisa added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v16 labels Sep 18, 2024
@@ -869,6 +869,7 @@ func (h *Handler) bindDefaultEndpoints() {
// Kube access handlers.
h.GET("/webapi/sites/:site/kubernetes", h.WithClusterAuth(h.clusterKubesGet))
h.GET("/webapi/sites/:site/pods", h.WithClusterAuth(h.clusterKubePodsGet))
h.GET("/webapi/sites/:site/kubernetes/resources", h.WithClusterAuth(h.clusterKubeResourcesGet))
Copy link
Contributor Author

@kimlisa kimlisa Sep 18, 2024

Choose a reason for hiding this comment

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

i added a generic endpoint to allow requesting any kube sub resources @tigrato

Copy link
Contributor

Choose a reason for hiding this comment

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

You can drop the h.GET("/webapi/sites/:site/pods", h.WithClusterAuth(h.clusterKubePodsGet)) endpoint.
It was never used and will be replaced by h.GET("/webapi/sites/:site/kubernetes/resources", h.WithClusterAuth(h.clusterKubeResourcesGet))

@@ -869,6 +869,7 @@ func (h *Handler) bindDefaultEndpoints() {
// Kube access handlers.
h.GET("/webapi/sites/:site/kubernetes", h.WithClusterAuth(h.clusterKubesGet))
h.GET("/webapi/sites/:site/pods", h.WithClusterAuth(h.clusterKubePodsGet))
h.GET("/webapi/sites/:site/kubernetes/resources", h.WithClusterAuth(h.clusterKubeResourcesGet))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can drop the h.GET("/webapi/sites/:site/pods", h.WithClusterAuth(h.clusterKubePodsGet)) endpoint.
It was never used and will be replaced by h.GET("/webapi/sites/:site/kubernetes/resources", h.WithClusterAuth(h.clusterKubeResourcesGet))

return nil, trace.Wrap(err)
}

resp, err := listKubeResources(r.Context(), clt, r.URL.Query(), site.GetName(), r.URL.Query().Get("kind"))
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a validation on kind?

if kind==""{
return trace.BadParameter..
}

if !slices.Contains(types.KubernetesResources, kind){
return trace.BadParameter(kind is not valid, valid kinds %v, types.KubernetesResources)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, i also added a check for empty kube cluster since that's also required

Copy link
Contributor

@tigrato tigrato left a comment

Choose a reason for hiding this comment

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

From my side, all good.
Thanks @kimlisa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v16 no-changelog Indicates that a PR does not require a changelog entry size/md ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants