diff --git a/.github/labeler-config.yml b/.github/labeler-config.yml deleted file mode 100644 index 06aab917bc..0000000000 --- a/.github/labeler-config.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index b57d58e567..0000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..b9b41ddd58 --- /dev/null +++ b/.github/workflows/main.yml @@ -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 }} + + + + diff --git a/README.md b/README.md index b403492e72..21522cf4cb 100644 --- a/README.md +++ b/README.md @@ -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-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: - [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) - [NodeJS](https://nodejs.org/dist/latest-v12.x/docs/api/) (api docs) + + ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/lensapp/lens. \ No newline at end of file diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 0000000000..12bc650410 --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +docs.k8slens.dev diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000000..f8a979fb90 --- /dev/null +++ b/docs/README.md @@ -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). diff --git a/docs/clusters/adding-clusters.md b/docs/clusters/adding-clusters.md new file mode 100644 index 0000000000..a89afb2f25 --- /dev/null +++ b/docs/clusters/adding-clusters.md @@ -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. \ No newline at end of file diff --git a/docs/clusters/images/add-cluster.png b/docs/clusters/images/add-cluster.png new file mode 100644 index 0000000000..b53c09f704 Binary files /dev/null and b/docs/clusters/images/add-cluster.png differ diff --git a/docs/clusters/images/cluster-context-menu.png b/docs/clusters/images/cluster-context-menu.png new file mode 100644 index 0000000000..d733840df3 Binary files /dev/null and b/docs/clusters/images/cluster-context-menu.png differ diff --git a/docs/clusters/images/cluster-settings-features.png b/docs/clusters/images/cluster-settings-features.png new file mode 100644 index 0000000000..3a8066309d Binary files /dev/null and b/docs/clusters/images/cluster-settings-features.png differ diff --git a/docs/clusters/images/cluster-settings-general.png b/docs/clusters/images/cluster-settings-general.png new file mode 100644 index 0000000000..d7de0a1a35 Binary files /dev/null and b/docs/clusters/images/cluster-settings-general.png differ diff --git a/docs/clusters/images/cluster-settings-removal.png b/docs/clusters/images/cluster-settings-removal.png new file mode 100644 index 0000000000..badcbcc6e0 Binary files /dev/null and b/docs/clusters/images/cluster-settings-removal.png differ diff --git a/docs/clusters/images/cluster-settings-status.png b/docs/clusters/images/cluster-settings-status.png new file mode 100644 index 0000000000..af8e939e35 Binary files /dev/null and b/docs/clusters/images/cluster-settings-status.png differ diff --git a/docs/clusters/images/cluster-settings.png b/docs/clusters/images/cluster-settings.png new file mode 100644 index 0000000000..27a4a72ff9 Binary files /dev/null and b/docs/clusters/images/cluster-settings.png differ diff --git a/docs/clusters/images/remove-cluster.png b/docs/clusters/images/remove-cluster.png new file mode 100644 index 0000000000..bcaa69c44a Binary files /dev/null and b/docs/clusters/images/remove-cluster.png differ diff --git a/docs/clusters/removing-clusters.md b/docs/clusters/removing-clusters.md new file mode 100644 index 0000000000..ab6205a960 --- /dev/null +++ b/docs/clusters/removing-clusters.md @@ -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) \ No newline at end of file diff --git a/docs/clusters/settings.md b/docs/clusters/settings.md new file mode 100644 index 0000000000..351c0babeb --- /dev/null +++ b/docs/clusters/settings.md @@ -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) diff --git a/docs/contributing/README.md b/docs/contributing/README.md new file mode 100644 index 0000000000..13a6ca8c05 --- /dev/null +++ b/docs/contributing/README.md @@ -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 diff --git a/docs/contributing/development.md b/docs/contributing/development.md new file mode 100644 index 0000000000..8e5633cda9 --- /dev/null +++ b/docs/contributing/development.md @@ -0,0 +1,3 @@ +# Development + +TBD diff --git a/docs/contributing/documentation.md b/docs/contributing/documentation.md new file mode 100644 index 0000000000..00b9f9550e --- /dev/null +++ b/docs/contributing/documentation.md @@ -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. diff --git a/docs/contributing/maintainers.md b/docs/contributing/maintainers.md new file mode 100644 index 0000000000..a73918b272 --- /dev/null +++ b/docs/contributing/maintainers.md @@ -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. diff --git a/docs/contributing/promotion.md b/docs/contributing/promotion.md new file mode 100644 index 0000000000..6f80ddb2b2 --- /dev/null +++ b/docs/contributing/promotion.md @@ -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! diff --git a/docs/custom_theme/img/favicon.ico b/docs/custom_theme/img/favicon.ico new file mode 100644 index 0000000000..19b2de71d1 Binary files /dev/null and b/docs/custom_theme/img/favicon.ico differ diff --git a/docs/custom_theme/main.html b/docs/custom_theme/main.html new file mode 100644 index 0000000000..b6ad2467dd --- /dev/null +++ b/docs/custom_theme/main.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block analytics %} + + + +{% endblock %} \ No newline at end of file diff --git a/docs/extensions/README.md b/docs/extensions/README.md new file mode 100644 index 0000000000..4a118bd4d3 --- /dev/null +++ b/docs/extensions/README.md @@ -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) diff --git a/docs/extensions/api/README.md b/docs/extensions/api/README.md new file mode 100644 index 0000000000..e751aa7a19 --- /dev/null +++ b/docs/extensions/api/README.md @@ -0,0 +1,3 @@ +# Lens Extension API Reference + +TBD diff --git a/docs/extensions/capabilities/README.md b/docs/extensions/capabilities/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/extensions/capabilities/common-capabilities.md b/docs/extensions/capabilities/common-capabilities.md new file mode 100644 index 0000000000..ee8745df08 --- /dev/null +++ b/docs/extensions/capabilities/common-capabilities.md @@ -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: () => , + Input: () => + } + } + ] +} +``` + +### 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: () => , + 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 ( + + Just an example. + + ) + } + }, + 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: ( +
Navigation.navigate("/example-page")} + > + +
+ ) + } + ] +} + +``` + +### 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) => + } + } + ] +} + +``` + +### 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) => + } + } + ] +} +``` diff --git a/docs/extensions/capabilities/theming.md b/docs/extensions/capabilities/theming.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/extensions/get-started/anatomy.md b/docs/extensions/get-started/anatomy.md new file mode 100644 index 0000000000..523c6b9781 --- /dev/null +++ b/docs/extensions/get-started/anatomy.md @@ -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 `@/` 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: () => , + 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. \ No newline at end of file diff --git a/docs/extensions/get-started/wrapping-up.md b/docs/extensions/get-started/wrapping-up.md new file mode 100644 index 0000000000..95f36dbe88 --- /dev/null +++ b/docs/extensions/get-started/wrapping-up.md @@ -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) diff --git a/docs/extensions/get-started/your-first-extension.md b/docs/extensions/get-started/your-first-extension.md new file mode 100644 index 0000000000..0b057d2a87 --- /dev/null +++ b/docs/extensions/get-started/your-first-extension.md @@ -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 /helloworld-sample helloworld-sample +``` + +To build the extension you can use `make` or run the `npm` commands manually: + +```sh +cd /helloworld-sample +make build +``` + +OR + +```sh +cd /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 /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 `/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. diff --git a/docs/extensions/guides/README.md b/docs/extensions/guides/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/extensions/guides/renderer-extension.md b/docs/extensions/guides/renderer-extension.md new file mode 100644 index 0000000000..fc4f9b8bdd --- /dev/null +++ b/docs/extensions/guides/renderer-extension.md @@ -0,0 +1 @@ +# Renderer Extension diff --git a/docs/extensions/testing-and-publishing/bundling.md b/docs/extensions/testing-and-publishing/bundling.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/extensions/testing-and-publishing/publishing.md b/docs/extensions/testing-and-publishing/publishing.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/extensions/testing-and-publishing/testing.md b/docs/extensions/testing-and-publishing/testing.md new file mode 100644 index 0000000000..f96e3ce9e5 --- /dev/null +++ b/docs/extensions/testing-and-publishing/testing.md @@ -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) +``` diff --git a/docs/extensions/usage/README.md b/docs/extensions/usage/README.md new file mode 100644 index 0000000000..7ca1ab7e51 --- /dev/null +++ b/docs/extensions/usage/README.md @@ -0,0 +1,3 @@ +# Using Extensions + +TBD diff --git a/docs/faq/README.md b/docs/faq/README.md new file mode 100644 index 0000000000..a0990367ef --- /dev/null +++ b/docs/faq/README.md @@ -0,0 +1 @@ +TBD diff --git a/docs/getting-started/README.md b/docs/getting-started/README.md new file mode 100644 index 0000000000..e4c6c38bec --- /dev/null +++ b/docs/getting-started/README.md @@ -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) + diff --git a/docs/getting-started/images/color-theme.png b/docs/getting-started/images/color-theme.png new file mode 100644 index 0000000000..5e4f144560 Binary files /dev/null and b/docs/getting-started/images/color-theme.png differ diff --git a/docs/getting-started/images/disabled-telemetry-usage-tracking.png b/docs/getting-started/images/disabled-telemetry-usage-tracking.png new file mode 100644 index 0000000000..809a96056a Binary files /dev/null and b/docs/getting-started/images/disabled-telemetry-usage-tracking.png differ diff --git a/docs/getting-started/images/snap-store.png b/docs/getting-started/images/snap-store.png new file mode 100644 index 0000000000..5e652132c3 Binary files /dev/null and b/docs/getting-started/images/snap-store.png differ diff --git a/docs/getting-started/introductory-videos.md b/docs/getting-started/introductory-videos.md new file mode 100644 index 0000000000..fcaee999c0 --- /dev/null +++ b/docs/getting-started/introductory-videos.md @@ -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. + + diff --git a/docs/getting-started/preferences.md b/docs/getting-started/preferences.md new file mode 100644 index 0000000000..cd71e476f8 --- /dev/null +++ b/docs/getting-started/preferences.md @@ -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) + diff --git a/docs/helm/README.md b/docs/helm/README.md new file mode 100644 index 0000000000..c6ea505cc3 --- /dev/null +++ b/docs/helm/README.md @@ -0,0 +1,3 @@ +# Using Helm Charts + +TBD diff --git a/docs/img/favicon.ico b/docs/img/favicon.ico new file mode 100644 index 0000000000..19b2de71d1 Binary files /dev/null and b/docs/img/favicon.ico differ diff --git a/docs/img/lens-intro-video-screenshot.png b/docs/img/lens-intro-video-screenshot.png new file mode 100644 index 0000000000..2c5467b3f0 Binary files /dev/null and b/docs/img/lens-intro-video-screenshot.png differ diff --git a/docs/img/lens-logo-icon.svg b/docs/img/lens-logo-icon.svg new file mode 100644 index 0000000000..ede39244e5 --- /dev/null +++ b/docs/img/lens-logo-icon.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + diff --git a/docs/img/play.svg b/docs/img/play.svg new file mode 100644 index 0000000000..a94d6e88ab --- /dev/null +++ b/docs/img/play.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css new file mode 100644 index 0000000000..f727034bbd --- /dev/null +++ b/docs/stylesheets/extra.css @@ -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 +} + diff --git a/docs/supporting/requirements.md b/docs/supporting/requirements.md new file mode 100644 index 0000000000..6eb929a3b3 --- /dev/null +++ b/docs/supporting/requirements.md @@ -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 + +... diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000000..b8159f8fd2 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,93 @@ +site_name: Lens Documentation +site_description: Documentation for Lens IDE. The only system you’ll 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 © 2020 Mirantis Inc. - 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 diff --git a/mkdocs/Dockerfile b/mkdocs/Dockerfile new file mode 100644 index 0000000000..81a82d3443 --- /dev/null +++ b/mkdocs/Dockerfile @@ -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"] diff --git a/mkdocs/requirements.txt b/mkdocs/requirements.txt new file mode 100644 index 0000000000..4db6d92e25 --- /dev/null +++ b/mkdocs/requirements.txt @@ -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 \ No newline at end of file diff --git a/package.json b/package.json index f44078b42b..7a2f53f412 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "download:kubectl": "yarn run ts-node build/download_kubectl.ts", "download:helm": "yarn run ts-node build/download_helm.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": { "bundledKubectlVersion": "1.17.11", diff --git a/src/common/user-store.ts b/src/common/user-store.ts index 0bb953b153..b03616c1d2 100644 --- a/src/common/user-store.ts +++ b/src/common/user-store.ts @@ -31,7 +31,7 @@ export interface UserPreferences { } export class UserStore extends BaseStore { - static readonly defaultTheme: ThemeId = "kontena-dark" + static readonly defaultTheme: ThemeId = "lens-dark" private constructor() { super({ diff --git a/src/extensions/extension-loader.ts b/src/extensions/extension-loader.ts index 64c4270439..fc918476fb 100644 --- a/src/extensions/extension-loader.ts +++ b/src/extensions/extension-loader.ts @@ -4,10 +4,11 @@ import type { LensRendererExtension } from "./lens-renderer-extension" import type { InstalledExtension } from "./extension-manager"; import path from "path" 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 { app, ipcRenderer, remote } from "electron" import * as registries from "./registries"; +import { extensionsStore } from "./extensions-store"; // lazy load so that we get correct userData export function extensionPackagesRoot() { @@ -15,33 +16,42 @@ export function extensionPackagesRoot() { } export class ExtensionLoader { + protected extensions = observable.map(); + protected instances = observable.map(); + @observable isLoaded = false; - protected extensions = observable.map([], { deep: false }); - protected instances = observable.map([], { deep: false }) + whenLoaded = when(() => this.isLoaded); constructor() { if (ipcRenderer) { - ipcRenderer.on("extensions:loaded", (event, extensions: InstalledExtension[]) => { + ipcRenderer.on("extensions:loaded", (event, extensions: [LensExtensionId, InstalledExtension][]) => { this.isLoaded = true; - extensions.forEach((ext) => { - if (!this.extensions.has(ext.manifestPath)) { - this.extensions.set(ext.manifestPath, ext) + extensions.forEach(([extId, ext]) => { + if (!this.extensions.has(extId)) { + this.extensions.set(extId, ext) } }) }); } + extensionsStore.manageState(this); } - @computed get userExtensions(): LensExtension[] { - return [...this.instances.values()].filter(ext => !ext.isBundled) + @computed get userExtensions(): Map { + const extensions = this.extensions.toJS(); + extensions.forEach((ext, extId) => { + if (ext.isBundled) { + extensions.delete(extId); + } + }) + return extensions; } - async init() { - const { extensionManager } = await import("./extension-manager"); - const installedExtensions = await extensionManager.load(); - this.extensions.replace(installedExtensions); + @action + async init(extensions: Map) { + this.extensions.replace(extensions); this.isLoaded = true; this.loadOnMain(); + this.broadcastExtensions(); } loadOnMain() { @@ -71,21 +81,26 @@ export class ExtensionLoader { } protected autoInitExtensions(register: (ext: LensExtension) => Function[]) { - return reaction(() => this.extensions.toJS(), (installedExtensions) => { - for (const [id, ext] of installedExtensions) { - let instance = this.instances.get(ext.manifestPath) - if (!instance) { - const extensionModule = this.requireExtension(ext) - if (!extensionModule) { - continue - } + return reaction(() => this.toJSON(), installedExtensions => { + for (const [extId, ext] of installedExtensions) { + let instance = this.instances.get(extId); + if (ext.isEnabled && !instance) { try { - const LensExtensionClass: LensExtensionConstructor = extensionModule.default; + const LensExtensionClass: LensExtensionConstructor = this.requireExtension(ext) + if (!LensExtensionClass) continue; instance = new LensExtensionClass(ext); instance.whenEnabled(() => register(instance)); - this.instances.set(ext.manifestPath, instance); + instance.enable(); + this.instances.set(extId, instance); } 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)) } if (extEntrypoint !== "") { - return __non_webpack_require__(extEntrypoint) + return __non_webpack_require__(extEntrypoint).default; } } catch (err) { 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 { + return toJS(this.extensions, { + exportMapsAsObjects: false, + recurseEverything: true, + }) + } + async broadcastExtensions(frameId?: number) { await when(() => this.isLoaded); broadcastIpc({ @@ -118,7 +144,7 @@ export class ExtensionLoader { frameId: frameId, frameOnly: !!frameId, args: [ - Array.from(this.extensions.toJS().values()) + Array.from(this.toJSON()), ], }) } diff --git a/src/extensions/extension-manager.ts b/src/extensions/extension-manager.ts index 1d37707596..7a10fa35f4 100644 --- a/src/extensions/extension-manager.ts +++ b/src/extensions/extension-manager.ts @@ -8,9 +8,10 @@ import { extensionPackagesRoot } from "./extension-loader" import { getBundledExtensions } from "../common/utils/app-version" export interface InstalledExtension { - manifest: LensExtensionManifest; - manifestPath: string; - isBundled?: boolean; // defined in package.json + readonly manifest: LensExtensionManifest; + readonly manifestPath: string; + readonly isBundled: boolean; // defined in project root's package.json + isEnabled: boolean; } type Dependencies = { @@ -77,7 +78,7 @@ export class ExtensionManager { return await this.loadExtensions(); } - protected async getByManifest(manifestPath: string): Promise { + protected async getByManifest(manifestPath: string, { isBundled = false } = {}): Promise { let manifestJson: LensExtensionManifest; try { fs.accessSync(manifestPath, fs.constants.F_OK); // check manifest file for existence @@ -88,6 +89,8 @@ export class ExtensionManager { return { manifestPath: path.join(this.nodeModulesPath, manifestJson.name, "package.json"), manifest: manifestJson, + isBundled: isBundled, + isEnabled: isBundled, } } catch (err) { 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 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) { - ext.isBundled = true; extensions.push(ext) } } diff --git a/src/extensions/extensions-store.ts b/src/extensions/extensions-store.ts new file mode 100644 index 0000000000..ba942c41d9 --- /dev/null +++ b/src/extensions/extensions-store.ts @@ -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; +} + +export interface LensExtensionState { + enabled?: boolean; +} + +export class ExtensionsStore extends BaseStore { + constructor() { + super({ + configName: "lens-extensions", + }); + } + + protected state = observable.map(); + + protected getState(extensionLoader: ExtensionLoader) { + const state: Record = {}; + 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(); diff --git a/src/extensions/lens-extension.ts b/src/extensions/lens-extension.ts index 246edfe110..f1ffb9184b 100644 --- a/src/extensions/lens-extension.ts +++ b/src/extensions/lens-extension.ts @@ -1,7 +1,6 @@ import type { InstalledExtension } from "./extension-manager"; -import { action, reaction } from "mobx"; +import { action, observable, reaction } from "mobx"; import logger from "../main/logger"; -import { ExtensionStore } from "./extension-store"; export type LensExtensionId = string; // path to manifest (package.json) export type LensExtensionConstructor = new (...args: ConstructorParameters) => LensExtension; @@ -14,35 +13,17 @@ export interface LensExtensionManifest { renderer?: string; // path to %ext/dist/renderer.js } -export interface LensExtensionStoreModel { - isEnabled: boolean; -} - -export class LensExtension = any> { - protected store: S; +export class LensExtension { readonly manifest: LensExtensionManifest; readonly manifestPath: string; readonly isBundled: boolean; + @observable private isEnabled = false; + constructor({ manifest, manifestPath, isBundled }: InstalledExtension) { this.manifest = manifest this.manifestPath = manifestPath 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 { @@ -64,7 +45,7 @@ export class LensExtension = a @action async enable() { if (this.isEnabled) return; - this.store.data.isEnabled = true; + this.isEnabled = true; this.onActivate(); logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`); } @@ -72,7 +53,7 @@ export class LensExtension = a @action async disable() { if (!this.isEnabled) return; - this.store.data.isEnabled = false; + this.isEnabled = false; this.onDeactivate(); logger.info(`[EXTENSION]: disabled ${this.name}@${this.version}`); } @@ -114,13 +95,3 @@ export class LensExtension = a // mock } } - -function createBaseStore() { - return class extends ExtensionStore { - constructor() { - super({ - configName: "state" - }); - } - } -} diff --git a/src/main/index.ts b/src/main/index.ts index 762c166bc4..01b98d0f41 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -21,6 +21,8 @@ import { userStore } from "../common/user-store"; import { workspaceStore } from "../common/workspace-store"; import { appEventBus } from "../common/event-bus" 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); let proxyPort: number; @@ -52,6 +54,7 @@ app.on("ready", async () => { userStore.load(), clusterStore.load(), workspaceStore.load(), + extensionsStore.load(), ]); // find free port @@ -76,7 +79,7 @@ app.on("ready", async () => { } 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(() => { appEventBus.emit({ name: "app", action: "start" }) diff --git a/src/main/menu.ts b/src/main/menu.ts index 037378537d..cb8f260dcf 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -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 { WindowManager } from "./window-manager"; import { appName, isMac, isWindows } from "../common/vars"; @@ -193,6 +193,12 @@ export function buildMenu(windowManager: WindowManager) { navigate(whatsNewURL()) }, }, + { + label: "Documentation", + click: async () => { + shell.openExternal('https://docs.k8slens.dev/'); + }, + }, ...ignoreOnMac([ { label: "About Lens", diff --git a/src/renderer/bootstrap.tsx b/src/renderer/bootstrap.tsx index 7311e0e0cf..52a92b7c11 100644 --- a/src/renderer/bootstrap.tsx +++ b/src/renderer/bootstrap.tsx @@ -4,6 +4,8 @@ import React from "react"; import * as Mobx from "mobx" import * as MobxReact from "mobx-react" import * as LensExtensions from "../extensions/extension-api" +import { App } from "./components/app"; +import { LensApp } from "./lens-app"; import { render, unmountComponentAtNode } from "react-dom"; import { isMac } from "../common/vars"; import { userStore } from "../common/user-store"; @@ -11,8 +13,7 @@ import { workspaceStore } from "../common/workspace-store"; import { clusterStore } from "../common/cluster-store"; import { i18nStore } from "./i18n"; import { themeStore } from "./theme.store"; -import { App } from "./components/app"; -import { LensApp } from "./lens-app"; +import { extensionsStore } from "../extensions/extensions-store"; type AppComponent = React.ComponentType & { init?(): Promise; @@ -34,6 +35,7 @@ export async function bootstrap(App: AppComponent) { userStore.load(), workspaceStore.load(), clusterStore.load(), + extensionsStore.load(), i18nStore.init(), themeStore.init(), ]); diff --git a/src/renderer/components/+extensions/extensions.scss b/src/renderer/components/+extensions/extensions.scss index 8e9256c201..63778d37e9 100644 --- a/src/renderer/components/+extensions/extensions.scss +++ b/src/renderer/components/+extensions/extensions.scss @@ -2,11 +2,17 @@ --width: 100%; --max-width: auto; - .extension { - --flex-gap: $padding / 3; - padding: $padding $padding * 2; - background: $colorVague; - border-radius: $radius; + .extension-list { + .extension { + --flex-gap: $padding / 3; + padding: $padding $padding * 2; + background: $colorVague; + border-radius: $radius; + + &:not(:first-of-type) { + margin-top: $padding * 2; + } + } } .extensions-path { diff --git a/src/renderer/components/+extensions/extensions.tsx b/src/renderer/components/+extensions/extensions.tsx index 7dc5f55726..34814393ae 100644 --- a/src/renderer/components/+extensions/extensions.tsx +++ b/src/renderer/components/+extensions/extensions.tsx @@ -19,7 +19,8 @@ export class Extensions extends React.Component { @computed get extensions() { 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 [ name.toLowerCase().includes(searchText), description.toLowerCase().includes(searchText), @@ -68,9 +69,10 @@ export class Extensions extends React.Component { ) } return extensions.map(ext => { - const { id, name, description, isEnabled } = ext; + const { manifestPath: extId, isEnabled, manifest } = ext; + const { name, description } = manifest; return ( -
+
Name: {name} @@ -80,10 +82,10 @@ export class Extensions extends React.Component {
{!isEnabled && ( - + )} {isEnabled && ( - + )}
) @@ -102,7 +104,7 @@ export class Extensions extends React.Component { value={this.search} onChange={(value) => this.search = value} /> -
+
{this.renderExtensions()}
diff --git a/src/renderer/components/dock/terminal.ts b/src/renderer/components/dock/terminal.ts index e508cc22b2..ea17554a31 100644 --- a/src/renderer/components/dock/terminal.ts +++ b/src/renderer/components/dock/terminal.ts @@ -178,7 +178,6 @@ export class Terminal { break; // 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": evt.preventDefault(); break; diff --git a/src/renderer/theme.store.ts b/src/renderer/theme.store.ts index 539be6651d..e96bc1f873 100644 --- a/src/renderer/theme.store.ts +++ b/src/renderer/theme.store.ts @@ -25,8 +25,8 @@ export class ThemeStore { // bundled themes from `themes/${themeId}.json` @observable themes: Theme[] = [ - { id: "kontena-dark", type: ThemeType.DARK }, - { id: "kontena-light", type: ThemeType.LIGHT }, + { id: "lens-dark", type: ThemeType.DARK }, + { id: "lens-light", type: ThemeType.LIGHT }, ]; @computed get activeThemeId() { diff --git a/src/renderer/themes/kontena-dark.json b/src/renderer/themes/lens-dark.json similarity index 100% rename from src/renderer/themes/kontena-dark.json rename to src/renderer/themes/lens-dark.json diff --git a/src/renderer/themes/kontena-light.json b/src/renderer/themes/lens-light.json similarity index 100% rename from src/renderer/themes/kontena-light.json rename to src/renderer/themes/lens-light.json