Skip to content

Commit

Permalink
Strict patch
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsakalozos committed Sep 28, 2022
1 parent c7a7188 commit 13a3535
Show file tree
Hide file tree
Showing 19 changed files with 860 additions and 72 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/build-snap.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
name: Build and test MicroK8s snap

on:
push:
branches:
- master
pull_request:
branches:
- master
- pull_request
- push

jobs:
build:
Expand Down Expand Up @@ -60,7 +56,7 @@ jobs:
path: build
- name: Running upgrade path test
run: |
sudo -E UPGRADE_MICROK8S_FROM=latest/edge UPGRADE_MICROK8S_TO=$PWD/build/microk8s.snap pytest -s ./tests/test-upgrade-path.py
sudo -E UPGRADE_MICROK8S_FROM=latest/edge/strict UPGRADE_MICROK8S_TO=$PWD/build/microk8s.snap pytest -s ./tests/test-upgrade-path.py
test-addons-core:
name: Test core addons
Expand All @@ -83,13 +79,15 @@ jobs:
with:
name: microk8s.snap
path: build
- name: Running addons tests
- name: Running addons tests in strict mode
run: |
set -x
sudo snap install build/microk8s.snap --classic --dangerous
sudo snap install build/microk8s.snap --dangerous
sudo ./tests/connect-all-interfaces.sh
sudo microk8s status --wait-ready --timeout 300
./tests/smoke-test.sh
export UNDER_TIME_PRESSURE="True"
export SKIP_PROMETHEUS="False"
export STRICT="yes"
sudo -E bash -c "cd /var/snap/microk8s/common/addons/core/tests; pytest -s -ra test-addons.py"
test-addons-community:
Expand Down Expand Up @@ -117,7 +115,11 @@ jobs:
run: |
set -x
sudo snap install build/microk8s.snap --classic --dangerous
sudo ./tests/connect-all-interfaces.sh
sudo microk8s status --wait-ready --timeout 300
sudo microk8s enable community
export UNDER_TIME_PRESSURE="True"
export STRICT="yes"
sudo -E bash -c "cd /var/snap/microk8s/common/addons/community/tests; pytest -s -ra test-addons.py"
test-addons-core-upgrade:
Expand Down Expand Up @@ -145,4 +147,5 @@ jobs:
run: |
set -x
export UNDER_TIME_PRESSURE="True"
sudo -E bash -c "UPGRADE_MICROK8S_FROM=latest/edge UPGRADE_MICROK8S_TO=$PWD/build/microk8s.snap pytest -s ./tests/test-upgrade.py"
export STRICT="yes"
sudo -E bash -c "UPGRADE_MICROK8S_FROM=latest/edge/strict UPGRADE_MICROK8S_TO=$PWD/build/microk8s.snap pytest -s ./tests/test-upgrade.py"
9 changes: 8 additions & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ lxc file pull test-build/root/microk8s/microk8s_v1.9.6_amd64.snap .
After copying it, you can install it with:

```shell
snap install microk8s_*_amd64.snap --classic --dangerous
sudo snap install microk8s_latest_amd64.snap --dangerous
```

Finally, you need to connect the interfaces. To this end you can use the `connect-all-interfaces.sh` under the `tests` directory:

```shell
sudo tests/connect-all-interfaces.sh
```


## Assembling the Calico CNI manifest

The calico CNI manifest can be found under `upgrade-scripts/000-switch-to-calico/resources/calico.yaml`.
Expand Down
13 changes: 10 additions & 3 deletions microk8s-resources/wrappers/apiservice-kicker
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,26 @@ do
# If no local-registry-hosting documentation has been installed,
# install a help guide that points to the microk8s registry docs.
#
# Wait until the apiserver is up and is successfully responding to
# namespace checks before we check for the registry configmap.
if snapctl services microk8s.daemon-kubelite | grep active &> /dev/null
then

# Wait until the apiserver is up and is successfully responding to
# namespace checks before we check for the registry configmap and/or
# apply the launch configuration.
if [ $installed_registry_help -eq 0 ] &&
"$SNAP/kubectl" "--kubeconfig=$SNAP_DATA/credentials/client.config" get namespace kube-public &> /dev/null
then
if ! "$SNAP/kubectl" "--kubeconfig=$SNAP_DATA/credentials/client.config" get configmap local-registry-hosting -n kube-public &> /dev/null
then
use_manifest registry/registry-help apply
fi

installed_registry_help=1
fi

if [ -e $SNAP_COMMON/etc/launcher/configuration/config.yaml ] &&
$SNAP/usr/bin/python3 $SNAP/scripts/launcher.py $SNAP_COMMON/etc/launcher/configuration/config.yaml
then
mv $SNAP_COMMON/etc/launcher/configuration/config.yaml $SNAP_COMMON/etc/launcher/configuration/config.yaml.applied
fi
fi
done
144 changes: 144 additions & 0 deletions scripts/launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/usr/bin/env python

import click
import yaml
import os
import sys

from subprocess import check_output
from jsonschema import validate
from abc import ABC, abstractmethod


# The schema of the configuration files we can handle
schema = """
type: object
properties:
addons:
description: "List of addons"
type: array
items:
type: object
properties:
name:
description: "Name of the addon"
type: string
status:
description: "Should the addon be enabled or disabled"
enum:
- enable
- disable
args:
description: "Arguments for the addon"
type: array
items:
type: string
required: ["name"]
"""


class Executor(ABC):
@abstractmethod
def Enable(self, addon: str, args: list):
"""
Enable an addon
"""
pass

@abstractmethod
def Disable(self, addon: str, args: list):
"""
Disable an addon
"""
pass


class EchoCommander(Executor):
"""
The class just prints out the commands to be executed. It is used for dry runs and debugging.
"""

def Enable(self, addon: str, args: list):
args_str = " ".join(args)
click.echo(f"microk8s enable {addon} {args_str}")

def Disable(self, addon: str, args: list):
args_str = " ".join(args)
click.echo(f"microk8s disable {addon} {args_str}")


class CliCommander(Executor):
"""
This Executor calls the microk8s wrappers to apply the configuration.
"""

def __init__(self) -> None:
super().__init__()
self.enable_cmd = os.path.expandvars("$SNAP/microk8s-enable.wrapper")
self.disable_cmd = os.path.expandvars("$SNAP/microk8s-disable.wrapper")

def Enable(self, addon: str, args: list):
args_str = " ".join(args)
click.echo(f"microk8s enable {addon} {args_str}")
command = [self.enable_cmd, addon]
if len(args) > 0:
command = command + args
output = check_output(command)
click.echo(output)

def Disable(self, addon: str, args: list):
args_str = " ".join(args)
click.echo(f"microk8s enable {addon} {args_str}")
command = [self.disable_cmd, addon]
if len(args) > 0:
command = command + args
output = check_output(command)
click.echo(output)


@click.command("launcher")
@click.argument("configuration")
@click.option(
"--dry",
is_flag=True,
required=False,
default=False,
help="Do nothing, just print the commands to be executed. (default: false)",
)
def launcher(configuration: str, dry):
"""
Setup MicroK8s based on the provided CONFIGURATION
CONFIGURATION is a yaml file
"""

if not os.path.exists(configuration):
sys.stderr.write("Please provide a yaml configuration file.\n")
sys.exit(1)

with open(configuration, "r") as stream:
try:
cfg = yaml.safe_load(stream)
except yaml.YAMLError as exc:
sys.stderr.write(exc)
sys.stderr.write("Please provide a valid yaml configuration file.\n")
sys.exit(2)

validate(cfg, yaml.safe_load(schema))
if dry:
executor = EchoCommander()
else:
executor = CliCommander()

for addon in cfg["addons"]:
args = []
if "args" in addon.keys():
args = addon["args"]
if "status" in addon.keys() and addon["status"] == "disable":
executor.Disable(addon["name"], args)
else:
executor.Enable(addon["name"], args)


if __name__ == "__main__":
launcher()
2 changes: 1 addition & 1 deletion scripts/wrappers/common/cluster/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def try_set_file_permissions(file):

os.chmod(file, 0o660)
try:
shutil.chown(file, group="microk8s")
shutil.chown(file, group="snap_microk8s")
except LookupError:
# not setting the group means only the current user can access the file
pass
Expand Down
6 changes: 6 additions & 0 deletions snap/hooks/connect-plug-configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eux

mkdir -p $SNAP_COMMON/etc/
cp -R $SNAP/etc/launcher $SNAP_COMMON/etc/
5 changes: 5 additions & 0 deletions snap/hooks/disconnect-plug-configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eux

rm -rf $SNAP_COMMON/etc/launcher
Loading

0 comments on commit 13a3535

Please sign in to comment.