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 KubeObjectStatusText extension API #1188

Merged
merged 15 commits into from
Nov 11, 2020

Conversation

nevalla
Copy link
Contributor

@nevalla nevalla commented Oct 30, 2020

Fixes #1118

Usage

// renderer.ts
export default class PodStatusTextExtension extends LensRendererExtension {
 KubeObjectStatusTexts = [
    {
      kind: "Pod",
      apiVersions: ["v1"],
      resolve: (pod: K8sApi.Pod) => resolve(pod)
    }
  ]
}

// pod-status-resolver.tsx
import { K8sApi } from "@k8slens/extensions";

export function resolve(pod: K8sApi.Pod): K8sApi.KubeObjectStatus {
  if (pod.getName().startsWith("nginx-deployment") {
    return {
      level:  K8sApi.KubeObjectStatusLevel.INFO,
      text: "Image scanned",
    }
  }

  return null
}

image

Signed-off-by: Lauri Nevala lauri.nevala@gmail.com

@nevalla nevalla added area/extension Something to related to the extension api enhancement New feature or request labels Oct 30, 2020
@jakolehm
Copy link
Contributor

why not just:

export interface ResourceStatusRegistration {
  kind: string;
  apiVersions: string[];
  resolver: (object: KubeObject) => ResourceStatus | null;
}

where ResourceStatus is an interface with text & color?

@nevalla
Copy link
Contributor Author

nevalla commented Nov 2, 2020

why not just:

export interface ResourceStatusRegistration {
  kind: string;
  apiVersions: string[];
  resolver: (object: KubeObject) => ResourceStatus | null;
}

where ResourceStatus is an interface with text & color?

Much better...will change it.

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
@nevalla nevalla force-pushed the resource-status-text-extension branch from b6693ac to 9faea88 Compare November 4, 2020 13:07
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
@nevalla
Copy link
Contributor Author

nevalla commented Nov 4, 2020

Now all resource lists are using new KubeResourceStatusIcon component instead of KubeEventIcon. New component will display multiple status messages (not only from events) in a tooltip (see the image in the description).

@nevalla nevalla marked this pull request as ready for review November 4, 2020 13:20
@nevalla nevalla requested a review from a team November 4, 2020 13:20
@nevalla nevalla changed the title Implement API ResourceStatusText extension Implement KubeObjectStatusText extension API Nov 4, 2020
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
@@ -2,6 +2,7 @@ export { isAllowedResource } from "../../common/rbac"
export { apiManager } from "../../renderer/api/api-manager";
export { KubeObjectStore } from "../../renderer/kube-object.store"
export { KubeApi, forCluster, IKubeApiCluster } from "../../renderer/api/kube-api";
export type { EventStore } from "../../renderer/components/+events/event.store"
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 we need a separate issue about missing store types?

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
@jakolehm jakolehm added this to the 4.0.0 milestone Nov 5, 2020
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
…xtensions

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
{
kind: "ReplicaSet",
apiVersions: ["v1"],
resolve: (object: K8sApi.KubeObject) => resolveStatus(object)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why some of these use specific types and other use generic KubeObject?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolveStatusFromPods and resolveStatusFromCronJobs requires specific type. I've changed this now to use always specific type to be more consistent.

@@ -29,3 +30,15 @@ export { Role, roleApi } from "../../renderer/api/endpoints";
export { RoleBinding, roleBindingApi } from "../../renderer/api/endpoints";
export { ClusterRole, clusterRoleApi } from "../../renderer/api/endpoints";
export { ClusterRoleBinding, clusterRoleBindingApi } from "../../renderer/api/endpoints";

export type KubeObjectStatus = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does not feel right to have them here, everything else is exported from somewhere outside.

Copy link
Contributor Author

@nevalla nevalla Nov 10, 2020

Choose a reason for hiding this comment

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

Moved these types to separate file where those are exported from now

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
@nevalla
Copy link
Contributor Author

nevalla commented Nov 10, 2020

Tests are now again green. @jakolehm PTAL

Copy link
Contributor

@jakolehm jakolehm left a comment

Choose a reason for hiding this comment

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

LGTM

@jakolehm jakolehm merged commit 85c4a10 into master Nov 11, 2020
@jakolehm jakolehm deleted the resource-status-text-extension branch November 11, 2020 06:57
@jakolehm
Copy link
Contributor

Just realised this PR was missing docs.

pauljwil pushed a commit to pauljwil/lens that referenced this pull request Nov 11, 2020
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
@jakolehm jakolehm mentioned this pull request Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/extension Something to related to the extension api area/ui enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to register text to status column of resource list
3 participants