diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 1f32789f4e..33dfe83206 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -30,17 +30,16 @@ jobs: displayName: Install Node.js - task: Cache@2 inputs: - key: yarn | $(Agent.OS) | yarn.lock + key: 'yarn | "$(Agent.OS)"" | yarn.lock' restoreKeys: | yarn | "$(Agent.OS)" - yarn path: $(YARN_CACHE_FOLDER) displayName: Cache Yarn packages - - script: make install-deps + - script: make node_modules displayName: Install dependencies - script: make build-npm displayName: Generate npm package - - script: make build-extensions + - script: make -j2 build-extensions displayName: Build bundled extensions - script: make integration-win displayName: Run integration tests @@ -70,17 +69,16 @@ jobs: displayName: Install Node.js - task: Cache@2 inputs: - key: yarn | $(Agent.OS) | yarn.lock + key: 'yarn | "$(Agent.OS)" | yarn.lock' restoreKeys: | yarn | "$(Agent.OS)" - yarn path: $(YARN_CACHE_FOLDER) displayName: Cache Yarn packages - - script: make install-deps + - script: make node_modules displayName: Install dependencies - script: make build-npm displayName: Generate npm package - - script: make build-extensions + - script: make -j2 build-extensions displayName: Build bundled extensions - script: make test displayName: Run tests @@ -116,19 +114,18 @@ jobs: displayName: Install Node.js - task: Cache@2 inputs: - key: yarn | $(Agent.OS) | yarn.lock + key: 'yarn | "$(Agent.OS)" | yarn.lock' restoreKeys: | yarn | "$(Agent.OS)" - yarn path: $(YARN_CACHE_FOLDER) displayName: Cache Yarn packages - - script: make install-deps + - script: make node_modules displayName: Install dependencies - script: make lint displayName: Lint - script: make build-npm displayName: Generate npm package - - script: make build-extensions + - script: make -j2 build-extensions displayName: Build bundled extensions - script: make test displayName: Run tests @@ -164,4 +161,4 @@ jobs: displayName: Publish npm package condition: "and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))" env: - NPM_TOKEN: $(NPM_TOKEN) \ No newline at end of file + NPM_TOKEN: $(NPM_TOKEN) diff --git a/.eslintrc.js b/.eslintrc.js index 63ace2611b..913d959a97 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,8 @@ -module.exports = { - ignorePatterns: ["src/extensions/npm/extensions/dist/**/*"], +module.exports = { + ignorePatterns: [ + "**/node_modules/**/*", + "**/dist/**/*", + ], overrides: [ { files: [ @@ -13,13 +16,17 @@ module.exports = { env: { node: true }, - parserOptions: { + parserOptions: { ecmaVersion: 2018, sourceType: 'module', }, rules: { - "indent": ["error", 2], + "indent": ["error", 2, { + "SwitchCase": 1, + }], "no-unused-vars": "off", + "semi": ["error", "always"], + "object-shorthand": "error", } }, { @@ -32,10 +39,10 @@ module.exports = { "__mocks__/*.ts", ], parser: "@typescript-eslint/parser", - extends: [ + extends: [ 'plugin:@typescript-eslint/recommended', ], - parserOptions: { + parserOptions: { ecmaVersion: 2018, sourceType: 'module', }, @@ -47,7 +54,12 @@ module.exports = { "@typescript-eslint/ban-types": "off", "@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/no-empty-interface": "off", - "indent": ["error", 2] + "indent": ["error", 2, { + "SwitchCase": 1, + }], + "semi": "off", + "@typescript-eslint/semi": ["error"], + "object-shorthand": "error", }, }, { @@ -55,10 +67,10 @@ module.exports = { "src/renderer/**/*.tsx", ], parser: "@typescript-eslint/parser", - extends: [ + extends: [ 'plugin:@typescript-eslint/recommended', ], - parserOptions: { + parserOptions: { ecmaVersion: 2018, sourceType: 'module', jsx: true, @@ -75,7 +87,12 @@ module.exports = { "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/ban-types": "off", "@typescript-eslint/no-empty-function": "off", - "indent": ["error", 2] + "indent": ["error", 2, { + "SwitchCase": 1, + }], + "semi": "off", + "@typescript-eslint/semi": ["error"], + "object-shorthand": "error", }, } ] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6560efcc11..d70f5f10dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,9 @@ on: push: branches: - master - + release: + types: + - published jobs: build: name: Deploy docs @@ -27,13 +29,12 @@ jobs: - name: Checkout Release from lens uses: actions/checkout@v2 with: - repository: lensapp/lens + fetch-depth: 0 - name: git config run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git pull - name: Using Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 @@ -45,17 +46,19 @@ jobs: yarn install yarn typedocs-extensions-api - - name: mkdocs deploy latest + - name: mkdocs deploy master + if: contains(github.ref, 'refs/heads/master') run: | - mike deploy --push latest + mike deploy --push master - - - name: mkdocs deploy new release / tag - if: contains(github.ref, 'refs/tags/v') + - name: Get the release version + if: contains(github.ref, 'refs/tags/v') # && !github.event.release.prerelease (generate pre-release docs until Lens 4.0.0 is GA, see #1408) + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + + - name: mkdocs deploy new release + if: contains(github.ref, 'refs/tags/v') # && !github.event.release.prerelease (generate pre-release docs until Lens 4.0.0 is GA, see #1408) run: | - mike deploy --push--update-aliases ${{ github.ref }} latest - mike set-default --push ${{ github.ref }} - - - - + mike deploy --push --update-aliases ${{ steps.get_version.outputs.VERSION }} latest + mike set-default --push ${{ steps.get_version.outputs.VERSION }} + diff --git a/.github/workflows/mkdocs-delete-version.yml b/.github/workflows/mkdocs-delete-version.yml new file mode 100644 index 0000000000..0183910d8d --- /dev/null +++ b/.github/workflows/mkdocs-delete-version.yml @@ -0,0 +1,38 @@ +name: Delete Documentation Version +on: + workflow_dispatch: + inputs: + version: + description: 'Version string to be deleted (e.g."v0.0.1")' + required: true +jobs: + build: + name: Delete docs Version + 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 mike + + - name: Checkout Release from lens + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: git config + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + + - name: mkdocs delete version + run: | + mike delete --push ${{ github.event.inputs.version }} + \ No newline at end of file diff --git a/.github/workflows/mkdocs-set-default-version.yml b/.github/workflows/mkdocs-set-default-version.yml new file mode 100644 index 0000000000..694a7af726 --- /dev/null +++ b/.github/workflows/mkdocs-set-default-version.yml @@ -0,0 +1,38 @@ +name: Update Default Documentation Version +on: + workflow_dispatch: + inputs: + version: + description: 'Version string to be default (e.g."v0.0.1")' + required: true +jobs: + build: + name: Update default docs Version + 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 mike + + - name: Checkout Release from lens + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: git config + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + + - name: mkdocs update default version + run: | + mike set-default --push ${{ github.event.inputs.version }} + \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..6eaa07c2fd --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,132 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +info@k8slens.dev. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available +at [https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..1c745f852d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contributing to Lens + +See [Contributing to Lens](https://docs.k8slens.dev/latest/contributing/) documentation. diff --git a/Makefile b/Makefile index c5252a9748..1f8d4f5392 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ EXTENSIONS_DIR = ./extensions +extensions = $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), ${dir}) +extension_node_modules = $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), ${dir}/node_modules) +extension_dists = $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), ${dir}/dist) ifeq ($(OS),Windows_NT) DETECTED_OS := Windows @@ -6,29 +9,23 @@ else DETECTED_OS := $(shell uname) endif -.PHONY: init -init: install-deps download-bins compile-dev - echo "Init done" - -.PHONY: download-bins -download-bins: +binaries/client: yarn download-bins -.PHONY: install-deps -install-deps: +node_modules: yarn install --frozen-lockfile --verbose yarn check --verify-tree --integrity +static/build/LensDev.html: + yarn compile:renderer + .PHONY: compile-dev compile-dev: yarn compile:main --cache yarn compile:renderer --cache .PHONY: dev -dev: -ifeq ("$(wildcard static/build/main.js)","") - make init -endif +dev: node_modules binaries/client build-extensions static/build/LensDev.html yarn dev .PHONY: lint @@ -36,7 +33,7 @@ lint: yarn lint .PHONY: test -test: download-bins +test: binaries/client yarn test .PHONY: integration-linux @@ -59,20 +56,25 @@ test-app: yarn test .PHONY: build -build: install-deps download-bins build-extensions +build: node_modules binaries/client build-extensions ifeq "$(DETECTED_OS)" "Windows" yarn dist:win else yarn dist endif +$(extension_node_modules): + cd $(@:/node_modules=) && npm install --no-audit --no-fund + +$(extension_dists): src/extensions/npm/extensions/dist + cd $(@:/dist=) && npm run build + .PHONY: build-extensions -build-extensions: - $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), (cd $(dir) && npm install && npm run build || exit $?);) +build-extensions: $(extension_node_modules) $(extension_dists) .PHONY: test-extensions -test-extensions: - $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), (cd $(dir) && npm install --dev && npm run test || exit $?);) +test-extensions: $(extension_node_modules) + $(foreach dir, $(extensions), (cd $(dir) && npm run test || exit $?);) .PHONY: copy-extension-themes copy-extension-themes: @@ -97,6 +99,20 @@ publish-npm: build-npm npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" cd src/extensions/npm/extensions && npm publish --access=public +.PHONY: docs +docs: + yarn mkdocs-serve-local + +.PHONY: clean-extensions +clean-extensions: +ifeq "$(DETECTED_OS)" "Windows" + $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), if exist $(dir)\dist del /s /q $(dir)\dist) + $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), if exist $(dir)\node_modules del /s /q $(dir)\node_modules) +else + $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), rm -rf $(dir)/dist) + $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), rm -rf $(dir)/node_modules) +endif + .PHONY: clean-npm clean-npm: ifeq "$(DETECTED_OS)" "Windows" @@ -110,13 +126,13 @@ else endif .PHONY: clean -clean: clean-npm +clean: clean-npm clean-extensions ifeq "$(DETECTED_OS)" "Windows" - if exist binaries\client del /s /q binaries\client\*.* + if exist binaries\client del /s /q binaries\client if exist dist del /s /q dist\*.* if exist static\build del /s /q static\build\*.* else - rm -rf binaries/client/* + rm -rf binaries/client rm -rf dist/* rm -rf static/build/* endif diff --git a/README.md b/README.md index aba5ee87aa..7d86bf6c52 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Lens | The Kubernetes IDE [![Build Status](https://dev.azure.com/lensapp/lensapp/_apis/build/status/lensapp.lens?branchName=master)](https://dev.azure.com/lensapp/lensapp/_build/latest?definitionId=1&branchName=master) -[![Releases](https://img.shields.io/github/downloads/lensapp/lens/total.svg)](https://github.com/lensapp/lens/releases) +[![Releases](https://img.shields.io/github/downloads/lensapp/lens/total.svg)](https://github.com/lensapp/lens/releases?label=Downloads) [![Chat on Slack](https://img.shields.io/badge/chat-on%20slack-blue.svg?logo=slack&longCache=true&style=flat)](https://join.slack.com/t/k8slens/shared_invite/enQtOTc5NjAyNjYyOTk4LWU1NDQ0ZGFkOWJkNTRhYTc2YjVmZDdkM2FkNGM5MjhiYTRhMDU2NDQ1MzIyMDA4ZGZlNmExOTc0N2JmY2M3ZGI) World’s most popular Kubernetes IDE provides a simplified, consistent entry point for developers, testers, integrators, and DevOps, to ship code faster at scale. Lens is the only IDE you’ll ever need to take control of your Kubernetes clusters. It is a standalone application for MacOS, Windows and Linux operating systems. Lens is an open source project and free! @@ -25,50 +25,12 @@ World’s most popular Kubernetes IDE provides a simplified, consistent entry po ## Installation -Download a pre-built package from the [releases](https://github.com/lensapp/lens/releases) page. Lens can be also installed via [snapcraft](https://snapcraft.io/kontena-lens) (Linux only). - -Alternatively on Mac: -``` -brew cask install lens -``` +See [Getting Started](https://docs.k8slens.dev/latest/getting-started/) page. ## Development -> Prerequisites: Nodejs v12, make, yarn - -* `make init` - initial compilation, installing deps, etc. -* `make dev` - builds and starts the app -* `make test` - run tests - -## Development (advanced) - -Allows for faster separate re-runs of some of the more involved processes: - -1. `yarn dev:main` compiles electron's main process app part -1. `yarn dev:renderer` compiles electron's renderer app part -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) -- [ReactJS](https://reactjs.org/docs/getting-started.html) (front-end, ui) -- [MobX](https://mobx.js.org/) (app-state-management, back-end/front-end) -- [ElectronJS](https://www.electronjs.org/docs) (chrome/node) -- [NodeJS](https://nodejs.org/dist/latest-v12.x/docs/api/) (api docs) - - +See [Development](https://docs.k8slens.dev/latest/contributing/development/) page. ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/lensapp/lens. \ No newline at end of file +See [Contributing](https://docs.k8slens.dev/latest/contributing/) page. diff --git a/__mocks__/electron.ts b/__mocks__/electron.ts index 08c94f0f8c..86f35c956d 100644 --- a/__mocks__/electron.ts +++ b/__mocks__/electron.ts @@ -5,7 +5,7 @@ module.exports = { getVersion: jest.fn().mockReturnValue("3.0.0"), getLocale: jest.fn().mockRejectedValue("en"), getPath: jest.fn((name: string) => { - return "tmp" + return "tmp"; }), }, remote: { diff --git a/build/build_tray_icon.ts b/build/build_tray_icon.ts index 00d09b69bc..e02d884412 100644 --- a/build/build_tray_icon.ts +++ b/build/build_tray_icon.ts @@ -1,9 +1,9 @@ // Generate tray icons from SVG to PNG + different sizes and colors (B&W) // Command: `yarn build:tray-icons` -import path from "path" +import path from "path"; import sharp from "sharp"; -import jsdom from "jsdom" -import fs from "fs-extra" +import jsdom from "jsdom"; +import fs from "fs-extra"; export async function generateTrayIcon( { @@ -14,15 +14,15 @@ export async function generateTrayIcon( pixelSize = 32, shouldUseDarkColors = false, // managed by electron.nativeTheme.shouldUseDarkColors } = {}) { - outputFilename += shouldUseDarkColors ? "_dark" : "" - dpiSuffix = dpiSuffix !== "1x" ? `@${dpiSuffix}` : "" - const pngIconDestPath = path.resolve(outputFolder, `${outputFilename}${dpiSuffix}.png`) + outputFilename += shouldUseDarkColors ? "_dark" : ""; + dpiSuffix = dpiSuffix !== "1x" ? `@${dpiSuffix}` : ""; + const pngIconDestPath = path.resolve(outputFolder, `${outputFilename}${dpiSuffix}.png`); try { // Modify .SVG colors const trayIconColor = shouldUseDarkColors ? "white" : "black"; const svgDom = await jsdom.JSDOM.fromFile(svgIconPath); const svgRoot = svgDom.window.document.body.getElementsByTagName("svg")[0]; - svgRoot.innerHTML += `` + svgRoot.innerHTML += ``; const svgIconBuffer = Buffer.from(svgRoot.outerHTML); // Resize and convert to .PNG diff --git a/build/download_helm.ts b/build/download_helm.ts index 9dddf7fcdc..7a3dc62a72 100644 --- a/build/download_helm.ts +++ b/build/download_helm.ts @@ -1,3 +1,3 @@ -import { helmCli } from "../src/main/helm/helm-cli" +import { helmCli } from "../src/main/helm/helm-cli"; -helmCli.ensureBinary() +helmCli.ensureBinary(); diff --git a/build/download_kubectl.ts b/build/download_kubectl.ts index a697552aa8..137588ff58 100644 --- a/build/download_kubectl.ts +++ b/build/download_kubectl.ts @@ -1,20 +1,20 @@ -import packageInfo from "../package.json" -import fs from "fs" -import request from "request" -import md5File from "md5-file" -import requestPromise from "request-promise-native" -import { ensureDir, pathExists } from "fs-extra" -import path from "path" +import packageInfo from "../package.json"; +import fs from "fs"; +import request from "request"; +import md5File from "md5-file"; +import requestPromise from "request-promise-native"; +import { ensureDir, pathExists } from "fs-extra"; +import path from "path"; class KubectlDownloader { - public kubectlVersion: string - protected url: string + public kubectlVersion: string; + protected url: string; protected path: string; - protected dirname: string + protected dirname: string; constructor(clusterVersion: string, platform: string, arch: string, target: string) { this.kubectlVersion = clusterVersion; - const binaryName = platform === "windows" ? "kubectl.exe" : "kubectl" + const binaryName = platform === "windows" ? "kubectl.exe" : "kubectl"; this.url = `https://storage.googleapis.com/kubernetes-release/release/v${this.kubectlVersion}/bin/${platform}/${arch}/${binaryName}`; this.dirname = path.dirname(target); this.path = target; @@ -25,83 +25,85 @@ class KubectlDownloader { method: "HEAD", uri: this.url, resolveWithFullResponse: true - }).catch((error) => { console.log(error) }) + }).catch((error) => { console.log(error); }); if (response.headers["etag"]) { - return response.headers["etag"].replace(/"/g, "") + return response.headers["etag"].replace(/"/g, ""); } - return "" + return ""; } public async checkBinary() { - const exists = await pathExists(this.path) + const exists = await pathExists(this.path); if (exists) { - const hash = md5File.sync(this.path) - const etag = await this.urlEtag() + const hash = md5File.sync(this.path); + const etag = await this.urlEtag(); if(hash == etag) { - console.log("Kubectl md5sum matches the remote etag") - return true + console.log("Kubectl md5sum matches the remote etag"); + return true; } - console.log("Kubectl md5sum " + hash + " does not match the remote etag " + etag + ", unlinking and downloading again") - await fs.promises.unlink(this.path) + console.log("Kubectl md5sum " + hash + " does not match the remote etag " + etag + ", unlinking and downloading again"); + await fs.promises.unlink(this.path); } - return false + return false; } public async downloadKubectl() { const exists = await this.checkBinary(); if(exists) { - console.log("Already exists and is valid") - return + console.log("Already exists and is valid"); + return; } - await ensureDir(path.dirname(this.path), 0o755) + await ensureDir(path.dirname(this.path), 0o755); - const file = fs.createWriteStream(this.path) - console.log(`Downloading kubectl ${this.kubectlVersion} from ${this.url} to ${this.path}`) + const file = fs.createWriteStream(this.path); + console.log(`Downloading kubectl ${this.kubectlVersion} from ${this.url} to ${this.path}`); const requestOpts: request.UriOptions & request.CoreOptions = { uri: this.url, gzip: true - } - const stream = request(requestOpts) + }; + const stream = request(requestOpts); stream.on("complete", () => { - console.log("kubectl binary download finished") - file.end(() => {}) - }) + console.log("kubectl binary download finished"); + // eslint-disable-next-line @typescript-eslint/no-empty-function + file.end(() => {}); + }); stream.on("error", (error) => { - console.log(error) - fs.unlink(this.path, () => {}) - throw(error) - }) + console.log(error); + // eslint-disable-next-line @typescript-eslint/no-empty-function + fs.unlink(this.path, () => {}); + throw(error); + }); return new Promise((resolve, reject) => { file.on("close", () => { - console.log("kubectl binary download closed") + console.log("kubectl binary download closed"); fs.chmod(this.path, 0o755, (err) => { if (err) reject(err); - }) - resolve() - }) - stream.pipe(file) - }) + }); + resolve(); + }); + stream.pipe(file); + }); } } const downloadVersion = packageInfo.config.bundledKubectlVersion; -const baseDir = path.join(process.env.INIT_CWD, 'binaries', 'client') +const baseDir = path.join(process.env.INIT_CWD, 'binaries', 'client'); const downloads = [ { platform: 'linux', arch: 'amd64', target: path.join(baseDir, 'linux', 'x64', 'kubectl') }, { platform: 'darwin', arch: 'amd64', target: path.join(baseDir, 'darwin', 'x64', 'kubectl') }, { platform: 'windows', arch: 'amd64', target: path.join(baseDir, 'windows', 'x64', 'kubectl.exe') }, { platform: 'windows', arch: '386', target: path.join(baseDir, 'windows', 'ia32', 'kubectl.exe') } -] +]; downloads.forEach((dlOpts) => { - console.log(dlOpts) + console.log(dlOpts); const downloader = new KubectlDownloader(downloadVersion, dlOpts.platform, dlOpts.arch, dlOpts.target); console.log("Downloading: " + JSON.stringify(dlOpts)); - downloader.downloadKubectl().then(() => downloader.checkBinary().then(() => console.log("Download complete"))) -}) + downloader.downloadKubectl().then(() => downloader.checkBinary().then(() => console.log("Download complete"))); +}); diff --git a/build/notarize.js b/build/notarize.js index 3d97b152c5..9904dccc3b 100644 --- a/build/notarize.js +++ b/build/notarize.js @@ -1,4 +1,4 @@ -const { notarize } = require('electron-notarize') +const { notarize } = require('electron-notarize'); exports.default = async function notarizing(context) { const { electronPlatformName, appOutDir } = context; diff --git a/build/set_npm_version.ts b/build/set_npm_version.ts index 70ce97416d..17d4a1ef83 100644 --- a/build/set_npm_version.ts +++ b/build/set_npm_version.ts @@ -1,9 +1,9 @@ -import * as fs from "fs" -import * as path from "path" -import packageInfo from "../src/extensions/npm/extensions/package.json" -import appInfo from "../package.json" +import * as fs from "fs"; +import * as path from "path"; +import packageInfo from "../src/extensions/npm/extensions/package.json"; +import appInfo from "../package.json"; -const packagePath = path.join(__dirname, "../src/extensions/npm/extensions/package.json") +const packagePath = path.join(__dirname, "../src/extensions/npm/extensions/package.json"); -packageInfo.version = appInfo.version -fs.writeFileSync(packagePath, JSON.stringify(packageInfo, null, 2) + "\n") +packageInfo.version = appInfo.version; +fs.writeFileSync(packagePath, JSON.stringify(packageInfo, null, 2) + "\n"); diff --git a/docs/clusters/adding-clusters.md b/docs/clusters/adding-clusters.md index 87a228567d..d153d8c9bf 100644 --- a/docs/clusters/adding-clusters.md +++ b/docs/clusters/adding-clusters.md @@ -1,6 +1,6 @@ # Adding Clusters -Add clusters by clicking the **Add Cluster** button in the left-side menu. +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. @@ -13,4 +13,10 @@ Selected [cluster contexts](https://kubernetes.io/docs/concepts/configuration/or 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 +To see your currently-enabled config with `kubectl`, enter `kubectl config view --minify --raw` in your terminal. + +When connecting to a cluster, make sure you have a valid and working kubeconfig for the cluster. Following lists known "gotchas" in some authentication types used in kubeconfig with Lens app. + +## Exec auth plugins + +When using [exec auth](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#configuration) plugins make sure the paths that are used to call any binaries are full paths as Lens app might not be able to call binaries with relative paths. Make also sure that you pass all needed information either as arguments or env variables in the config, Lens app might not have all login shell env variables set automatically. diff --git a/docs/clusters/images/add-cluster.png b/docs/clusters/images/add-cluster.png index b53c09f704..fa7b632026 100644 Binary files a/docs/clusters/images/add-cluster.png and b/docs/clusters/images/add-cluster.png differ diff --git a/docs/contributing/README.md b/docs/contributing/README.md index 13a6ca8c05..6cf7053fb8 100644 --- a/docs/contributing/README.md +++ b/docs/contributing/README.md @@ -1,17 +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. +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! +Here are some ways you can contribute! -* [Development](./development.md) – Help making Lens better. -* [Maintaining the Project](./maintainers.md) – Become community maintainer and help us maintain the project. +* [Development](./development.md) – Help make Lens better. +* [Maintaining the Project](./maintainers.md) – Become a 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! +* [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)! +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 +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 index 8e5633cda9..b92edd319e 100644 --- a/docs/contributing/development.md +++ b/docs/contributing/development.md @@ -1,3 +1,40 @@ # Development -TBD +Thank you for taking the time to make a contribution to Lens. The following document is a set of guidelines and instructions for contributing to Lens. + +When contributing to this repository, please consider first discussing the change you wish to make by opening an issue. + +## Recommended Reading: + +- [TypeScript](https://www.typescriptlang.org/docs/home.html) (front-end/back-end) +- [ReactJS](https://reactjs.org/docs/getting-started.html) (front-end, ui) +- [MobX](https://mobx.js.org/) (app-state-management, back-end/front-end) +- [ElectronJS](https://www.electronjs.org/docs) (chrome/node) +- [NodeJS](https://nodejs.org/dist/latest-v12.x/docs/api/) (api docs) + +## Local Development Environment + +> Prerequisites: Nodejs v12, make, yarn + +* `make dev` - builds and starts the app +* `make clean` - cleanup local environment build artifacts + + +## Github Workflow + +We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), so all code changes are tracked via Pull Requests. +A detailed guide on the recommended workflow can be found below: + +* [Github Workflow](./github_workflow.md) + +## Code Testing + +All submitted PRs go through a set of tests and reviews. You can run most of these tests *before* a PR is submitted. +In fact, we recommend it, because it will save on many possible review iterations and automated tests. +The testing guidelines can be found here: + +* [Contributor's Guide to Testing](./testing.md) + +## License + +By contributing, you agree that your contributions will be licensed as described in [LICENSE](https://github.com/lensapp/lens/blob/master/LICENSE). diff --git a/docs/contributing/documentation.md b/docs/contributing/documentation.md index 00b9f9550e..501c57779f 100644 --- a/docs/contributing/documentation.md +++ b/docs/contributing/documentation.md @@ -1,14 +1,14 @@ # 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). +We are glad to see you're interested in contributing to the Lens documentation. If this is the first Open Source project you've contributed 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: +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. +3. You can start working on the issue. When you're done, simply submit a pull request. ## Requirements for Documentation Pull Requests @@ -18,5 +18,16 @@ When you create a new pull request, we expect some requirements to be met. * 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. +* If your Pull Request closes an issue, you must write `Closes #ISSUE_NUMBER` where the ISSUE_NUMBER is the number in the end of the link url or the relevent issue. This will link your pull request to the issue, and when it is merged, the issue will close. +* 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. + + +## Testing Documentation Site Locally + +Run a local instance of `mkdocs` in a docker container for developing the Lens Documentation. + +> Prerequisites: docker, yarn + +* `make docs` - local build and serve of mkdocs with auto update enabled + +Go to [localhost:8000](http://127.0.0.1:8000). diff --git a/docs/contributing/github_workflow.md b/docs/contributing/github_workflow.md new file mode 100644 index 0000000000..3509645b47 --- /dev/null +++ b/docs/contributing/github_workflow.md @@ -0,0 +1,148 @@ +# Github Workflow + + +- [Fork The Project](#fork-the-project) +- [Adding the Forked Remote](#adding-the-forked-remote) +- [Create & Rebase Your Feature Branch](#create--rebase-your-feature-branch) +- [Commit & Push](#commit--push) +- [Open a Pull Request](#open-a-pull-request) + - [Get a code review](#get-a-code-review) + - [Squash commits](#squash-commits) + - [Push Your Final Changes](#push-your-final-changes) + + +This guide assumes you have already cloned the upstream repo to your system via git clone. + +## Fork The Project + +1. Go to [http://github.com/lensapp/lens](http://github.com/lensapp/lens) +2. On the top, right-hand side, click on "fork" and select your username for the fork destination. + +## Adding the Forked Remote + +``` +export GITHUB_USER={ your github's username } + +cd $WORKDIR/lens +git remote add $GITHUB_USER git@github.com:${GITHUB_USER}/lens.git + +# Prevent push to Upstream +git remote set-url --push origin no_push + +# Set your fork remote as a default push target +git push --set-upstream $GITHUB_USER master +``` + +Your remotes should look something like this: + +``` +➜ git remote -v +origin https://github.com/lensapp/lens (fetch) +origin no_push (push) +my_fork git@github.com:{ github_username }/lens.git (fetch) +my_fork git@github.com:{ github_username }/lens.git (push) +``` + +## Create & Rebase Your Feature Branch + +Create a feature branch: + +``` +git branch -b my_feature_branch +``` + +Rebase your branch: + +``` +git fetch origin + +git rebase origin/master +Current branch my_feature_branch is up to date. +``` + +Please don't use `git pull` instead of the above `fetch / rebase`. `git pull` does a merge, which leaves merge commits. These make the commit history messy and violate the principle that commits ought to be individually understandable and useful. + +## Commit & Push + +Commit and sign your changes: + +``` +git commit -m "my commit title" --signoff +``` + +You can go back and edit/build/test some more, then `commit --amend` in a few cycles. + +When ready, push your changes to your fork's repository: + +``` +git push --set-upstream my_fork my_feature_branch +``` + +## Open a Pull Request + +See [Github Docs](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork). + +### Get a code review + +Once your pull request has been opened it will be assigned to one or more reviewers, and will go through a series of smoke tests. + +Commit changes made in response to review comments should be added to the same branch on your fork. + +Very small PRs are easy to review. Very large PRs are very difficult to review. + +### Squashing Commits +Commits on your branch should represent meaningful milestones or units of work. +Small commits that contain typo fixes, rebases, review feedbacks, etc should be squashed. + +To do that, it's best to perform an [interactive rebase](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History): + +#### Example +If you PR has 3 commits, count backwards from your last commit using `HEAD~3`: +``` +git rebase -i HEAD~3 +``` +Output would be similar to this: +``` +pick f7f3f6d Changed some code +pick 310154e fixed some typos +pick a5f4a0d made some review changes + +# Rebase 710f0f8..a5f4a0d onto 710f0f8 +# +# Commands: +# p, pick = use commit +# r, reword = use commit, but edit the commit message +# e, edit = use commit, but stop for amending +# s, squash = use commit, but meld into previous commit +# f, fixup = like "squash", but discard this commit's log message +# x, exec = run command (the rest of the line) using shell +# b, break = stop here (continue rebase later with 'git rebase --continue') +# d, drop = remove commit +# l, label