1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Merge branch 'master' into logs-search

This commit is contained in:
Alex Andreev 2020-11-09 14:21:16 +03:00
commit b67d367022
70 changed files with 1387 additions and 119 deletions

View File

@ -1,17 +0,0 @@
---
area/ui:
- src/renderer/**/*
area/test:
- integration/**/*
- __mocks__/**/*
area/extension:
- extensions/**/*
- src/extensions/**/*
area/documentation:
- README.md
- docs/**/*
area/ci:
- .github/workflows/**/*
- .azure-pipelines.yml
dependencies:
- yarn.lock

View File

@ -1,15 +0,0 @@
---
name: "Pull Request Labeler"
on:
- pull_request
jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v2
if: github.repository == 'lensapp/lens'
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/labeler-config.yml

49
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,49 @@
name: Publish docs via GitHub Pages
on:
push:
branches:
- master
jobs:
build:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install git+https://${{ secrets.GH_TOKEN }}@github.com/lensapp/mkdocs-material-insiders.git
pip install mkdocs-git-revision-date-localized-plugin mike
- name: Checkout Release from lens
uses: actions/checkout@v2
with:
repository: lensapp/lens
- name: git config
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git pull
- name: mkdocs deploy latest
run: |
mike deploy --push latest
- name: mkdocs deploy new release / tag
if: contains(github.ref, 'refs/tags/v')
run: |
mike deploy --push--update-aliases ${{ github.ref }} latest
mike set-default --push ${{ github.ref }}

View File

@ -45,6 +45,16 @@ Allows for faster separate re-runs of some of the more involved processes:
1. `yarn dev:extension-types` compile declaration types for `@k8slens/extensions` 1. `yarn dev:extension-types` compile declaration types for `@k8slens/extensions`
1. `yarn dev-run` runs app in dev-mode and auto-restart when main process file has changed 1. `yarn dev-run` runs app in dev-mode and auto-restart when main process file has changed
## Development (documentation)
Run a local instance of `mkdocs serve` in a docker container for developing the Lens Documentation.
> Prerequisites: docker, yarn
* `yarn mkdocs-serve-local` - local build and serve of mkdocs with auto update enabled
Go to [localhost:8000](http://127.0.0.1:8000)
## Developer's ~~RTFM~~ recommended list: ## Developer's ~~RTFM~~ recommended list:
- [TypeScript](https://www.typescriptlang.org/docs/home.html) (front-end/back-end) - [TypeScript](https://www.typescriptlang.org/docs/home.html) (front-end/back-end)
@ -53,6 +63,8 @@ Allows for faster separate re-runs of some of the more involved processes:
- [ElectronJS](https://www.electronjs.org/docs) (chrome/node) - [ElectronJS](https://www.electronjs.org/docs) (chrome/node)
- [NodeJS](https://nodejs.org/dist/latest-v12.x/docs/api/) (api docs) - [NodeJS](https://nodejs.org/dist/latest-v12.x/docs/api/) (api docs)
## Contributing ## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/lensapp/lens. Bug reports and pull requests are welcome on GitHub at https://github.com/lensapp/lens.

1
docs/CNAME Normal file
View File

@ -0,0 +1 @@
docs.k8slens.dev

21
docs/README.md Normal file
View File

@ -0,0 +1,21 @@
# Overview
Lens is the most powerful Kubernetes IDE on the market. It is a standalone application, and it is available on macOS, Windows, and Linux. Some of the benefits of using Lens include:
* Confidence that your clusters are properly setup and configured.
* Increased visibility, real time statistics, log streams, and hands-on troubleshooting capabilities.
* The ability to work with your clusters quickly and easily, radically improving productivity and the speed of business.
Watch this introductory video to see Lens in action:
[![Screenshot](img/lens-intro-video-screenshot.png)](https://youtu.be/04v2ODsmtIs)
**Note:** Use CTRL+click (on Windows and Linux) or CMD+click (on MacOS) to open the above in a new tab
## Downloading Lens
[Download Lens](https://github.com/lensapp/lens/releases) for macOS, Windows, or Linux.
## Quick Start
Get up and running quickly by learning to [add clusters](clusters/adding-clusters.md).

View File

@ -0,0 +1,16 @@
# Adding clusters
Add clusters by clicking the **Add Cluster** button in the left-side menu.
1. Click the **Add Cluster** button (indicated with a '+' icon).
2. Enter the path to your kubeconfig file. You'll need to have a kubeconfig file for the cluster you want to add. You can either browse for the path from the file system or or enter it directly.
Selected [cluster contexts](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#context) are added as a separate item in the left-side cluster menu to allow you to operate easily on multiple clusters and/or contexts.
**NOTE**: Any cluster that you added manually will not be merged into your kubeconfig file.
![Add Cluster](images/add-cluster.png)
For more information on kubeconfig see [Kubernetes docs](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/).
To see your currently-enabled config with `kubectl`, enter `kubectl config view --minify --raw` in your terminal.

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

View File

@ -0,0 +1,12 @@
# Removing clusters
Remove Lens clusters using the context menu that appears when you right-click the cluster in the left-side menu that you want to remove.
To remove a cluster from your cluster list:
1. Right-click the name of the cluster in the left-side menu that you want to remove.
2. Click **Remove**.
**NOTE**: This will only remove the cluster from your Lens cluster list. It will not affect your actual Kubernetes cluster or its configuration.
![Remove Cluster](images/remove-cluster.png)

75
docs/clusters/settings.md Normal file
View File

@ -0,0 +1,75 @@
# Settings
It is easy to configure Lens Clusters to your liking through its various settings.
1. Right-click the name of the cluster in the left-side menu that you want to open the settings for.
2. Click **Settings**.
![Cluster settings](images/cluster-context-menu.png)
## Status
Overview of the cluster status
### Cluster Status
Cluster status information including the detected distribution, kernel version, API endpoint, and online status
![Cluster settings status](images/cluster-settings-status.png)
## General
General cluster settings
### Cluster Name
The cluster name is inheritated by default from the kubeconfig file. Change the cluster name to another value by updating it here. Note that doing so does not update your kubeconfig file.
### Workspace
This is the Lens workspace that the cluster is associated with. Change workspaces by selecting a different workspace from the dropdown menu. Create a new workspace by clicking **workspace** in "Define cluster workspace" above the dropdown menu. This option will take you the workspaces editor. Create a new workspace and then navigate back to cluster settings.
### Cluster Icon
Lens randomly generates an icon to associate with each newly-created cluster. Use this setting to choose your own icon.
### HTTP Proxy
Some users will need to define an HTTP proxy for communicating with the Kubernetes API. Use this setting to do so.
### Prometheus
Lens can be configured to query a Prometheus server installed in the cluster. Select a query format by choosing either to auto-detect or from the following configurations:
* Lens
* Helm Operator
* Prometheus Operator
* Stacklight
To learn more about custom Prometheus configurations, please refer to this [guide](https://github.com/lensapp/lens/blob/master/troubleshooting/custom-prometheus.md).
### Working Directory
Use this field to set the terminal working directory. The default is `$HOME`.
![Cluster settings general](images/cluster-settings-general.png)
## Features
Additional Lens features that can be installed by the user
### Metrics
Enable timeseries data visualization (Prometheus stack) for your cluster. Install this only if you don't have existing Prometheus stack installed.
### User Mode
User Mode feature enables non-admin users to see namespaces they have access to. This is achieved by configuring RBAC rules so that every authenticated user is granted to list namespaces.
![Cluster settings features](images/cluster-settings-features.png)
## Removal
Use this setting to remove the current cluster.
![Cluster settings removal](images/cluster-settings-removal.png)

View File

@ -0,0 +1,17 @@
# Contributing
There are multiple ways you can contribute to Lens - even if you are not a developer, you can still contribute. We are always looking for assistance with creating or updating documentation, testing the application, reporting and troubleshooting issues.
Here are some ideas how you can contribute!
* [Development](./development.md) Help making Lens better.
* [Maintaining the Project](./maintainers.md) Become community maintainer and help us maintain the project.
* [Extension Development](../extensions) Add integrations via Lens Extensions.
* [Documentation](./documentation.md) Help improve Lens documentation.
* [Promotion](./promotion.md) Show your support, be an ambassador to Lens, write blogs and make videos!
If you are an influencer, blogger or journalist, feel free to [spread the word](./promotion.md)!
## Code of Conduct
This project adheres to the [Contributor Covenant](https://www.contributor-covenant.org/) code of conduct. By participating and contributing to Lens, you are expected to uphold this code. Please report unacceptable behaviour to info@k8slens.dev

View File

@ -0,0 +1,3 @@
# Development
TBD

View File

@ -0,0 +1,22 @@
# Documentation
We are glad to see you are interested in contributing to Lens documentation. If this is the first Open Source project you will contribute to, we strongly suggest reading GitHub's excellent guide: [How to Contribute to Open Source](https://opensource.guide/how-to-contribute).
## Finding Documentation Issues to Work On
You can find a list of open documentation related issues [here](https://github.com/lensapp/lens/issues?q=is%3Aopen+is%3Aissue+label%3Aarea%2Fdocumentation). When you find something you would like to work on:
1. Express your interest to start working on an issue via comments.
2. One of the maintainers will assign the issue for you.
3. You can start working on the issue. Once done, simply submit a pull request.
## Requirements for Documentation Pull Requests
When you create a new pull request, we expect some requirements to be met.
* Follow this naming convention for Pull Requests:
* When adding new documentation, add `New Documentation:` before the title. E.g. `New Documentation: Getting Started`
* When fixing documentation, add `Fix Documentation:` before the title. E.g. `Fix Documentation: Getting Started`
* When updating documentation, add `Update Documentation:` before the title. E.g. `Update Documentation: Getting Started`
* If your Pull Request closes an issue you need to write `Closes #ISSUE_NUMBER` where the ISSUE_NUMBER is the number in the end of the link url that will link your pull request to the issue, when merged will close that issue.
* For each pull request made, we run tests to check if there are any broken links, the markdown formatting is valid and the linter is passing.

View File

@ -0,0 +1,17 @@
# Maintainers
We are looking for community maintainers for the Lens project. Maintainers will be added to a special team with write permissions. These permissions consist of opening, closing, tagging and editing issues, and pull requests, as well as create and delete non protected branches.
The responsibilities of a community maintainer are listed below.
## Issues Triage
* **Labeling Issues:** Label issues accordingly.
* **Finding Duplicates:** Finding and closing duplicate issues.
* **Doing First Level Contact:** Getting more information on the issues (like version number or asking for clarification) if needed.
* **Closing Irrelevant Issues:** Closing issues that are determined irrelevant, no longer needed, not relevant to the project and/or doesn't follow the issues guidelines.
## Help with Contributions
* **Help Manage Pull Requests:** Help the author of the pull request with any problems.
* **Contributing:** Create pull requests to help maintain and drive the project forward.

View File

@ -0,0 +1,27 @@
# Promoting
Help promote Lens! If you are not a developer (or even if you are), you can still contribute to the project, a lot, by helping us promote it. As we are a free open source project, the community is our most important asset, so here are some ways that you can help the project continue to grow.
## Follow, Like, Recommend, Favorite, Vote and Star Us
There are many sites where you can vote, recommend, favorite and star us.
* [Twitter](https://twitter.com/k8slens) - Like, comment and retweet our posts, and follow us on Twitter
* [Medium](https://medium.com/k8slens) - Give claps to our articles and follow us on Medium
* [GitHub](https://github.com/lensapp/lens) - Become a stargazer on GitHub
* [StackShare](https://stackshare.io/lens) - Indicate you are using Lens and follow us on StackShare
* [Reddit](https://www.reddit.com/search/?q=lens%20kubernetes&sort=new) - Upvote and be an ambassador of Lens by participating relevant discussions on Reddit
* [Hacker News](https://hn.algolia.com/?dateRange=all&page=0&prefix=false&query=lens%20kubernetes&sort=byDate&type=story) - Upvote and be an ambassador of Lens by participating relevant discussions on Hacker News
## Write Blogs or Make Videos About Us
Here are some nice blog posts and videos about our project for you to get some inspiration:
[Onboard AWS EKS Cluster on Lens(Kubernetes IDE)](https://dev.to/himwad05/onboard-aws-eks-cluster-on-lens-kubernetes-ide-492l)
[Using Lens to Manage All Your Kubernetes Cluster](https://medium.com/@magicmagnate/using-lens-to-manage-all-your-kubernetes-cluster-c1ef88fdb476)
[Kontena Lens - Beautiful Kubernetes UI](https://www.youtube.com/watch?v=YGgaiGdYfdI)
[Gerenciando Kubernetes com Lens e Octant](https://www.youtube.com/watch?v=h9ZqDelJLQQ)
[Walkthrough of Kubernetes IDE - Lens](https://www.youtube.com/watch?v=602aHZSdEfY)
[LENS - Interfaz Gráfica para Kubernetes en 1 PASO.](https://www.youtube.com/watch?v=DFMKcR4BqwM)
Psst... If you have created some content around Lens, let us know!

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block analytics %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-90E1JB4HW4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-90E1JB4HW4');
</script>
{% endblock %}

48
docs/extensions/README.md Normal file
View File

@ -0,0 +1,48 @@
# Lens Extension API
The Extensions API in Lens allows users to customize and enhance the Lens experience by creating their own menus or page content that is extended from the existing pages. Many of the core features of Lens are built as extensions and use the same Extension API.
This documentation describes:
* How to build, run, test and publish an extension
* How to take advantage of Lens's Extension API
* Where to find [guides](guides/overview.md) and [code samples](https://github.com/lensapp/lens-extension-samples) to help get you started
Code samples are available at [lensapp/lens-extension-samples](https://github.com/lensapp/lens-extension-samples).
## What can extensions 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
If you'd like to have a more comprehensive overview of the Extension API, refer to the [Extension Capabilities Overview](capabilities/overview.md) page. [Extension Guides Overview](guides/overview.md) also includes a list of code samples and guides that illustrate various Extension API usage.
## How to build extensions
Building a good extension can take a lot of effort. Here is what each section of the API doc can help you with:
* **Get 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.
* **Advanced Topics** explains advanced concepts such as integrating with 3rd party applications/services.
* **References** contains exhaustive references for the Lens Extension API, Contribution Points, and many other topics.
## What's new
Lens updates on a monthly cadence, and that applies to the Extension API as well. New features and APIs become available every month to increase the power and scope of Lens extensions.
To stay current with the Extension API and Lens features in general, you can review the [release notes](https://github.com/lensapp/lens/releases).
## Looking for help
If you have questions for extension development, try asking on:
* [Lens Dev Slack](http://k8slens.slack.com/): Public chatroom for Lens developers. Some Lens team members chime in on conversations.
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) with the labels `area/documentation` and/or `area/extension`.
## Download Lens - The Kubernetes IDE
Go to [Lens](https://k8slens.dev)

View File

@ -0,0 +1,3 @@
# Lens Extension API Reference
TBD

View File

View File

@ -0,0 +1,258 @@
# Common Capabilities
Common Capabilities are important building blocks for your extensions. Almost all extensions use some of these functionalities. Here is how you can take advantage of them.
## Main Extension
A main extension runs in the background and, apart from app menu items, does not add content to the Lens UI. If you want to see logs from this extension you need to start Lens from the command line.
### Activate
An extension can register a custom callback that is executed when an extension is activated (started).
``` javascript
import { LensMainExtension } from "@k8slens/extensions"
export default class ExampleMainExtension extends LensMainExtension {
async onActivate() {
console.log("hello world")
}
}
```
### Deactivate
An extension can register a custom callback that is executed when an extension is deactivated (stopped).
``` javascript
import { LensMainExtension } from "@k8slens/extensions"
export default class ExampleMainExtension extends LensMainExtension {
async onDeactivate() {
console.log("bye bye")
}
}
```
### App Menus
An extension can register custom App menus that will be displayed on OS native menus.
Example:
``` typescript
import { LensMainExtension, windowManager } from "@k8slens/extensions"
export default class ExampleMainExtension extends LensMainExtension {
appMenus = [
{
parentId: "help",
label: "Example item",
click() {
windowManager.navigate("https://k8slens.dev");
}
}
]
}
```
## Renderer Extension
A renderer extension runs in a browser context and it's visible directly via Lens main window. If you want to see logs from this extension you need to check them via View -> Toggle Developer Tools -> Console.
### Activate
An extension can register a custom callback that is executed when an extension is activated (started).
``` javascript
import { LensRendererExtension } from "@k8slens/extensions"
export default class ExampleExtension extends LensRendererExtension {
async onActivate() {
console.log("hello world")
}
}
```
### Deactivate
An extension can register a custom callback that is executed when an extension is deactivated (stopped).
``` javascript
import { LensRendererExtension } from "@k8slens/extensions"
export default class ExampleMainExtension extends LensRendererExtension {
async onDeactivate() {
console.log("bye bye")
}
}
```
### Global Pages
An extension can register custom global pages (views) to Lens main window. Global page is a full screen page that hides all the other content from a window.
``` typescript
import React from "react"
import { Component, LensRendererExtension } from "@k8slens/extensions"
import { ExamplePage } from "./src/example-page"
export default class ExampleRendererExtension extends LensRendererExtension {
globalPages = [
{
path: "/example-route",
hideInMenu: true,
components: {
Page: ExamplePage,
}
}
]
}
```
### App Preferences
An extension can register custom app preferences. An extension is responsible for storing a state for custom preferences.
``` typescript
import React from "react"
import { LensRendererExtension } from "@k8slens/extensions"
import { myCustomPreferencesStore } from "./src/my-custom-preferences-store"
import { MyCustomPreferenceHint, MyCustomPreferenceInput } from "./src/my-custom-preference"
export default class ExampleRendererExtension extends LensRendererExtension {
appPreferences = [
{
title: "My Custom Preference",
components: {
Hint: () => <MyCustomPreferenceHint/>,
Input: () => <MyCustomPreferenceInput store={myCustomPreferencesStore}/>
}
}
]
}
```
### Cluster Pages
An extension can register custom cluster pages which are visible in a cluster menu when a cluster is opened.
``` typescript
import React from "react"
import { LensRendererExtension } from "@k8slens/extensions";
import { ExampleIcon, ExamplePage } from "./src/page"
export default class ExampleExtension extends LensRendererExtension {
clusterPages = [
{
path: "/extension-example",
title: "Example Extension",
components: {
Page: () => <ExamplePage extension={this}/>,
MenuIcon: ExampleIcon,
}
}
]
}
```
### Cluster Features
An extension can register installable features for a cluster. A cluster feature is visible in "Cluster Settings" page.
``` typescript
import React from "react"
import { LensRendererExtension } from "@k8slens/extensions"
import { MyCustomFeature } from "./src/my-custom-feature"
export default class ExampleExtension extends LensRendererExtension {
clusterFeatures = [
{
title: "My Custom Feature",
components: {
Description: () => {
return (
<span>
Just an example.
</span>
)
}
},
feature: new MyCustomFeature()
}
]
}
```
### Status Bar Items
An extension can register custom icons/texts to a status bar area.
``` typescript
import React from "react";
import { Component, LensRendererExtension, Navigation } from "@k8slens/extensions";
export default class ExampleExtension extends LensRendererExtension {
statusBarItems = [
{
item: (
<div
className="flex align-center gaps hover-highlight"
onClick={() => Navigation.navigate("/example-page")}
>
<Component.Icon material="favorite" smallest />
</div>
)
}
]
}
```
### Kubernetes Object Menu Items
An extension can register custom menu items (actions) for specified Kubernetes kinds/apiVersions.
``` typescript
import React from "react"
import { LensRendererExtension } from "@k8slens/extensions";
import { CustomMenuItem, CustomMenuItemProps } from "./src/custom-menu-item"
export default class ExampleExtension extends LensRendererExtension {
kubeObjectMenuItems = [
{
kind: "Node",
apiVersions: ["v1"],
components: {
MenuItem: (props: CustomMenuItemProps) => <CustomMenuItem {...props} />
}
}
]
}
```
### Kubernetes Object Details
An extension can register custom details (content) for specified Kubernetes kinds/apiVersions.
``` typescript
import React from "react"
import { LensRendererExtension } from "@k8slens/extensions";
import { CustomKindDetails, CustomKindDetailsProps } from "./src/custom-kind-details"
export default class ExampleExtension extends LensRendererExtension {
kubeObjectMenuItems = [
{
kind: "CustomKind",
apiVersions: ["custom.acme.org/v1"],
components: {
Details: (props: CustomKindDetailsProps) => <CustomKindDetails {...props} />
}
}
]
}
```

View File

View File

@ -0,0 +1,98 @@
# Extension Anatomy
You've now learnt how to get basic extension running. In this topic you will learn some fundamental concepts to Lens Extension development; How does it work under the hood?
`Hello World` extension does three things:
- Hooks on `onActivate()` and ouputs message into console.
- Hooks on `onDectivate()` and ouputs message into console.
- Registers `ClusterPage` so that page is visible in the sidebars of cluster dashboards.
Let's take a closer look at Hello World sample's source code and see how to achieve these things.
## Extension File Structure
```
.
├── .gitignore // Ignore build output and node_modules
├── Makefile // Config for build tasks that compiles the extension
├── README.md // Readable description of your extension's functionality
├── src
│ └── page.tsx // Extension's additional source code
├── main.ts // Source code for extension's main entrypoint
├── package.json // Extension manifest and dependencies
├── renderer.tsx // Source code for extension's renderer entrypoint
├── tsconfig.json // TypeScript configuration
├── webpack.config.js // Webpack configuration
```
Extension directory contains extension's entry files and few configuration files. Let's focus on `package.json`, `main.ts` and `renderer.tsx` which are essential to understanding the `Hello World` extension.
### Extension Manifest
Each Lens extension must have `package.json`. The `package.json` contains a mix of Node.js fields such as scripts and dependencies and Lens specific fields such as `publisher` and `contributes`. Here are some most important fields:
- `name` and `publisher`: Lens uses `@<publisher>/<name>` as a unique ID for the extension. For example, the Hello World sample has the ID `@lensapp-samples/helloworld-sample`. Lens uses the ID to uniquely identify your extension
- `main`: The extension's entry point run in `main` process.
- `renderer`: The extension's entry point run in `renderer` process.
- `engines.lens`: This specifies the minimum version of Lens API that the extension depends on.
``` javascript
{
"name": "helloworld-sample",
"publisher": "lens-samples",
"version": "0.0.1",
"description": "Lens helloworld-sample",
"license": "MIT",
"homepage": "https://github.com/lensapp/lens-extension-samples",
"engines": {
"lens": "^4.0.0"
},
"main": "dist/main.js",
"renderer": "dist/renderer.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"dev": "npm run build --watch"
},
"dependencies": {
"react-open-doodles": "^1.0.5"
},
"devDependencies": {
"@k8slens/extensions": "^4.0.0-alpha.2",
"ts-loader": "^8.0.4",
"typescript": "^4.0.3",
"@types/react": "^16.9.35",
"@types/node": "^12.0.0",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.11"
}
}
```
## Extension Entry Files
Lens extensions can have two separate entry files. One file that is used in `main` process of Lens application and antoher that is used in `renderer` process. `main` entry file should export class that extends `LensMainExtension` and `renderer` entry file should export class that extends `LensRendererExtension`.
Both extensions classes have `onActivate` and `onDeactivate` methods. `onActivate` is executed when your extension activation happens. You may want to initialize something in your extension at this point. `onDeactivate` gives you a chance to clean up before your extension becomes deactivated. For many extensions, explicit cleanup may not be required, and you don't need to override this method. However, if an extension needs to perform an operation when Lens is shutting down or the extension is disabled or uninstalled, this is the method to do so.
`Hello world` extension does not do anything special on `main` process, so let's focus on the `renderer` side. On `renderer` entry point, `Hello world` extension defines one `Cluster Page` object that registers `/extension-example` path that renders `ExamplePage` React component. It registers also `MenuItem` component that displays `ExampleIcon` React component and "Hello World" text in the sidebar of cluster dashboards. These React components are defined in additional `./src/page.tsx` file.
``` typescript
import { LensRendererExtension } from "@k8slens/extensions";
import { ExampleIcon, ExamplePage } from "./page"
import React from "react"
export default class ExampleExtension extends LensRendererExtension {
clusterPages = [
{
path: "/extension-example",
title: "Hello World",
components: {
Page: () => <ExamplePage extension={this}/>,
MenuIcon: ExampleIcon,
}
}
]
}
```
`Hello World` extension uses only one capability (`Cluster Page`) of Lens extensions. The [Extension Capabilities Overview](/extensions/capabilities/) topic helps you find the right capabilities you can use with your own extension.

View File

@ -0,0 +1,18 @@
# Wrapping Up
In the [Your First Extension](your-first-extension.md) topic, you learned how to create and run an extension. In the [Extension Anatomy](anatomy.md) topic, you learned fundamental concepts to Lens extension development. However, this is just a small glimpse of what can be created with Lens Extensions. Below are some suggested routes for furthering your Lens extension development skills.
## Extension Capabilities
In this section, we split the Lens extension points into a few categories, each with short descriptions as to what your extension could achieve. Validate that your extension idea is achievable by reading the [Extension Capabilities](../capabilities/overview.md) section for new extension ideas.
## Guides & Samples
We have a great collection of sample extensions that you can adapt from, and some of them include a detailed guide that explains the source code. You can find all Samples & Guides in the [lens-extension-samples](https://github.com/lensapp/lens-extension-samples) repository.
## Testing and Publishing
This section includes topics that help you develop high-quality Lens extensions. For example, you can learn
* How to add [integration tests](../testing-and-publishing/testing.md) for your extension
* How to [publish your extension](../testing-and-publishing/publishing.md)

View File

@ -0,0 +1,63 @@
# Your First Extension
In this topic, we'll teach you the fundamental concepts for building extensions. Make sure you have [Node.js](https://nodejs.org/en/) and [Git](https://git-scm.com/) installed....
## Installing and Building the extension
Simple Lens extension that adds "Hello World" page to a cluster menu.
### Linux
First you will need to clone the [Lens Extension samples](https://github.com/lensapp/lens-extension-samples) repository to your local machine:
```sh
git clone https://github.com/lensapp/lens-extension-samples.git
```
Next you need to create a symlink from the directory that Lens will monitor for user installed extensions to the sample extension, in this case **helloworld-sample**:
```sh
mkdir -p ~/.k8slens/extensions
cd ~/.k8slens/extensions
ln -s <lens-extension-samples directory>/helloworld-sample helloworld-sample
```
To build the extension you can use `make` or run the `npm` commands manually:
```sh
cd <lens-extension-samples directory>/helloworld-sample
make build
```
OR
```sh
cd <lens-extension-samples directory>/helloworld-sample
npm install
npm run build
```
If you want to watch for any source code changes and automatically rebuild the extension you can use:
```sh
cd <lens-extension-samples directory>/helloworld-sample
npm run dev
```
Finally, if you already have Lens open you will need to quit and restart Lens for the extension to be loaded. After this initial restart you can reload Lens and it will pick up any new builds of the extension. Within Lens connect to an existing cluster or [create a new one](../../clusters/adding-clusters.md). You should see then see the "Hello World" page in the Lens sidebar cluster menu.
## Developing the extension
Let's make a change to the message that our helloworld-sample extension displays:
* Navigate to `<lens-extension-samples directory>/helloworld-sample`.
* Change the message from HelloWorld! to **Hello Lens Extensions** in `page.tsx`.
* Rebuild the extension or, if you used `npm run dev`, the extension should automatically rebuild.
* Reload the Lens window and click on the Hello World page.
* You should see the updated message showing up.
## Next steps
In the next topic, [Extension Anatomy](anatomy.md), we'll take a closer look at the source code of the Hello World sample and explain key concepts.
You can find the source code of this tutorial at: [lensapp/lens-extension-samples](https://github.com/lensapp/lens-extension-samples/tree/master/helloworld-sample). The [Extension Guides](../guides/overview.md) topic contains other samples, each illustrating a different Lens Extension API.

View File

View File

@ -0,0 +1 @@
# Renderer Extension

View File

@ -0,0 +1,32 @@
# Testing Extensions
## Console.log
`console.log()` might be handy for extension developers to prints out info/errors from extensions. To use `console.log`, note that Lens is based on Electron. Electron has two types of processes: [Main and Renderer](https://www.electronjs.org/docs/tutorial/quick-start#main-and-renderer-processes).
### Renderer process logs
`console.log()` in Renderer process is printed in the Console in Developer Tools (View > Toggle Developer Tools).
### Main process logs
To view the logs from the main process is a bit trickier, since you cannot open developer tools for them. On MacOSX, one way is to run Lens from the terminal.
```bash
/Applications/Lens.app/Contents/MacOS/Lens
```
You can alos use [Console.app](https://support.apple.com/en-gb/guide/console/welcome/mac) to view logs from Lens.
On linux, you can get PID of Lens first
```bash
ps aux | grep Lens | grep -v grep
```
And get logs by the PID
```bash
tail -f /proc/[pid]/fd/1 # stdout (console.log)
tail -f /proc/[pid]/fd/2 # stdout (console.error)
```

View File

@ -0,0 +1,3 @@
# Using Extensions
TBD

1
docs/faq/README.md Normal file
View File

@ -0,0 +1 @@
TBD

View File

@ -0,0 +1,55 @@
# Getting Started
Lens is lightweight and simple to install. You'll be up and running in just a few minutes.
## System requirements
Review the [System Requirements](/supporting/requirements/) to check if your computer configuration is supported.
## macOS
1. [Download Lens](https://github.com/lensapp/lens/releases) for macOS.
2. Open the browser's download list and locate the downloaded archive.
3. Select the 'magnifying glass' icon to open the archive in Finder.
4. Double-click `Lens-{version}.dmg` and drag `Lens.app` to the `Applications` folder, making it available in the macOS Launchpad.
5. Add Lens to your Dock by right-clicking on the icon to bring up the context menu and choosing **Options**, **Keep in Dock**.
## Windows
1. Download the [Lens installer](https://github.com/lensapp/lens/releases) for Windows.
2. Once it is downloaded, run the installer `Lens-Setup-{version}.exe`. This will only take a minute.
3. By default, Lens is installed under `C:\users\{username}\AppData\Local\Programs\Lens`.
## Linux
See the [Download Lens](https://github.com/lensapp/lens/releases) page for a complete list of available installation options.
### Snap
Lens is officially distributed as a Snap package in the [Snap Store](https://snapcraft.io/store):
[![Get it from the Snap Store](images/snap-store.png)](https://snapcraft.io/kontena-lens)
You can install it by running:
```bash
sudo snap install kontena-lens --classic
```
## Update cadence
Lens releases a new version each month with new features and important bug fixes. Lens supports auto updating and you will be prompted to install the new release when it becomes available!
To stay current with the Lens features, you can review the [release notes](https://github.com/lensapp/lens/releases).
## Next Steps
- [Add clusters](../clusters/adding-clusters.md)
- [Watch introductory videos](./introductory-videos.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -0,0 +1,36 @@
# Introductory Videos
Continue your Lens journey with this set of introductory videos! These videos are meant to quickly familiarize you with Lens' various powerful features.
<ul class="video-list">
<li class="video">
<a target="_blank" href="https://youtu.be/mc-BzPDKfkQ">
<img src="https://img.youtube.com/vi/mc-BzPDKfkQ/mqdefault.jpg" alt aria-hidden="true" class="thumb"/>
<div class="info">
<h3 class="title">Getting started</h3>
<p class="description">Get Lens Kubernetes IDE Running in 5 Minutes</p>
<span class="duration"><span class="sr-only">Duration </span>35<span class="sr-only"> minutes</span></span>
</div>
</a>
</li>
<li class="video">
<a target="_blank" href="https://youtu.be/epw_MjxjMYI">
<img src="https://img.youtube.com/vi/epw_MjxjMYI/mqdefault.jpg" alt aria-hidden="true" class="thumb"/>
<div class="info">
<h3 class="title">Introducing Lens</h3>
<p class="description">Lens Kubernetes IDE overview</p>
<span class="duration"><span class="sr-only">Duration </span>2<span class="sr-only"> minutes</span></span>
</div>
</a>
</li>
<li class="video">
<a target="_blank" href="https://youtu.be/fqneoWCgJdw">
<img src="https://img.youtube.com/vi/fqneoWCgJdw/mqdefault.jpg" alt aria-hidden="true" class="thumb"/>
<div class="info">
<h3 class="title">Demo of Mirantis Lens</h3>
<p class="description">The Best IDE For Kubernetes</p>
<span class="duration"><span class="sr-only">Duration </span>10<span class="sr-only"> minutes</span></span>
</div>
</a>
</li>
</ul>

View File

@ -0,0 +1,28 @@
# Preferences
## Color themes
The Color Themes option in Lens preferences lets you set the colors in the Lens user interface to suit your liking.
1. Go to **File** > **Preferences** (**Lens** > **Preferences** on Mac).
2. Select your preferred theme from the **Color Theme** dropdown.
![Color Theme](images/color-theme.png)
## Telemetry & usage tracking
Lens collects telemetry data, which is used to help us understand how to improve the product. For example, this usage data helps us to debug issues and to prioritize new features. While we appreciate the insights this data provides, we also know that not everyone wants to send usage data. Please see our [privacy statement](https://www.mirantis.com/company/privacy-policy/) to learn more.
### Disable telemetry reporting
If you don't wish to send usage data to Mirantis, you can disable the "Telemetry & Usage Tracking" in the Lens preferences.
1. Go to **File** > **Preferences** (**Lens** > **Preferences** on Mac).
2. Scroll down to **Telemetry & Usage Tracking**
3. Uncheck **Allow telemetry & usage tracking**.
This will silence all telemetry events from Lens going forward. Telemetry information may have been collected and sent up until the point when you disable this setting.
![Disable Telemetry & Usage Tracking](images/disabled-telemetry-usage-tracking.png)

3
docs/helm/README.md Normal file
View File

@ -0,0 +1,3 @@
# Using Helm Charts
TBD

BIN
docs/img/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 754 KiB

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<style type="text/css">
.st0{fill:none;}
.st1{fill:#3D90CE;}
.st2{fill:#FFFFFF;}
</style>
<rect y="0" class="st0" width="512" height="512"/>
<rect x="16" y="16" class="st1" width="480" height="480"/>
<g>
<path class="st2" d="M242.6,426h130.9l-30.2-128.7L242.6,426z"/>
<path class="st2" d="M86,352.5V426h137.6l57.5-73.5H86z"/>
<path class="st2" d="M273.1,167L426,241.4v-148L273.1,167z"/>
<path class="st2" d="M388.9,426H426V258l-86.4-42.1L388.9,426z"/>
<path class="st2" d="M406.9,86H216.4l-23,102.7L406.9,86z"/>
<path class="st2" d="M86,195.1v142.5h113.3L86,195.1z"/>
<path class="st2" d="M201.1,86H86v85.1l75,94.3L201.1,86z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 999 B

1
docs/img/play.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 22 22"><path fill="#fff" d="M9.35 15.95V6.6L15.4 11zM11 1C5.477 1 1 5.477 1 11c0 5.522 4.477 10 10 10s10-4.478 10-10c0-5.523-4.477-10-10-10zm0 18.5a8.5 8.5 0 1 1 .001-17.001A8.5 8.5 0 0 1 11 19.5z"/></svg>

After

Width:  |  Height:  |  Size: 283 B

View File

@ -0,0 +1,90 @@
:root {
--md-primary-fg-color: #3d90ce;
--md-accent-fg-color: #3d90ce;
}
:root > * {
/* Footer */
--md-footer-bg-color: #3d90ce;
}
.md-version__list {
overflow: auto;
}
ul.video-list {
counter-reset: section;
list-style: none;
padding-left: 0;
position:relative
}
ul.video-list .video:not(:last-of-type) a {
border-bottom:2px solid #e6e6e6
}
ul.video-list a {
position: relative;
padding: 2rem 2rem 2rem 4.2rem;
display: block;
box-sizing:border-box
}
ul.video-list a .info {
padding-top:0.25rem
}
ul.video-list a .info::before {
counter-increment: section;
content: counter(section);
position: absolute;
left: 1.5rem;
color:black
}
ul.video-list a .info > p, ul.video-list a .info > span {
color:black
}
ul.video-list a .info .title {
margin-top: 0;
margin-bottom:0.7rem
}
ul.video-list a .info .description {
margin-bottom: 1rem;
}
ul.video-list a .info .duration, ul.video-list a .info .duration span {
color: #6e6e6e;
}
ul.video-list a:hover, ul.video-list a:focus {
text-decoration:none
}
ul.video-list a:hover {
background:#f2f2f2
}
ul.video-list a:hover::after {
content: '';
display: block;
width: 6rem;
height: 6rem;
position: absolute;
background: url("/img/play.svg");
background-size: 6rem;
top: 3rem;
left:8.6rem
}
ul.video-list .thumb {
max-height: 8.2rem;
padding-right: 2rem;
position: relative;
float:left
}

View File

@ -0,0 +1,26 @@
# Requirements for Lens
## Hardware
Lens is a small download (< 300 MB) and has a disk footprint of 600 MB. Lens is lightweight and should easily run on today's hardware.
We recommend:
* 2 GHz or faster processor
* 1 GB of RAM
## Platforms
Lens has been tested on the following platforms:
* OS X
* Windows
* Linux
### Additional Windows requirements
...
### Additional Linux requirements
...

93
mkdocs.yml Normal file
View File

@ -0,0 +1,93 @@
site_name: Lens Documentation
site_description: Documentation for Lens IDE. The only system youll ever need to take control of your Kubernetes clusters. It's open source and free. Download it today!
site_author: Mirantis, Inc.
site_url: https://docs.k8slens.dev
docs_dir: docs/
repo_name: GitHub
repo_url: https://github.com/lensapp/lens
copyright: Copyright &copy; 2020 <a href="https://mirantis.com/">Mirantis Inc.</a> - All rights reserved.
edit_uri: ""
nav:
- Overview: README.md
- Getting Started: getting-started/README.md
- Managing Clusters:
- Adding clusters: clusters/adding-clusters.md
- Removing cluster: clusters/removing-clusters.md
- Settings: clusters/settings.md
- Using Helm Charts: helm/README.md
- Using Extensions: extensions/usage/README.md
- Preferences: getting-started/preferences.md
- Extension Development:
- Overview: extensions/README.md
- Get Started:
- 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:
- Overview: extensions/capabilities/README.md
- Common Capabilities: extensions/capabilities/common-capabilities.md
- Theming: extensions/capabilities/theming.md
- Extension Guides:
- Overview: extensions/guides/README.md
- Renderer Extension: extensions/guides/renderer-extension.md
- Testing and Publishing:
- Testing Extensions: extensions/testing-and-publishing/testing.md
- Publishing Extensions: extensions/testing-and-publishing/publishing.md
- Bundling Extensions: extensions/testing-and-publishing/bundling.md
- API Reference: extensions/api/README.md
- Contributing: contributing/README.md
- FAQ: faq/README.md
theme:
name: 'material'
highlightjs: true
language: 'en'
custom_dir: docs/custom_theme
favicon: img/favicon.ico
logo: img/lens-logo-icon.svg
palette:
- scheme: default
toggle:
icon: material/toggle-switch
name: Switch to light mode
- scheme: slate
toggle:
icon: material/toggle-switch-off-outline
name: Switch to dark mode
features:
- navigation.instant
- toc.autohide
- search.suggest
- search.highlight
extra_css:
- stylesheets/extra.css
plugins:
- search
- git-revision-date-localized
markdown_extensions:
- pymdownx.highlight: {}
- pymdownx.superfences: {}
- pymdownx.inlinehilite: {}
- toc:
permalink: "#"
toc_depth: 3
extra:
generator: false
social:
- icon: fontawesome/brands/github
link: https://github.com/lensapp/lens
name: Lens on GitHub
- 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/solid/link
link: https://k8slens.dev/
name: Lens Website
version:
method: mike

35
mkdocs/Dockerfile Normal file
View File

@ -0,0 +1,35 @@
ARG PYTHON_VERSION=3.8.1-alpine3.11
FROM python:${PYTHON_VERSION} as builder
ENV PYTHONUNBUFFERED 1
# Set build directory
WORKDIR /wheels
# Copy files necessary
COPY ./requirements.txt .
# Perform build and cleanup artifacts
RUN \
apk add --no-cache \
git \
git-fast-import \
&& apk add --no-cache --virtual .build gcc musl-dev \
&& python -m pip install --upgrade pip \
&& pip install -r requirements.txt \
&& apk del .build gcc musl-dev \
&& rm -rf /usr/local/lib/python3.8/site-packages/mkdocs/themes/*/* \
&& rm -rf /tmp/*
# Set final MkDocs working directory
WORKDIR /docs
# Expose MkDocs development server port
EXPOSE 8000
# Start development server by default
ENTRYPOINT ["mkdocs"]
CMD ["serve", "--dev-addr=0.0.0.0:8000"]

8
mkdocs/requirements.txt Normal file
View File

@ -0,0 +1,8 @@
# Direct dependencies
mkdocs>=1.1
Pygments>=2.4
markdown>=3.2
pymdown-extensions>=7.0
mkdocs-material-extensions>=1.0
mkdocs-git-revision-date-localized-plugin>=0.7.3
mkdocs-material>=6.1.0

View File

@ -37,7 +37,8 @@
"download:kubectl": "yarn run ts-node build/download_kubectl.ts", "download:kubectl": "yarn run ts-node build/download_kubectl.ts",
"download:helm": "yarn run ts-node build/download_helm.ts", "download:helm": "yarn run ts-node build/download_helm.ts",
"build:tray-icons": "yarn run ts-node build/build_tray_icon.ts", "build:tray-icons": "yarn run ts-node build/build_tray_icon.ts",
"lint": "eslint $@ --ext js,ts,tsx --max-warnings=0 src/" "lint": "eslint $@ --ext js,ts,tsx --max-warnings=0 src/",
"mkdocs-serve-local": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-serve-local:latest"
}, },
"config": { "config": {
"bundledKubectlVersion": "1.17.11", "bundledKubectlVersion": "1.17.11",

View File

@ -31,7 +31,7 @@ export interface UserPreferences {
} }
export class UserStore extends BaseStore<UserStoreModel> { export class UserStore extends BaseStore<UserStoreModel> {
static readonly defaultTheme: ThemeId = "kontena-dark" static readonly defaultTheme: ThemeId = "lens-dark"
private constructor() { private constructor() {
super({ super({

View File

@ -4,10 +4,11 @@ import type { LensRendererExtension } from "./lens-renderer-extension"
import type { InstalledExtension } from "./extension-manager"; import type { InstalledExtension } from "./extension-manager";
import path from "path" import path from "path"
import { broadcastIpc } from "../common/ipc" import { broadcastIpc } from "../common/ipc"
import { computed, observable, reaction, when } from "mobx" import { action, computed, observable, reaction, toJS, when } from "mobx"
import logger from "../main/logger" import logger from "../main/logger"
import { app, ipcRenderer, remote } from "electron" import { app, ipcRenderer, remote } from "electron"
import * as registries from "./registries"; import * as registries from "./registries";
import { extensionsStore } from "./extensions-store";
// lazy load so that we get correct userData // lazy load so that we get correct userData
export function extensionPackagesRoot() { export function extensionPackagesRoot() {
@ -15,33 +16,42 @@ export function extensionPackagesRoot() {
} }
export class ExtensionLoader { export class ExtensionLoader {
protected extensions = observable.map<LensExtensionId, InstalledExtension>();
protected instances = observable.map<LensExtensionId, LensExtension>();
@observable isLoaded = false; @observable isLoaded = false;
protected extensions = observable.map<LensExtensionId, InstalledExtension>([], { deep: false }); whenLoaded = when(() => this.isLoaded);
protected instances = observable.map<LensExtensionId, LensExtension>([], { deep: false })
constructor() { constructor() {
if (ipcRenderer) { if (ipcRenderer) {
ipcRenderer.on("extensions:loaded", (event, extensions: InstalledExtension[]) => { ipcRenderer.on("extensions:loaded", (event, extensions: [LensExtensionId, InstalledExtension][]) => {
this.isLoaded = true; this.isLoaded = true;
extensions.forEach((ext) => { extensions.forEach(([extId, ext]) => {
if (!this.extensions.has(ext.manifestPath)) { if (!this.extensions.has(extId)) {
this.extensions.set(ext.manifestPath, ext) this.extensions.set(extId, ext)
} }
}) })
}); });
} }
extensionsStore.manageState(this);
} }
@computed get userExtensions(): LensExtension[] { @computed get userExtensions(): Map<LensExtensionId, InstalledExtension> {
return [...this.instances.values()].filter(ext => !ext.isBundled) const extensions = this.extensions.toJS();
extensions.forEach((ext, extId) => {
if (ext.isBundled) {
extensions.delete(extId);
}
})
return extensions;
} }
async init() { @action
const { extensionManager } = await import("./extension-manager"); async init(extensions: Map<LensExtensionId, InstalledExtension>) {
const installedExtensions = await extensionManager.load(); this.extensions.replace(extensions);
this.extensions.replace(installedExtensions);
this.isLoaded = true; this.isLoaded = true;
this.loadOnMain(); this.loadOnMain();
this.broadcastExtensions();
} }
loadOnMain() { loadOnMain() {
@ -71,21 +81,26 @@ export class ExtensionLoader {
} }
protected autoInitExtensions(register: (ext: LensExtension) => Function[]) { protected autoInitExtensions(register: (ext: LensExtension) => Function[]) {
return reaction(() => this.extensions.toJS(), (installedExtensions) => { return reaction(() => this.toJSON(), installedExtensions => {
for (const [id, ext] of installedExtensions) { for (const [extId, ext] of installedExtensions) {
let instance = this.instances.get(ext.manifestPath) let instance = this.instances.get(extId);
if (!instance) { if (ext.isEnabled && !instance) {
const extensionModule = this.requireExtension(ext)
if (!extensionModule) {
continue
}
try { try {
const LensExtensionClass: LensExtensionConstructor = extensionModule.default; const LensExtensionClass: LensExtensionConstructor = this.requireExtension(ext)
if (!LensExtensionClass) continue;
instance = new LensExtensionClass(ext); instance = new LensExtensionClass(ext);
instance.whenEnabled(() => register(instance)); instance.whenEnabled(() => register(instance));
this.instances.set(ext.manifestPath, instance); instance.enable();
this.instances.set(extId, instance);
} catch (err) { } catch (err) {
logger.error(`[EXTENSIONS-LOADER]: init extension instance error`, { ext, err }) logger.error(`[EXTENSION-LOADER]: activation extension error`, { ext, err })
}
} else if (!ext.isEnabled && instance) {
try {
instance.disable();
this.instances.delete(extId);
} catch (err) {
logger.error(`[EXTENSION-LOADER]: deactivation extension error`, { ext, err })
} }
} }
} }
@ -103,7 +118,7 @@ export class ExtensionLoader {
extEntrypoint = path.resolve(path.join(path.dirname(extension.manifestPath), extension.manifest.main)) extEntrypoint = path.resolve(path.join(path.dirname(extension.manifestPath), extension.manifest.main))
} }
if (extEntrypoint !== "") { if (extEntrypoint !== "") {
return __non_webpack_require__(extEntrypoint) return __non_webpack_require__(extEntrypoint).default;
} }
} catch (err) { } catch (err) {
console.error(`[EXTENSION-LOADER]: can't load extension main at ${extEntrypoint}: ${err}`, { extension }); console.error(`[EXTENSION-LOADER]: can't load extension main at ${extEntrypoint}: ${err}`, { extension });
@ -111,6 +126,17 @@ export class ExtensionLoader {
} }
} }
getExtension(extId: LensExtensionId): InstalledExtension {
return this.extensions.get(extId);
}
toJSON(): Map<LensExtensionId, InstalledExtension> {
return toJS(this.extensions, {
exportMapsAsObjects: false,
recurseEverything: true,
})
}
async broadcastExtensions(frameId?: number) { async broadcastExtensions(frameId?: number) {
await when(() => this.isLoaded); await when(() => this.isLoaded);
broadcastIpc({ broadcastIpc({
@ -118,7 +144,7 @@ export class ExtensionLoader {
frameId: frameId, frameId: frameId,
frameOnly: !!frameId, frameOnly: !!frameId,
args: [ args: [
Array.from(this.extensions.toJS().values()) Array.from(this.toJSON()),
], ],
}) })
} }

View File

@ -8,9 +8,10 @@ import { extensionPackagesRoot } from "./extension-loader"
import { getBundledExtensions } from "../common/utils/app-version" import { getBundledExtensions } from "../common/utils/app-version"
export interface InstalledExtension { export interface InstalledExtension {
manifest: LensExtensionManifest; readonly manifest: LensExtensionManifest;
manifestPath: string; readonly manifestPath: string;
isBundled?: boolean; // defined in package.json readonly isBundled: boolean; // defined in project root's package.json
isEnabled: boolean;
} }
type Dependencies = { type Dependencies = {
@ -77,7 +78,7 @@ export class ExtensionManager {
return await this.loadExtensions(); return await this.loadExtensions();
} }
protected async getByManifest(manifestPath: string): Promise<InstalledExtension> { protected async getByManifest(manifestPath: string, { isBundled = false } = {}): Promise<InstalledExtension> {
let manifestJson: LensExtensionManifest; let manifestJson: LensExtensionManifest;
try { try {
fs.accessSync(manifestPath, fs.constants.F_OK); // check manifest file for existence fs.accessSync(manifestPath, fs.constants.F_OK); // check manifest file for existence
@ -88,6 +89,8 @@ export class ExtensionManager {
return { return {
manifestPath: path.join(this.nodeModulesPath, manifestJson.name, "package.json"), manifestPath: path.join(this.nodeModulesPath, manifestJson.name, "package.json"),
manifest: manifestJson, manifest: manifestJson,
isBundled: isBundled,
isEnabled: isBundled,
} }
} catch (err) { } catch (err) {
logger.error(`[EXTENSION-MANAGER]: can't install extension at ${manifestPath}: ${err}`, { manifestJson }); logger.error(`[EXTENSION-MANAGER]: can't install extension at ${manifestPath}: ${err}`, { manifestJson });
@ -129,9 +132,8 @@ export class ExtensionManager {
} }
const absPath = path.resolve(folderPath, fileName); const absPath = path.resolve(folderPath, fileName);
const manifestPath = path.resolve(absPath, "package.json"); const manifestPath = path.resolve(absPath, "package.json");
const ext = await this.getByManifest(manifestPath).catch(() => null) const ext = await this.getByManifest(manifestPath, { isBundled: true }).catch(() => null)
if (ext) { if (ext) {
ext.isBundled = true;
extensions.push(ext) extensions.push(ext)
} }
} }

View File

@ -0,0 +1,77 @@
import type { LensExtensionId } from "./lens-extension";
import type { ExtensionLoader } from "./extension-loader";
import { BaseStore } from "../common/base-store"
import { action, observable, reaction, toJS } from "mobx";
export interface LensExtensionsStoreModel {
extensions: Record<LensExtensionId, LensExtensionState>;
}
export interface LensExtensionState {
enabled?: boolean;
}
export class ExtensionsStore extends BaseStore<LensExtensionsStoreModel> {
constructor() {
super({
configName: "lens-extensions",
});
}
protected state = observable.map<LensExtensionId, LensExtensionState>();
protected getState(extensionLoader: ExtensionLoader) {
const state: Record<LensExtensionId, LensExtensionState> = {};
return Array.from(extensionLoader.userExtensions).reduce((state, [extId, ext]) => {
state[extId] = {
enabled: ext.isEnabled,
}
return state;
}, state)
}
async manageState(extensionLoader: ExtensionLoader) {
await extensionLoader.whenLoaded;
await this.whenLoaded;
// activate user-extensions when state is ready
extensionLoader.userExtensions.forEach((ext, extId) => {
ext.isEnabled = this.isEnabled(extId);
});
// apply state on changes from store
reaction(() => this.state.toJS(), extensionsState => {
extensionsState.forEach((state, extId) => {
const ext = extensionLoader.getExtension(extId);
if (ext && !ext.isBundled) {
ext.isEnabled = state.enabled;
}
})
})
// save state on change `extension.isEnabled`
reaction(() => this.getState(extensionLoader), extensionsState => {
this.state.merge(extensionsState)
})
}
isEnabled(extId: LensExtensionId) {
const state = this.state.get(extId);
return !state /* enabled by default */ || state.enabled;
}
@action
protected fromStore({ extensions }: LensExtensionsStoreModel) {
this.state.merge(extensions);
}
toJSON(): LensExtensionsStoreModel {
return toJS({
extensions: this.state.toJSON(),
}, {
recurseEverything: true
})
}
}
export const extensionsStore = new ExtensionsStore();

View File

@ -1,7 +1,6 @@
import type { InstalledExtension } from "./extension-manager"; import type { InstalledExtension } from "./extension-manager";
import { action, reaction } from "mobx"; import { action, observable, reaction } from "mobx";
import logger from "../main/logger"; import logger from "../main/logger";
import { ExtensionStore } from "./extension-store";
export type LensExtensionId = string; // path to manifest (package.json) export type LensExtensionId = string; // path to manifest (package.json)
export type LensExtensionConstructor = new (...args: ConstructorParameters<typeof LensExtension>) => LensExtension; export type LensExtensionConstructor = new (...args: ConstructorParameters<typeof LensExtension>) => LensExtension;
@ -14,35 +13,17 @@ export interface LensExtensionManifest {
renderer?: string; // path to %ext/dist/renderer.js renderer?: string; // path to %ext/dist/renderer.js
} }
export interface LensExtensionStoreModel { export class LensExtension {
isEnabled: boolean;
}
export class LensExtension<S extends ExtensionStore<LensExtensionStoreModel> = any> {
protected store: S;
readonly manifest: LensExtensionManifest; readonly manifest: LensExtensionManifest;
readonly manifestPath: string; readonly manifestPath: string;
readonly isBundled: boolean; readonly isBundled: boolean;
@observable private isEnabled = false;
constructor({ manifest, manifestPath, isBundled }: InstalledExtension) { constructor({ manifest, manifestPath, isBundled }: InstalledExtension) {
this.manifest = manifest this.manifest = manifest
this.manifestPath = manifestPath this.manifestPath = manifestPath
this.isBundled = !!isBundled this.isBundled = !!isBundled
this.init();
}
protected async init(store: S = createBaseStore().getInstance()) {
this.store = store;
await this.store.loadExtension(this);
reaction(() => this.store.data.isEnabled, (isEnabled = true) => {
this.toggle(isEnabled); // handle activation & deactivation
}, {
fireImmediately: true
});
}
get isEnabled() {
return !!this.store.data.isEnabled;
} }
get id(): LensExtensionId { get id(): LensExtensionId {
@ -64,7 +45,7 @@ export class LensExtension<S extends ExtensionStore<LensExtensionStoreModel> = a
@action @action
async enable() { async enable() {
if (this.isEnabled) return; if (this.isEnabled) return;
this.store.data.isEnabled = true; this.isEnabled = true;
this.onActivate(); this.onActivate();
logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`); logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`);
} }
@ -72,7 +53,7 @@ export class LensExtension<S extends ExtensionStore<LensExtensionStoreModel> = a
@action @action
async disable() { async disable() {
if (!this.isEnabled) return; if (!this.isEnabled) return;
this.store.data.isEnabled = false; this.isEnabled = false;
this.onDeactivate(); this.onDeactivate();
logger.info(`[EXTENSION]: disabled ${this.name}@${this.version}`); logger.info(`[EXTENSION]: disabled ${this.name}@${this.version}`);
} }
@ -114,13 +95,3 @@ export class LensExtension<S extends ExtensionStore<LensExtensionStoreModel> = a
// mock // mock
} }
} }
function createBaseStore() {
return class extends ExtensionStore<LensExtensionStoreModel> {
constructor() {
super({
configName: "state"
});
}
}
}

View File

@ -21,6 +21,8 @@ import { userStore } from "../common/user-store";
import { workspaceStore } from "../common/workspace-store"; import { workspaceStore } from "../common/workspace-store";
import { appEventBus } from "../common/event-bus" import { appEventBus } from "../common/event-bus"
import { extensionLoader } from "../extensions/extension-loader"; import { extensionLoader } from "../extensions/extension-loader";
import { extensionManager } from "../extensions/extension-manager";
import { extensionsStore } from "../extensions/extensions-store";
const workingDir = path.join(app.getPath("appData"), appName); const workingDir = path.join(app.getPath("appData"), appName);
let proxyPort: number; let proxyPort: number;
@ -52,6 +54,7 @@ app.on("ready", async () => {
userStore.load(), userStore.load(),
clusterStore.load(), clusterStore.load(),
workspaceStore.load(), workspaceStore.load(),
extensionsStore.load(),
]); ]);
// find free port // find free port
@ -76,7 +79,7 @@ app.on("ready", async () => {
} }
LensExtensionsApi.windowManager = windowManager = new WindowManager(proxyPort); LensExtensionsApi.windowManager = windowManager = new WindowManager(proxyPort);
extensionLoader.init(); // call after windowManager to see splash earlier extensionLoader.init(await extensionManager.load()); // call after windowManager to see splash earlier
setTimeout(() => { setTimeout(() => {
appEventBus.emit({ name: "app", action: "start" }) appEventBus.emit({ name: "app", action: "start" })

View File

@ -1,4 +1,4 @@
import { app, BrowserWindow, dialog, Menu, MenuItem, MenuItemConstructorOptions, webContents } from "electron" import { app, BrowserWindow, dialog, Menu, MenuItem, MenuItemConstructorOptions, webContents, shell } from "electron"
import { autorun } from "mobx"; import { autorun } from "mobx";
import { WindowManager } from "./window-manager"; import { WindowManager } from "./window-manager";
import { appName, isMac, isWindows } from "../common/vars"; import { appName, isMac, isWindows } from "../common/vars";
@ -193,6 +193,12 @@ export function buildMenu(windowManager: WindowManager) {
navigate(whatsNewURL()) navigate(whatsNewURL())
}, },
}, },
{
label: "Documentation",
click: async () => {
shell.openExternal('https://docs.k8slens.dev/');
},
},
...ignoreOnMac([ ...ignoreOnMac([
{ {
label: "About Lens", label: "About Lens",

View File

@ -4,6 +4,8 @@ import React from "react";
import * as Mobx from "mobx" import * as Mobx from "mobx"
import * as MobxReact from "mobx-react" import * as MobxReact from "mobx-react"
import * as LensExtensions from "../extensions/extension-api" import * as LensExtensions from "../extensions/extension-api"
import { App } from "./components/app";
import { LensApp } from "./lens-app";
import { render, unmountComponentAtNode } from "react-dom"; import { render, unmountComponentAtNode } from "react-dom";
import { isMac } from "../common/vars"; import { isMac } from "../common/vars";
import { userStore } from "../common/user-store"; import { userStore } from "../common/user-store";
@ -11,8 +13,7 @@ import { workspaceStore } from "../common/workspace-store";
import { clusterStore } from "../common/cluster-store"; import { clusterStore } from "../common/cluster-store";
import { i18nStore } from "./i18n"; import { i18nStore } from "./i18n";
import { themeStore } from "./theme.store"; import { themeStore } from "./theme.store";
import { App } from "./components/app"; import { extensionsStore } from "../extensions/extensions-store";
import { LensApp } from "./lens-app";
type AppComponent = React.ComponentType & { type AppComponent = React.ComponentType & {
init?(): Promise<void>; init?(): Promise<void>;
@ -34,6 +35,7 @@ export async function bootstrap(App: AppComponent) {
userStore.load(), userStore.load(),
workspaceStore.load(), workspaceStore.load(),
clusterStore.load(), clusterStore.load(),
extensionsStore.load(),
i18nStore.init(), i18nStore.init(),
themeStore.init(), themeStore.init(),
]); ]);

View File

@ -2,11 +2,17 @@
--width: 100%; --width: 100%;
--max-width: auto; --max-width: auto;
.extension { .extension-list {
--flex-gap: $padding / 3; .extension {
padding: $padding $padding * 2; --flex-gap: $padding / 3;
background: $colorVague; padding: $padding $padding * 2;
border-radius: $radius; background: $colorVague;
border-radius: $radius;
&:not(:first-of-type) {
margin-top: $padding * 2;
}
}
} }
.extensions-path { .extensions-path {

View File

@ -19,7 +19,8 @@ export class Extensions extends React.Component {
@computed get extensions() { @computed get extensions() {
const searchText = this.search.toLowerCase(); const searchText = this.search.toLowerCase();
return extensionLoader.userExtensions.filter(({ name, description }) => { return Array.from(extensionLoader.userExtensions.values()).filter(ext => {
const { name, description } = ext.manifest;
return [ return [
name.toLowerCase().includes(searchText), name.toLowerCase().includes(searchText),
description.toLowerCase().includes(searchText), description.toLowerCase().includes(searchText),
@ -68,9 +69,10 @@ export class Extensions extends React.Component {
) )
} }
return extensions.map(ext => { return extensions.map(ext => {
const { id, name, description, isEnabled } = ext; const { manifestPath: extId, isEnabled, manifest } = ext;
const { name, description } = manifest;
return ( return (
<div key={id} className="extension flex gaps align-center"> <div key={extId} className="extension flex gaps align-center">
<div className="box grow flex column gaps"> <div className="box grow flex column gaps">
<div className="package"> <div className="package">
Name: <code className="name">{name}</code> Name: <code className="name">{name}</code>
@ -80,10 +82,10 @@ export class Extensions extends React.Component {
</div> </div>
</div> </div>
{!isEnabled && ( {!isEnabled && (
<Button plain active onClick={() => ext.enable()}>Enable</Button> <Button plain active onClick={() => ext.isEnabled = true}>Enable</Button>
)} )}
{isEnabled && ( {isEnabled && (
<Button accent onClick={() => ext.disable()}>Disable</Button> <Button accent onClick={() => ext.isEnabled = false}>Disable</Button>
)} )}
</div> </div>
) )
@ -102,7 +104,7 @@ export class Extensions extends React.Component {
value={this.search} value={this.search}
onChange={(value) => this.search = value} onChange={(value) => this.search = value}
/> />
<div className="extension-list flex column gaps"> <div className="extension-list">
{this.renderExtensions()} {this.renderExtensions()}
</div> </div>
</WizardLayout> </WizardLayout>

View File

@ -178,7 +178,6 @@ export class Terminal {
break; break;
// Ctrl+W: prevent unexpected terminal tab closing, e.g. editing file in vim // Ctrl+W: prevent unexpected terminal tab closing, e.g. editing file in vim
// https://github.com/kontena/lens-app/issues/156#issuecomment-534906480
case "KeyW": case "KeyW":
evt.preventDefault(); evt.preventDefault();
break; break;

View File

@ -25,8 +25,8 @@ export class ThemeStore {
// bundled themes from `themes/${themeId}.json` // bundled themes from `themes/${themeId}.json`
@observable themes: Theme[] = [ @observable themes: Theme[] = [
{ id: "kontena-dark", type: ThemeType.DARK }, { id: "lens-dark", type: ThemeType.DARK },
{ id: "kontena-light", type: ThemeType.LIGHT }, { id: "lens-light", type: ThemeType.LIGHT },
]; ];
@computed get activeThemeId() { @computed get activeThemeId() {