Skip to content

Commit 13a3535

Browse files
committed
Strict patch
1 parent c7a7188 commit 13a3535

File tree

19 files changed

+860
-72
lines changed

19 files changed

+860
-72
lines changed

.github/workflows/build-snap.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
name: Build and test MicroK8s snap
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
pull_request:
8-
branches:
9-
- master
4+
- pull_request
5+
- push
106

117
jobs:
128
build:
@@ -60,7 +56,7 @@ jobs:
6056
path: build
6157
- name: Running upgrade path test
6258
run: |
63-
sudo -E UPGRADE_MICROK8S_FROM=latest/edge UPGRADE_MICROK8S_TO=$PWD/build/microk8s.snap pytest -s ./tests/test-upgrade-path.py
59+
sudo -E UPGRADE_MICROK8S_FROM=latest/edge/strict UPGRADE_MICROK8S_TO=$PWD/build/microk8s.snap pytest -s ./tests/test-upgrade-path.py
6460
6561
test-addons-core:
6662
name: Test core addons
@@ -83,13 +79,15 @@ jobs:
8379
with:
8480
name: microk8s.snap
8581
path: build
86-
- name: Running addons tests
82+
- name: Running addons tests in strict mode
8783
run: |
8884
set -x
89-
sudo snap install build/microk8s.snap --classic --dangerous
85+
sudo snap install build/microk8s.snap --dangerous
86+
sudo ./tests/connect-all-interfaces.sh
87+
sudo microk8s status --wait-ready --timeout 300
9088
./tests/smoke-test.sh
9189
export UNDER_TIME_PRESSURE="True"
92-
export SKIP_PROMETHEUS="False"
90+
export STRICT="yes"
9391
sudo -E bash -c "cd /var/snap/microk8s/common/addons/core/tests; pytest -s -ra test-addons.py"
9492
9593
test-addons-community:
@@ -117,7 +115,11 @@ jobs:
117115
run: |
118116
set -x
119117
sudo snap install build/microk8s.snap --classic --dangerous
118+
sudo ./tests/connect-all-interfaces.sh
119+
sudo microk8s status --wait-ready --timeout 300
120120
sudo microk8s enable community
121+
export UNDER_TIME_PRESSURE="True"
122+
export STRICT="yes"
121123
sudo -E bash -c "cd /var/snap/microk8s/common/addons/community/tests; pytest -s -ra test-addons.py"
122124
123125
test-addons-core-upgrade:
@@ -145,4 +147,5 @@ jobs:
145147
run: |
146148
set -x
147149
export UNDER_TIME_PRESSURE="True"
148-
sudo -E bash -c "UPGRADE_MICROK8S_FROM=latest/edge UPGRADE_MICROK8S_TO=$PWD/build/microk8s.snap pytest -s ./tests/test-upgrade.py"
150+
export STRICT="yes"
151+
sudo -E bash -c "UPGRADE_MICROK8S_FROM=latest/edge/strict UPGRADE_MICROK8S_TO=$PWD/build/microk8s.snap pytest -s ./tests/test-upgrade.py"

docs/build.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,16 @@ lxc file pull test-build/root/microk8s/microk8s_v1.9.6_amd64.snap .
8383
After copying it, you can install it with:
8484

8585
```shell
86-
snap install microk8s_*_amd64.snap --classic --dangerous
86+
sudo snap install microk8s_latest_amd64.snap --dangerous
8787
```
8888

89+
Finally, you need to connect the interfaces. To this end you can use the `connect-all-interfaces.sh` under the `tests` directory:
90+
91+
```shell
92+
sudo tests/connect-all-interfaces.sh
93+
```
94+
95+
8996
## Assembling the Calico CNI manifest
9097

9198
The calico CNI manifest can be found under `upgrade-scripts/000-switch-to-calico/resources/calico.yaml`.

microk8s-resources/wrappers/apiservice-kicker

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,26 @@ do
8484
# If no local-registry-hosting documentation has been installed,
8585
# install a help guide that points to the microk8s registry docs.
8686
#
87-
# Wait until the apiserver is up and is successfully responding to
88-
# namespace checks before we check for the registry configmap.
8987
if snapctl services microk8s.daemon-kubelite | grep active &> /dev/null
9088
then
89+
90+
# Wait until the apiserver is up and is successfully responding to
91+
# namespace checks before we check for the registry configmap and/or
92+
# apply the launch configuration.
9193
if [ $installed_registry_help -eq 0 ] &&
9294
"$SNAP/kubectl" "--kubeconfig=$SNAP_DATA/credentials/client.config" get namespace kube-public &> /dev/null
9395
then
9496
if ! "$SNAP/kubectl" "--kubeconfig=$SNAP_DATA/credentials/client.config" get configmap local-registry-hosting -n kube-public &> /dev/null
9597
then
9698
use_manifest registry/registry-help apply
9799
fi
98-
99100
installed_registry_help=1
100101
fi
102+
103+
if [ -e $SNAP_COMMON/etc/launcher/configuration/config.yaml ] &&
104+
$SNAP/usr/bin/python3 $SNAP/scripts/launcher.py $SNAP_COMMON/etc/launcher/configuration/config.yaml
105+
then
106+
mv $SNAP_COMMON/etc/launcher/configuration/config.yaml $SNAP_COMMON/etc/launcher/configuration/config.yaml.applied
107+
fi
101108
fi
102109
done

scripts/launcher.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env python
2+
3+
import click
4+
import yaml
5+
import os
6+
import sys
7+
8+
from subprocess import check_output
9+
from jsonschema import validate
10+
from abc import ABC, abstractmethod
11+
12+
13+
# The schema of the configuration files we can handle
14+
schema = """
15+
type: object
16+
properties:
17+
addons:
18+
description: "List of addons"
19+
type: array
20+
items:
21+
type: object
22+
properties:
23+
name:
24+
description: "Name of the addon"
25+
type: string
26+
status:
27+
description: "Should the addon be enabled or disabled"
28+
enum:
29+
- enable
30+
- disable
31+
args:
32+
description: "Arguments for the addon"
33+
type: array
34+
items:
35+
type: string
36+
required: ["name"]
37+
"""
38+
39+
40+
class Executor(ABC):
41+
@abstractmethod
42+
def Enable(self, addon: str, args: list):
43+
"""
44+
Enable an addon
45+
"""
46+
pass
47+
48+
@abstractmethod
49+
def Disable(self, addon: str, args: list):
50+
"""
51+
Disable an addon
52+
"""
53+
pass
54+
55+
56+
class EchoCommander(Executor):
57+
"""
58+
The class just prints out the commands to be executed. It is used for dry runs and debugging.
59+
"""
60+
61+
def Enable(self, addon: str, args: list):
62+
args_str = " ".join(args)
63+
click.echo(f"microk8s enable {addon} {args_str}")
64+
65+
def Disable(self, addon: str, args: list):
66+
args_str = " ".join(args)
67+
click.echo(f"microk8s disable {addon} {args_str}")
68+
69+
70+
class CliCommander(Executor):
71+
"""
72+
This Executor calls the microk8s wrappers to apply the configuration.
73+
"""
74+
75+
def __init__(self) -> None:
76+
super().__init__()
77+
self.enable_cmd = os.path.expandvars("$SNAP/microk8s-enable.wrapper")
78+
self.disable_cmd = os.path.expandvars("$SNAP/microk8s-disable.wrapper")
79+
80+
def Enable(self, addon: str, args: list):
81+
args_str = " ".join(args)
82+
click.echo(f"microk8s enable {addon} {args_str}")
83+
command = [self.enable_cmd, addon]
84+
if len(args) > 0:
85+
command = command + args
86+
output = check_output(command)
87+
click.echo(output)
88+
89+
def Disable(self, addon: str, args: list):
90+
args_str = " ".join(args)
91+
click.echo(f"microk8s enable {addon} {args_str}")
92+
command = [self.disable_cmd, addon]
93+
if len(args) > 0:
94+
command = command + args
95+
output = check_output(command)
96+
click.echo(output)
97+
98+
99+
@click.command("launcher")
100+
@click.argument("configuration")
101+
@click.option(
102+
"--dry",
103+
is_flag=True,
104+
required=False,
105+
default=False,
106+
help="Do nothing, just print the commands to be executed. (default: false)",
107+
)
108+
def launcher(configuration: str, dry):
109+
"""
110+
Setup MicroK8s based on the provided CONFIGURATION
111+
112+
CONFIGURATION is a yaml file
113+
"""
114+
115+
if not os.path.exists(configuration):
116+
sys.stderr.write("Please provide a yaml configuration file.\n")
117+
sys.exit(1)
118+
119+
with open(configuration, "r") as stream:
120+
try:
121+
cfg = yaml.safe_load(stream)
122+
except yaml.YAMLError as exc:
123+
sys.stderr.write(exc)
124+
sys.stderr.write("Please provide a valid yaml configuration file.\n")
125+
sys.exit(2)
126+
127+
validate(cfg, yaml.safe_load(schema))
128+
if dry:
129+
executor = EchoCommander()
130+
else:
131+
executor = CliCommander()
132+
133+
for addon in cfg["addons"]:
134+
args = []
135+
if "args" in addon.keys():
136+
args = addon["args"]
137+
if "status" in addon.keys() and addon["status"] == "disable":
138+
executor.Disable(addon["name"], args)
139+
else:
140+
executor.Enable(addon["name"], args)
141+
142+
143+
if __name__ == "__main__":
144+
launcher()

scripts/wrappers/common/cluster/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def try_set_file_permissions(file):
2929

3030
os.chmod(file, 0o660)
3131
try:
32-
shutil.chown(file, group="microk8s")
32+
shutil.chown(file, group="snap_microk8s")
3333
except LookupError:
3434
# not setting the group means only the current user can access the file
3535
pass
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
mkdir -p $SNAP_COMMON/etc/
6+
cp -R $SNAP/etc/launcher $SNAP_COMMON/etc/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
rm -rf $SNAP_COMMON/etc/launcher

0 commit comments

Comments
 (0)