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

Release 6.4.0-beta.17 #7237

Merged
merged 5 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Lens Desktop Core ("OpenLens")

[![Build Status](https://github.com/lensapp/lens/actions/workflows/test.yml/badge.svg)](https://github.com/lensapp/lens/actions/workflows/test.yml)
[![Chat on Slack](https://img.shields.io/badge/chat-on%20slack-blue.svg?logo=slack&longCache=true&style=flat)](https://k8slens.dev/slack.html)
<img src="https://upload.wikimedia.org/wikipedia/commons/1/17/Discourse_icon.svg" width=25>[Explore our Forums](https://forums.k8slens.dev)

## The Repository

This repository is where Team Lens develops the core of the [Lens Desktop](https://k8slens.dev) product together with the community.
This repository is where Team Lens develops the core of the [Lens Desktop](https://k8slens.dev) product together with the community.

The core is a library, powered by [Electron](https://www.electronjs.org/) and [React](https://reactjs.org/). Unlike generic Electron + React frameworks / boilerplates, it is very opinionated for creating Lens Desktop-like applications and has support for Lens Extensions.

Expand All @@ -31,4 +31,4 @@ See [Contributing](https://docs.k8slens.dev/contributing/) page.

## License

See [License](LICENSE).
See [License](LICENSE).
20 changes: 10 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ To install your first extension you should goto the [extension page](lens://app/

This documentation describes:

* How to build, run, test, and publish an extension.
* How to take full advantage of the Lens Extension API.
* Where to find [guides](extensions/guides/README.md) and [code samples](https://github.com/lensapp/lens-extension-samples) to help get you started.
- How to build, run, test, and publish an extension.
- How to take full advantage of the Lens Extension API.
- Where to find [guides](extensions/guides/README.md) and [code samples](https://github.com/lensapp/lens-extension-samples) to help get you started.

## What Extensions Can Do

Here are some examples of what you can achieve with the Extension API:

* Add custom components & views in the UI - Extending the Lens Workbench
- Add custom components & views in the UI - Extending the Lens Workbench

For an overview of the Lens Extension API, refer to the [Common Capabilities](extensions/capabilities/common-capabilities.md) page. [Extension Guides Overview](extensions/guides/README.md) also includes a list of code samples and guides that illustrate various ways of using the Lens Extension API.

## How to Build Extensions

Here is what each section of the Lens Extension API docs can help you with:

* **Getting Started** teaches fundamental concepts for building extensions with the Hello World sample.
* **Extension Capabilities** dissects Lens's Extension API into smaller categories and points you to more detailed topics.
* **Extension Guides** includes guides and code samples that explain specific usages of Lens Extension API.
* **Testing and Publishing** includes in-depth guides on various extension development topics, such as testing and publishing extensions.
* **API Reference** contains exhaustive references for the Lens Extension API, Contribution Points, and many other topics.
- **Getting Started** teaches fundamental concepts for building extensions with the Hello World sample.
- **Extension Capabilities** dissects Lens's Extension API into smaller categories and points you to more detailed topics.
- **Extension Guides** includes guides and code samples that explain specific usages of Lens Extension API.
- **Testing and Publishing** includes in-depth guides on various extension development topics, such as testing and publishing extensions.
- **API Reference** contains exhaustive references for the Lens Extension API, Contribution Points, and many other topics.

## What's New

Expand All @@ -45,7 +45,7 @@ See the [Lens v4 to v5 extension migration notes](extensions/extension-migration

## Looking for Help

If you have questions for extension development, try asking on the [Lens Dev Slack](http://k8slens.slack.com/). It's a public chatroom for Lens developers, where Lens team members chime in from time to time.
If you have questions for extension development, try asking on the [Lens Forums](http://forums.k8slens.dev/). It's a public chatroom for Lens developers, where Lens team members chime in from time to time.

To provide feedback on the documentation or issues with the Lens Extension API, create new issues at [lensapp/lens](https://github.com/lensapp/lens/issues). Please use the labels `area/documentation` and/or `area/extension`.

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"packages": [
"packages/*"
],
"version": "6.4.0-beta.16",
"version": "6.4.0-beta.17",
"npmClient": "yarn",
"npmClientArgs": [
"--network-timeout=100000"
Expand Down
48 changes: 24 additions & 24 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ edit_uri: ""
nav:
- Overview: README.md
- Getting Started:
- Overview: extensions/get-started/overview.md
- Your First Extension: extensions/get-started/your-first-extension.md
- Extension Anatomy: extensions/get-started/anatomy.md
- Wrapping Up: extensions/get-started/wrapping-up.md
- Overview: extensions/get-started/overview.md
- Your First Extension: extensions/get-started/your-first-extension.md
- Extension Anatomy: extensions/get-started/anatomy.md
- Wrapping Up: extensions/get-started/wrapping-up.md
- Extension Capabilities:
- Common Capabilities: extensions/capabilities/common-capabilities.md
- Styling: extensions/capabilities/styling.md
- Common Capabilities: extensions/capabilities/common-capabilities.md
- Styling: extensions/capabilities/styling.md
- Extension Guides:
- Overview: extensions/guides/README.md
- Generator: extensions/guides/generator.md
- Main Extension: extensions/guides/main-extension.md
- Renderer Extension: extensions/guides/renderer-extension.md
- Catalog: extensions/guides/catalog.md
- Resource Stack: extensions/guides/resource-stack.md
- Extending KubernetesCluster: extensions/guides/extending-kubernetes-cluster.md
- Stores: extensions/guides/stores.md
- Working with MobX: extensions/guides/working-with-mobx.md
- Protocol Handlers: extensions/guides/protocol-handlers.md
- IPC: extensions/guides/ipc.md
- Overview: extensions/guides/README.md
- Generator: extensions/guides/generator.md
- Main Extension: extensions/guides/main-extension.md
- Renderer Extension: extensions/guides/renderer-extension.md
- Catalog: extensions/guides/catalog.md
- Resource Stack: extensions/guides/resource-stack.md
- Extending KubernetesCluster: extensions/guides/extending-kubernetes-cluster.md
- Stores: extensions/guides/stores.md
- Working with MobX: extensions/guides/working-with-mobx.md
- Protocol Handlers: extensions/guides/protocol-handlers.md
- IPC: extensions/guides/ipc.md
- Testing and Publishing:
- Testing Extensions: extensions/testing-and-publishing/testing.md
- Publishing Extensions: extensions/testing-and-publishing/publishing.md
- Testing Extensions: extensions/testing-and-publishing/testing.md
- Publishing Extensions: extensions/testing-and-publishing/publishing.md
- API Reference: extensions/api/README.md
theme:
name: 'material'
name: "material"
highlightjs: true
language: 'en'
language: "en"
custom_dir: docs/custom_theme
favicon: img/favicon.ico
logo: img/lens-logo-icon.svg
Expand Down Expand Up @@ -79,9 +79,9 @@ extra:
- icon: fontawesome/brands/twitter
link: https://twitter.com/k8slens
name: Lens on Twitter
- icon: fontawesome/brands/slack
link: http://k8slens.slack.com/
name: Lens on Slack
- icon: fontawesome/brands/discourse
link: https://forums.k8slens.dev/
name: Lens Forums
- icon: fontawesome/solid/link
link: https://k8slens.dev/
name: Lens Website
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "",
"description": "Lens Desktop Core",
"homepage": "https://github.com/lensapp/lens",
"version": "6.4.0-beta.16",
"version": "6.4.0-beta.17",
"repository": {
"type": "git",
"url": "git+https://github.com/lensapp/lens.git"
Expand Down
38 changes: 34 additions & 4 deletions packages/core/src/common/k8s-api/__tests__/api-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { KubeObject } from "../kube-object";
import { KubeObjectStore } from "../kube-object.store";
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";

// eslint-disable-next-line no-restricted-imports
import { KubeApi as ExternalKubeApi } from "../../../extensions/common-api/k8s-api";

class TestApi extends KubeApi<KubeObject> {
protected async checkPreferredVersion() {
return;
Expand Down Expand Up @@ -54,7 +57,7 @@ describe("ApiManager", () => {
});

describe("registerApi", () => {
it("re-register store if apiBase changed", async () => {
it("re-register store if apiBase changed", () => {
const apiBase = "apis/v1/foo";
const fallbackApiBase = "/apis/extensions/v1beta1/foo";
const kubeApi = new TestApi({
Expand All @@ -72,21 +75,48 @@ describe("ApiManager", () => {
logger: di.inject(loggerInjectable),
}, kubeApi);

apiManager.registerApi(apiBase, kubeApi);
apiManager.registerApi(kubeApi);

// Define to use test api for ingress store
Object.defineProperty(kubeStore, "api", { value: kubeApi });
apiManager.registerStore(kubeStore, [kubeApi]);
apiManager.registerStore(kubeStore);

// Test that store is returned with original apiBase
expect(apiManager.getStore(kubeApi)).toBe(kubeStore);

// Change apiBase similar as checkPreferredVersion does
Object.defineProperty(kubeApi, "apiBase", { value: fallbackApiBase });
apiManager.registerApi(fallbackApiBase, kubeApi);
apiManager.registerApi(kubeApi);

// Test that store is returned with new apiBase
expect(apiManager.getStore(kubeApi)).toBe(kubeStore);
});
});

describe("technical tests for autorun", () => {
it("given two extensions register apis with the same apibase, settle into using the second", () => {
const apiBase = "/apis/aquasecurity.github.io/v1alpha1/vulnerabilityreports";
const firstApi = Object.assign(new ExternalKubeApi({
objectConstructor: KubeObject,
apiBase,
kind: "VulnerabilityReport",
}), {
myField: 1,
});
const secondApi = Object.assign(new ExternalKubeApi({
objectConstructor: KubeObject,
apiBase,
kind: "VulnerabilityReport",
}), {
myField: 2,
});

void firstApi;
void secondApi;

expect(apiManager.getApi(apiBase)).toMatchObject({
myField: 2,
});
});
});
});
9 changes: 6 additions & 3 deletions packages/core/src/common/k8s-api/api-manager/api-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ export class ApiManager {
const apis = chain(this.dependencies.apis.get().values())
.concat(this.externalApis.values());
const removedApis = new Set(this.apis.values());
const newState = new Map(this.apis);

for (const api of apis) {
removedApis.delete(api);
this.apis.set(api.apiBase, api);
newState.set(api.apiBase, api);
}

for (const api of removedApis) {
for (const [apiBase, storedApi] of this.apis) {
for (const [apiBase, storedApi] of newState) {
if (storedApi === api) {
this.apis.delete(apiBase);
newState.delete(apiBase);
}
}
}

this.apis.replace(newState);
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export const apiKubePrefix = "/api-kube"; // k8s cluster apis

// Links
export const issuesTrackerUrl = "https://github.com/lensapp/lens/issues" as string;
export const slackUrl = "https://k8slens.dev/slack.html" as string;
export const supportUrl = "https://docs.k8slens.dev/support/" as string;
export const docsUrl = "https://docs.k8slens.dev" as string;
export const forumsUrl = "https://forums.k8slens.dev" as string;
7 changes: 5 additions & 2 deletions packages/core/src/extensions/common-api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import isWindowsInjectable from "../../common/vars/is-windows.injectable";
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import getEnabledExtensionsInjectable from "./get-enabled-extensions/get-enabled-extensions.injectable";
import { slackUrl, issuesTrackerUrl } from "../../common/vars";
import { issuesTrackerUrl } from "../../common/vars";
import { buildVersionInjectionToken } from "../../common/vars/build-semantic-version.injectable";
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
import userStoreInjectable from "../../common/user-store/user-store.injectable";
Expand Down Expand Up @@ -53,6 +53,9 @@ export const App = {

return di.inject(isLinuxInjectable);
},
slackUrl,
/**
* @deprecated This value is now `""` and is left here for backwards compatability.
*/
slackUrl: "",
issuesTrackerUrl,
} as const;
18 changes: 15 additions & 3 deletions packages/core/src/extensions/common-api/k8s-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,29 @@ const getKubeApiDeps = (): KubeApiDependencies => {
};
};

export interface ExternalKubeApiOptions {
/**
* If `true` then on creation of the `KubeApi`instance a call to `apiManager.registerApi` will be
* made. This is `true` by default to maintain backwards compatability.
*
* Setting this to `false` might make `KubeObject`'s details drawer stop working.
*
* @default true
*/
autoRegister?: boolean;
}

// NOTE: this is done to preserve `instanceOf` behaviour
function KubeApiCstr<
Object extends KubeObject = KubeObject,
Data extends KubeJsonApiDataFor<Object> = KubeJsonApiDataFor<Object>,
>(opts: KubeApiOptions<Object, Data>) {
>({ autoRegister = true, ...opts }: KubeApiOptions<Object, Data> & ExternalKubeApiOptions) {
const api = new InternalKubeApi(getKubeApiDeps(), opts);

const di = getLegacyGlobalDiForExtensionApi();
const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken);

if (storesAndApisCanBeCreated) {
if (storesAndApisCanBeCreated && autoRegister) {
apiManager.registerApi(api);
}

Expand All @@ -72,7 +84,7 @@ export type KubeApi<
export const KubeApi = KubeApiCstr as unknown as new<
Object extends KubeObject = KubeObject,
Data extends KubeJsonApiDataFor<Object> = KubeJsonApiDataFor<Object>,
>(opts: KubeApiOptions<Object, Data>) => InternalKubeApi<Object, Data>;
>(opts: KubeApiOptions<Object, Data> & ExternalKubeApiOptions) => InternalKubeApi<Object, Data>;

/**
* @deprecated Switch to using `Common.createResourceStack` instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ exports[`extension special characters in page registrations renders 1`] = `
If you have any questions or feedback, please join our
<a
class="link"
href="https://k8slens.dev/slack.html"
href="https://forums.k8slens.dev"
rel="noreferrer"
target="_blank"
>
Lens Community slack channel
Lens Forums
</a>
.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ exports[`navigate to extension page renders 1`] = `
If you have any questions or feedback, please join our
<a
class="link"
href="https://k8slens.dev/slack.html"
href="https://forums.k8slens.dev"
rel="noreferrer"
target="_blank"
>
Lens Community slack channel
Lens Forums
</a>
.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ exports[`add-cluster - navigation using application menu renders 1`] = `
If you have any questions or feedback, please join our
<a
class="link"
href="https://k8slens.dev/slack.html"
href="https://forums.k8slens.dev"
rel="noreferrer"
target="_blank"
>
Lens Community slack channel
Lens Forums
</a>
.
</p>
Expand Down
Loading