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

Feat/launch config #18

Merged
merged 16 commits into from
Sep 3, 2023
49 changes: 49 additions & 0 deletions .github/workflows/e2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test Microk8s
on: [push]

jobs:
test:
runs-on: ubuntu-latest
name: A job to install MicroK8s
steps:
- uses: balchua/microk8s-actions@master
with:
channel: "1.26/stable"
addons: '["rbac", "dns", "hostpath-storage", "registry"]'

- name: Check User
run: |
id
sg microk8s -c 'microk8s status'

- name: Check push to local registry
run: |
docker pull busybox:1
echo $REGISTRY_IP
docker tag busybox:1 localhost:32000/my-repo/busybox:1
docker push localhost:32000/my-repo/busybox:1
curl http://localhost:32000/v2/_catalog

- name: Test MicroK8s
id: microk8s
run: |
set -ex
kubectl get no
kubectl get pods -A -o wide
sleep 120 # Give it sometime before we start checking for pod readiness.
# wait for storage pod to be ready
kubectl -n kube-system wait --for=condition=ready pod -l k8s-app=hostpath-provisioner --timeout=60s
storage_ready=$?

if [ $storage_ready -ne 0 ]; then
echo "Error storage not ready."
exit $storage_ready
fi
- name: Test MicroK8s commands
id: microk8s-commands
run: |
set -ex
echo "Executing microk8s status using sg command."
sg microk8s -c 'microk8s status'
echo "Executing microk8s status using sudo command."
sudo microk8s status
49 changes: 0 additions & 49 deletions .github/workflows/e2e.yaml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/launch-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Test Launch Configuration Microk8s
on: [push]

jobs:
test:
runs-on: ubuntu-latest

name: A job to install MicroK8s with launch configurations
steps:
- uses: actions/checkout@v3
with:
sparse-checkout: |
microk8s-config.yaml
sparse-checkout-cone-mode: false

- name: build-image-and-create-microk8s-config
run: |
mkdir -p $HOME/sideload
docker pull alpine:edge
docker save alpine:edge > $HOME/sideload/alpine-edge.tar

- uses: balchua/microk8s-actions@master
with:
channel: "1.28/stable"
launch-configuration: "$GITHUB_WORKSPACE/microk8s-config.yaml"
sideload-images-path: "$HOME/sideload/"

- name: Check Side loaded images
run: |
sudo microk8s ctr images ls | grep alpine:edge

- name: Check enabled addons
run: |
echo "wait for a few seconds"
sleep 120
sudo microk8s kubectl wait pods --for=jsonpath='{.status.phase}'=Running -l name=nginx-ingress-microk8s -n ingress --timeout=300s
sudo microk8s status --wait-ready
sudo microk8s status --addon dns --wait-ready | grep enabled
sudo microk8s status --addon ingress --wait-ready | grep enabled
sudo microk8s status --addon rbac --wait-ready | grep enabled
sudo microk8s status --addon hostpath-storage --wait-ready | grep enabled
sudo microk8s status --addon registry --wait-ready | grep enabled

- name: Check push to local registry
run: |
sudo microk8s kubectl wait --for=jsonpath='{.status.phase}'=Bound pvc/registry-claim -n container-registry --timeout=90s
sudo microk8s kubectl wait pods --for=jsonpath='{.status.phase}'=Running -l app=registry -n container-registry --timeout=90s
docker pull busybox:1
docker tag busybox:1 localhost:32000/my-repo/busybox:1
docker push localhost:32000/my-repo/busybox:1
curl http://localhost:32000/v2/_catalog

- name: Test MicroK8s
id: microk8s
run: |
set -ex
kubectl get no
kubectl get pods -A -o wide
sleep 120 # Give it sometime before we start checking for pod readiness.
# wait for storage pod to be ready
kubectl -n kube-system wait --for=condition=ready pod -l k8s-app=hostpath-provisioner --timeout=60s
storage_ready=$?

if [ $storage_ready -ne 0 ]; then
echo "Error storage not ready."
exit $storage_ready
fi
- name: Test MicroK8s commands
id: microk8s-commands
run: |
set -ex
echo "Executing microk8s status using sg command."
sg microk8s -c 'microk8s status'
echo "Executing microk8s status using sudo command."
sudo microk8s status
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,40 @@ New from `v0.2.0`

New from `v0.3.0`

### `launch-configuration`

New from `v0.4.0`

**Optional** A launch configuration is a YAML configuration file that can be applied to a MicroK8s node typically during installation. Example: `/home/runner/microk8s-config.yaml`

Once you have defined your `launch-configuration`, there is no need to add the addons one by one in the config.

Example:

``` yaml
- uses: balchua/microk8s-actions@feat/launch_config
with:
channel: "1.28/stable"
launch-configuration: "$GITHUB_WORKSPACE/microk8s-config.yaml"
sideload-images-path: "$HOME/sideload/"
```

**This is only available from MicroK8s `v1.27`**

### `sideload-images-path`

New from `v0.4.0`

**Optional**

Side load images automatically loads image tarballs to MicroK8s Containerd.
You can use this to automatically load your images into MicroK8s, without using a registry .

Example: `/home/runner/sideload/`

Please note that this is applicable during MicroK8s installation.

**This is only available from MicroK8s `v1.27`**

## Example Usage:

Expand Down Expand Up @@ -138,7 +171,9 @@ For more information regarding kubeflow addon check this [link](https://microk8s

## Building

The main program is a Typescript, located in [src/index.ts](src/index.ts). Before pushing the code to Github, you should compile the source to ES6.
The main program is a Typescript, located in [src](src/).

Before pushing the code to Github, you should compile the source to ES6.

```shell
$ npm run build
Expand Down
25 changes: 16 additions & 9 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
name: 'MicroK8s Action'
description: 'Run a MicroK8s Kubernetes cluster in your GitHub Action'
name: "MicroK8s Action"
description: "Run a MicroK8s Kubernetes cluster in your GitHub Action"
author: "balchua"
inputs:
channel: # MicroK8s channel
description: 'The MicroK8s Channel to use. More information here https://microk8s.io/docs/setting-snap-channel'
channel: # MicroK8s channel
description: "The MicroK8s Channel to use. More information here https://microk8s.io/docs/setting-snap-channel"
required: true
default: 'latest/stable'
default: "latest/stable"
devMode:
description: "Enable devmode, this is only applicable to strict confinement"
required: false
default: "false"
addons:
description: "A JSON array of addons to enable"
description: "A JSON array of addons to enable"
required: false
default: "[]"

launch-configuration:
description: "Fully qualified path where the custom MicroK8s launch configuration is located"
required: false
default: ""
sideload-images-path:
description: "Fully qualified path where the container image tarballs is located"
required: false
default: ""
runs:
using: 'node16'
main: 'lib/index.js'
using: "node16"
main: "lib/index.js"
44 changes: 44 additions & 0 deletions lib/addon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Addon = void 0;
const util = __importStar(require("./util"));
const status = __importStar(require("./status"));
const sh = __importStar(require("shelljs"));
class Addon {
constructor(addon) {
this.addon = addon;
}
enable() {
sh.echo('Start enabling ' + this.addon);
status.waitForReadyState();
if (this.addon === "kubeflow") {
sh.echo('kubeflow is no longer supported as a addon');
}
else {
util.executeCommand(false, 'sudo microk8s enable ' + this.addon);
status.silentWaitForStorageToBeReady(this.addon);
status.silentwaitForRegistryPvClaim(this.addon);
}
status.waitForReadyState();
}
}
exports.Addon = Addon;
Loading
Loading