Skip to content

Commit c5787c8

Browse files
petrutlucian94berkayoz
authored andcommitted
fix: Always refresh the default hooks during upgrades (#5009)
(cherry picked from commit 0f715db)
1 parent e5b6ab4 commit c5787c8

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

.github/workflows/build-snap.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
jobs:
77
build:
88
name: Create snap package
9-
runs-on: ubuntu-22.04
9+
runs-on: ubuntu-latest
1010

1111
steps:
1212
- name: Checking out repo
@@ -15,7 +15,9 @@ jobs:
1515
run: |
1616
sudo lxd init --auto
1717
sudo usermod --append --groups lxd $USER
18-
sg lxd -c 'lxc version'
18+
# `newgrp` does not work in GitHub Actions; use `sudo --user` instead
19+
# See https://github.com/actions/runner-images/issues/9932#issuecomment-2573170305
20+
sudo --user "$USER" --preserve-env --preserve-env=PATH -- env -- lxc version
1921
# Docker sets iptables rules that interfere with LXD or K8s.
2022
# https://documentation.ubuntu.com/lxd/en/latest/howto/network_bridge_firewalld/#prevent-connectivity-issues-with-lxd-and-docker
2123
- name: Apply Docker iptables workaround
@@ -30,7 +32,7 @@ jobs:
3032
sudo snap refresh snapd --channel=latest/stable
3133
- name: Build snap
3234
run: |
33-
sg lxd -c 'snapcraft --use-lxd'
35+
sudo --user "$USER" --preserve-env --preserve-env=PATH -- env -- snapcraft --use-lxd
3436
sudo mv microk8s*.snap microk8s.snap
3537
- name: Uploading snap
3638
uses: actions/upload-artifact@v4
@@ -40,7 +42,7 @@ jobs:
4042

4143
test-upgrade:
4244
name: Upgrade path test
43-
runs-on: ubuntu-22.04
45+
runs-on: ubuntu-latest
4446
needs: build
4547
timeout-minutes: 30
4648
steps:
@@ -54,7 +56,7 @@ jobs:
5456
5557
test-addons-core:
5658
name: Test core addons
57-
runs-on: ubuntu-22.04
59+
runs-on: ubuntu-latest
5860
needs: build
5961
timeout-minutes: 30
6062
steps:
@@ -77,9 +79,9 @@ jobs:
7779
7880
test-addons-community:
7981
name: Test community addons
80-
runs-on: ubuntu-22.04
82+
runs-on: ubuntu-latest
8183
needs: build
82-
timeout-minutes: 30
84+
timeout-minutes: 60
8385
steps:
8486
- name: Checking out repo
8587
uses: actions/checkout@v4
@@ -99,7 +101,7 @@ jobs:
99101
100102
test-addons-core-upgrade:
101103
name: Test core addons upgrade
102-
runs-on: ubuntu-22.04
104+
runs-on: ubuntu-latest
103105
needs: build
104106
timeout-minutes: 30
105107
steps:
@@ -117,7 +119,7 @@ jobs:
117119
118120
test-cluster-agent:
119121
name: Cluster agent health check
120-
runs-on: ubuntu-22.04
122+
runs-on: ubuntu-latest
121123
needs: build
122124
timeout-minutes: 30
123125
steps:
@@ -134,7 +136,7 @@ jobs:
134136
135137
test-airgap:
136138
name: Test airgap installation
137-
runs-on: ubuntu-22.04
139+
runs-on: ubuntu-latest
138140
needs: build
139141
timeout-minutes: 30
140142
steps:
@@ -147,14 +149,16 @@ jobs:
147149
sudo lxd init --auto
148150
sudo lxc network set lxdbr0 ipv6.address=none
149151
sudo usermod --append --groups lxd $USER
150-
sg lxd -c 'lxc version'
152+
# `newgrp` does not work in GitHub Actions; use `sudo --user` instead
153+
# See https://github.com/actions/runner-images/issues/9932#issuecomment-2573170305
154+
sudo --user "$USER" --preserve-env --preserve-env=PATH -- env -- lxc version
151155
- name: Run airgap tests
152156
run: |
153157
sudo -E bash -x -c "./tests/libs/airgap.sh --distro ubuntu:22.04 --channel $PWD/build/microk8s.snap"
154158
155159
security-scan:
156160
name: Security scan
157-
runs-on: ubuntu-22.04
161+
runs-on: ubuntu-latest
158162
needs: build
159163
timeout-minutes: 30
160164
steps:

snap/hooks/configure

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,13 @@ then
220220

221221
fi
222222

223-
# Install default-hooks
224-
if ! [ -d "${SNAP_COMMON}/hooks" ]
225-
then
226-
cp -r --preserve=mode ${SNAP}/default-hooks ${SNAP_COMMON}/hooks
227-
fi
228-
229-
# (1.28 -> 1.29) Install 10-pods-restart hook if missing
230-
if ! [ -e "${SNAP_COMMON}/hooks/reconcile.d/10-pods-restart" ]; then
231-
cp -r --preserve=mode "${SNAP}/default-hooks/reconcile.d/10-pods-restart" "${SNAP_COMMON}/hooks/reconcile.d/10-pods-restart"
232-
fi
223+
# Install default-hooks.
224+
#
225+
# Updated hooks may contain fixes, so we'll always replace existing files.
226+
# Custom hooks are expected to use separate files so that they won't get
227+
# overwritten during upgrades.
228+
mkdir -p ${SNAP_COMMON}/hooks
229+
cp -r --preserve=mode ${SNAP}/default-hooks/* ${SNAP_COMMON}/hooks/
233230

234231
# Make sure the server certificate includes the IP we are using
235232
if [ "$(produce_certs)" == "1" ]

tests/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ def wait_for_pod_state(
100100
deadline = datetime.datetime.now() + datetime.timedelta(seconds=timeout_insec)
101101
while True:
102102
if datetime.datetime.now() > deadline:
103-
raise TimeoutError(
104-
"Pod {} not in {} after {} seconds.".format(pod, desired_state, timeout_insec)
105-
)
103+
all_res = kubectl("get all -A")
104+
err_msg = f"Pod {pod} not in {desired_state} after {timeout_insec} seconds, "
105+
err_msg += f"label: {label}, desired_reason: {desired_reason}.\n"
106+
print(err_msg)
107+
print(f"kubectl get all -A\n{all_res}\n")
108+
raise TimeoutError(err_msg)
106109
cmd = "po {} -n {}".format(pod, namespace)
107110
if label:
108111
cmd += " -l {}".format(label)

tests/validators.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def validate_storage():
5757
)
5858
kubectl(cmd)
5959

60-
wait_for_pod_state("", "kube-system", "running", label="k8s-app=hostpath-provisioner")
60+
wait_for_pod_state(
61+
"", "kube-system", "running", label="k8s-app=hostpath-provisioner"
62+
)
6163
manifest = TEMPLATES / "pvc.yaml"
6264
kubectl("apply -f {}".format(manifest))
6365
wait_for_pod_state("hostpath-test-pod", "default", "running")
@@ -101,7 +103,9 @@ def common_ingress():
101103
while attempt >= 0:
102104
try:
103105
resp = requests.get("http://microbot.127.0.0.1.nip.io/")
104-
if resp.status_code == 200 and "microbot.png" in resp.content.decode("utf-8"):
106+
if resp.status_code == 200 and "microbot.png" in resp.content.decode(
107+
"utf-8"
108+
):
105109
service_ok = True
106110
break
107111
except requests.RequestException:
@@ -118,9 +122,13 @@ def validate_ingress():
118122
daemonset = kubectl("get ds")
119123
if "nginx-ingress-microk8s-controller" in daemonset:
120124
wait_for_pod_state("", "default", "running", label="app=default-http-backend")
121-
wait_for_pod_state("", "default", "running", label="name=nginx-ingress-microk8s")
125+
wait_for_pod_state(
126+
"", "default", "running", label="name=nginx-ingress-microk8s"
127+
)
122128
else:
123-
wait_for_pod_state("", "ingress", "running", label="name=nginx-ingress-microk8s")
129+
wait_for_pod_state(
130+
"", "ingress", "running", label="name=nginx-ingress-microk8s"
131+
)
124132

125133
manifest = TEMPLATES / "ingress.yaml"
126134
update_yaml_with_arch(manifest)

0 commit comments

Comments
 (0)