Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify more platforms and externalize environment checking #71

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2eabd4f
Identify Solaris goos, 386, mipsle and amd goarch
mmorel-35 Jan 18, 2022
04f2de3
externalize requirements from main.ts
mmorel-35 Jan 25, 2022
a62ee06
boolean flag doesn't need value
mmorel-35 Jan 27, 2022
de5e401
check version before consulting github api
mmorel-35 Feb 2, 2022
a9c6dc0
externalize requirements from main.ts
mmorel-35 Jan 25, 2022
e07abbf
boolean flag doesn't need value
mmorel-35 Jan 27, 2022
b03eb22
Merge branch 'patch-3' into browser_download_url
mmorel-35 Feb 6, 2022
63ef4c8
retrieve download url from github api
mmorel-35 Feb 6, 2022
96ddde2
remove @octokit/types @octokit/rest
mmorel-35 Feb 6, 2022
0593816
don't look for process.env['npm_package_version']
mmorel-35 Feb 7, 2022
16c3d14
install kubectl when kubernetes version can be identified throught im…
mmorel-35 Feb 9, 2022
f029a62
install kubectl only if identified
mmorel-35 Feb 9, 2022
d1ca53d
remove useless await and provide empty string as default for empty va…
mmorel-35 Feb 9, 2022
7ece80c
use catch after promise instead of try catch inside the promise
mmorel-35 Feb 9, 2022
313808b
mutualise octokit instantiation
mmorel-35 Feb 9, 2022
a5c975c
use core.info instead of console.log and define consts
mmorel-35 Feb 10, 2022
aa984ea
change log and log level for tools
mmorel-35 Feb 13, 2022
a903540
parse kubernetes version from kind config file
mmorel-35 Feb 10, 2022
9649d09
Group logs by action
mmorel-35 Feb 17, 2022
4701224
setup a Metallb load-balancer
mmorel-35 Feb 18, 2022
18ba799
setup a local registry
mmorel-35 Feb 18, 2022
545ec57
retrieve addresses instead of the first parts of the IP
mmorel-35 Feb 25, 2022
530a40f
simplify variables calculation
mmorel-35 Feb 26, 2022
c232c02
mutualize docker executor
mmorel-35 Feb 27, 2022
1c43ff0
executable command function
mmorel-35 Feb 27, 2022
5c5bbdf
Update README.md
mmorel-35 Feb 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/checkin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Build and test Action"
name: 'Build and test Action'
on: [push, pull_request]

jobs:
Expand All @@ -20,5 +20,5 @@ jobs:
- run: npm run test:coverage

- uses: codecov/codecov-action@v2

- run: npm audit
8 changes: 6 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Create cluster using KinD"
name: 'Create cluster using KinD'
on: [pull_request, push]

jobs:
Expand All @@ -15,8 +15,12 @@ jobs:

- run: npm run build

- name: "Run engineerd/setup-kind@${{github.sha}}"
- name: 'Run engineerd/setup-kind@${{github.sha}}'
uses: ./
with:
image: kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
loadBalancer: true
localRegistry: true

- run: kubectl cluster-info

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
__tests__/runner/*
lib/
dist/
coverage/
coverage/
.vscode/
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"endOfLine": "auto",
"printWidth": 100,
"singleQuote": true
}
}
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
> version 0.6 of Kind. See [this document for a detailed migration
> guide][kind-kubeconfig]

> Note: GitHub Actions workers come pre-configured with `kubectl`.

The following arguments can be configured on the job using the `with` keyword
(see example above). Currently, possible inputs are all the flags for
`kind cluster create`, with the additional version, which sets the Kind version
Expand All @@ -55,6 +53,8 @@ Optional inputs:
- `skipClusterLogsExport`: if `"true"`, the action will not export the cluster logs
- `verbosity`: numeric log verbosity, (info = 0, debug = 3, trace = 2147483647) (default `"0"`)
- `quiet`: silence all stderr output (default `"false"`)
- `loadBalancer`: setup a Metallb load-balancer (default `"false"`)
- `localRegistry`: setup a local registry on localhost:5000 (default `"false"`)

Example using optional inputs:

Expand All @@ -78,6 +78,26 @@ jobs:
echo "environment-kubeconfig:" ${KUBECONFIG}
```

## Kubectl

GitHub Actions workers come pre-configured with `kubectl` but if the Kubernetes version can be identified from the image
input or the images of the nodes in the config file, it will be installed in the tool-cache with the right version.

## Load-balancer

When `loadBalancer: true` a load-balancer is created based on <https://kind.sigs.k8s.io/docs/user/loadbalancer/>

## Local registry

When `localRegistry: true` a local registry is created based on <https://kind.sigs.k8s.io/docs/user/local-registry/>
It is then available on localhost:5000 as KIND_REGISTRY on the host machine

## Self-hosted agents

When using on a self-hosted agent, an access to GITHUB_API_URL (<https://api.github.com> by default) and <https://storage.googleapis.com> are required for setup-kind to work properly.

NB: The load-balancer needs an access to <https://raw.githubusercontent.com>

[kind-kubeconfig]: https://github.com/kubernetes-sigs/kind/issues/1060
[gh-actions-path]:
https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
Expand Down
6 changes: 3 additions & 3 deletions __tests__/go.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as go from '../src/go';
import { env as goenv } from '../src/go';

describe('checking go env simulation', function () {
it('correctly parse os', () => {
expect(['windows', 'darwin', 'linux']).toContain(go.goos());
expect(['windows', 'darwin', 'linux']).toContain(goenv.GOOS);
});

it('correctly parse arch', () => {
expect(['amd64', 'arm64']).toContain(go.goarch());
expect(['amd64', 'arm64']).toContain(goenv.GOARCH);
});
});
5 changes: 1 addition & 4 deletions __tests__/kind/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { KindMainService } from '../../src/kind/main';
const testEnvVars = {
INPUT_VERBOSITY: '3',
INPUT_QUIET: 'true',
INPUT_VERSION: 'v0.5.3',
INPUT_CONFIG: 'some-path',
INPUT_IMAGE: 'some-docker-image',
INPUT_NAME: 'some-name',
Expand All @@ -30,7 +29,6 @@ describe('checking input parsing', function () {

it('correctly parse input', () => {
const service: KindMainService = KindMainService.getInstance();
expect(service.version).toEqual(testEnvVars.INPUT_VERSION);
expect(service.configFile).toEqual(testEnvVars.INPUT_CONFIG);
expect(service.image).toEqual(testEnvVars.INPUT_IMAGE);
expect(service.name).toEqual(testEnvVars.INPUT_NAME);
Expand All @@ -46,14 +44,13 @@ describe('checking input parsing', function () {
});

it('correctly generates the cluster create command', () => {
const args: string[] = KindMainService.getInstance().createCommand();
const args: string[] = KindMainService.getInstance().createCommand('');
expect(args).toEqual([
'create',
'cluster',
'--verbosity',
testEnvVars.INPUT_VERBOSITY,
'--quiet',
testEnvVars.INPUT_QUIET,
'--config',
path.normalize('/home/runner/repo/some-path'),
'--image',
Expand Down
12 changes: 6 additions & 6 deletions __tests__/kind/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ describe('checking input parsing', function () {
'--verbosity',
testEnvVars.INPUT_VERBOSITY,
'--quiet',
testEnvVars.INPUT_QUIET,
'--name',
testEnvVars.INPUT_NAME,
'--kubeconfig',
Expand All @@ -54,17 +53,18 @@ describe('checking input parsing', function () {
});

it('correctly generates the cluster export logs command', () => {
const args: string[] = KindPostService.getInstance().exportLogsCommand();
const logsDir = KindPostService.getInstance().kindLogsDir();
expect(logsDir).toEqual(
path.normalize('/home/runner/work/_temp/1c1900ec-8f4f-5069-a966-1d3072cc9723')
);
const args: string[] = KindPostService.getInstance().exportLogsCommand(logsDir);
expect(args).toEqual([
'export',
'logs',
path.normalize(
'/home/runner/work/_temp/1c1900ec-8f4f-5069-a966-1d3072cc9723'
),
path.normalize('/home/runner/work/_temp/1c1900ec-8f4f-5069-a966-1d3072cc9723'),
'--verbosity',
testEnvVars.INPUT_VERBOSITY,
'--quiet',
testEnvVars.INPUT_QUIET,
'--name',
testEnvVars.INPUT_NAME,
]);
Expand Down
23 changes: 23 additions & 0 deletions __tests__/local-registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { hasRegistryConfig } from '../src/local-registry';

describe('checking registry validation', function () {
it('disable_tcp_service configuration', () => {
const configPatch = `[plugins."io.containerd.grpc.v1.cri"]
disable_tcp_service = true`;
expect(hasRegistryConfig(configPatch)).toBeFalsy();
});
it('empty configuration', () => {
const configPatch = ``;
expect(hasRegistryConfig(configPatch)).toBeFalsy();
});
it('wrong port', () => {
const configPatch = `[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5001"]
endpoint = ["http://kind-registry:5000"]`;
expect(hasRegistryConfig(configPatch)).toBeFalsy();
});
it('correctly configured', () => {
const configPatch = `[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
endpoint = ["http://kind-registry:5000"]`;
expect(hasRegistryConfig(configPatch)).toBeTruthy();
});
});
31 changes: 31 additions & 0 deletions __tests__/requirements.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { checkEnvironment } from '../src/requirements';

const testEnvVars = {
INPUT_VERSION: 'v0.7.0',
GITHUB_JOB: 'kind',
GITHUB_WORKSPACE: '/home/runner/repo',
RUNNER_OS: 'Linux',
RUNNER_ARCH: 'X64',
RUNNER_TEMP: '/home/runner/work/_temp',
RUNNER_TOOL_CACHE: '/opt/hostedtoolcache',
};

describe('checking requirements', function () {
const originalEnv = process.env;
beforeEach(() => {
jest.resetModules();
process.env = {
...originalEnv,
...testEnvVars,
};
});

afterEach(() => {
process.env = originalEnv;
});

it('required GITHUB_JOB must be defined', async () => {
process.env['GITHUB_JOB'] = '';
await expect(checkEnvironment()).rejects.toThrow('Expected GITHUB_JOB to be defined');
});
});
60 changes: 35 additions & 25 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
name: "KinD (Kubernetes in Docker) Action"
description: "Easily run a Kubernetes cluster in your GitHub Action"
author: "Engineerd"
name: 'KinD (Kubernetes in Docker) Action'
description: 'Easily run a Kubernetes cluster in your GitHub Action'
author: 'Engineerd'
inputs:
version:
description: "Version of Kind to use (default v0.11.1)"
default: "v0.11.1"
description: 'Version of Kind to use (default v0.11.1)'
default: 'v0.11.1'
required: true
config:
description: "Path (relative to the root of the repository) to a kind config file"
description: 'Path (relative to the root of the repository) to a kind config file'
image:
description: "Node Docker image to use for booting the cluster"
description: 'Node Docker image to use for booting the cluster'
name:
description: "Cluster name (default kind)"
default: "kind"
description: 'Cluster name (default kind)'
default: 'kind'
required: true
wait:
description: "Wait for control plane node to be ready (default 300s)"
default: "300s"
description: 'Wait for control plane node to be ready (default 300s)'
default: '300s'
kubeconfig:
description: "Sets kubeconfig path instead of $KUBECONFIG or $HOME/.kube/config"
description: 'Sets kubeconfig path instead of $KUBECONFIG or $HOME/.kube/config'
skipClusterCreation:
description: "If true, the action will not create a cluster, just acquire the tools"
default: "false"
description: 'If true, the action will not create a cluster, just acquire the tools'
default: 'false'
skipClusterDeletion:
description: "If true, the action will not delete the cluster"
default: "false"
description: 'If true, the action will not delete the cluster'
default: 'false'
skipClusterLogsExport:
description: "If true, the action will not export the cluster logs"
default: "false"
description: 'If true, the action will not export the cluster logs'
default: 'false'
verbosity:
description: "Defines log verbosity with a numeric value, (info = 0, debug = 3, trace = 2147483647)"
default: "0"
description: 'Defines log verbosity with a numeric value, (info = 0, debug = 3, trace = 2147483647)'
default: '0'
quiet:
description: "Silence all stderr output"
default: "false"
description: 'Silence all stderr output'
default: 'false'
token:
description: 'Used to retrieve release informations concerning KinD and Kubernetes from https://api.github.com'
default: '${{ github.token }}'
required: true
loadBalancer:
description: 'Setup a Metallb load-balancer'
default: 'false'
localRegistry:
description: 'Setup a local registry on localhost:5000'
default: 'false'
runs:
using: "node12"
main: "dist/main/index.js"
post: "dist/post/index.js"
using: 'node12'
main: 'dist/main/index.js'
post: 'dist/post/index.js'
post-if: success()
Loading