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

Teleterm: add support for access requesting kube namespaces #47347

Open
wants to merge 2 commits into
base: lisa/kube-namespace-3
Choose a base branch
from

Conversation

kimlisa
Copy link
Contributor

@kimlisa kimlisa commented Oct 8, 2024

part of #46742

requires:

if you want to test connect, i have a staging cluster that i can invite to then:

  1. OS: check out branch lisa/connect-team (it has all the necessary PRs stiched)
  2. build tsh, and then pnpm start-term and login to my cluster

when request mode requires you to request for namespace

  ... rest of role
  options:
    request_mode:
      kubernetes_resources:
      - kind: namespace   # wildcard '*' enforces the same namespace requirement on the UI (since UI only supports namespace selection)
image

when request mode is a kind that UI doesn't support, it disables the checkout regardless of other resources (it is enabled once user removes the kubernetes):

  ... rest of role
  options:
    request_mode:
      kubernetes_resources:
      - kind: pod   # only namespace is supported on the web UI, tsh supports all
image

demo (when no request mode is specified, allows requesting for a kube_cluster or a kube_clusters namespace):

  ... rest of role
  options:
    # no request mode defined
Screen.Recording.2024-10-08.at.11.58.11.PM.mov

changelog: Add Connect support for selecting Kubernetes namespaces during access requests

Copy link

github-actions bot commented Oct 8, 2024

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@kimlisa kimlisa requested review from ravicious and removed request for ryanclark October 8, 2024 16:45
Copy link

github-actions bot commented Oct 8, 2024

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@kimlisa kimlisa force-pushed the lisa/teleterm-kube-namespace branch from 357f75a to 65cb297 Compare October 9, 2024 06:17
@@ -110,12 +114,21 @@ export function AccessRequestCheckout() {
setShowCheckout(false);
}

const filteredData = data?.filter(d =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we the need optional chaining here.

excludeKubeClusterWithNamespaces(d, data)
);

const numAddedResources = filteredData?.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

And here.

@@ -258,6 +299,7 @@ export type ResourceRequest =
kind: 'kube';
resource: {
uri: KubeUri;
namespaces?: KubeResourceNamespaceUri[];
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unused, no?

But I wonder if it wouldn't be more convenient to keep the selected namespaces here, instead of having them as a separate resource (line 313).
Pros:

  1. We wouldn't need to remember about removing kube_cluster resources (from UI/API requests) when there are namespaces selected.
  2. We wouldn't have to remove namespaces manually when a "parent" kube_cluster is removed from the access request.

Cons:

  1. This would differ from shared types where the namespace is a regular requestable resource. OTOH I feel that the proposed data model is more correct.

I can imagine having a function like this one in AccessRequestsService:

  async addOrRemoveKubeNamespace(resourceUri: KubeResourceNamespaceUri) {
    this.setState(draftState => {
      if (draftState.pending.kind !== 'resource') {
        throw new Error('Cannot add a kube namespace to a role access request');
      }

      const { resources } = draftState.pending;

      const requestedResource = resources.get(
        routing.getKubeUri(
          routing.parseKubeResourceNamespaceUri(resourceUri).params
        )
      );
      if (!requestedResource || requestedResource.kind !== 'kube') {
        throw new Error('Cannot add a kube namespace to a non-kube resource');
      }
      const kubeResource = requestedResource.resource;
      if (!kubeResource.namespaces) {
        kubeResource.namespaces = new Set();
      }
      if (kubeResource.namespaces.has(resourceUri)) {
        kubeResource.namespaces.delete(resourceUri);
      } else {
        kubeResource.namespaces.add(resourceUri);
      }
    });
  }

Please let me know what do you think about it :)

kubernetesCluster: kubeCluster,
kubernetesNamespace: '',
});
return response.resources.map(i => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of returning Promise<string> here?
We could do the mapping to Option in KubeNamespaceSelector.

@pnrao1983 pnrao1983 added the c-svt Internal Customer Reference label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-svt Internal Customer Reference size/md ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants