Skip to content

Commit 4d7eef6

Browse files
committed
Ensure the configure hook detects the API server coming up (#3009)
1 parent b971877 commit 4d7eef6

File tree

5 files changed

+98
-12
lines changed

5 files changed

+98
-12
lines changed

microk8s-resources/actions/common/utils.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,15 @@ fetch_as() {
825825

826826
############################# Strict functions ######################################
827827

828+
log_init () {
829+
echo `date +"[%m-%d %H:%M:%S]" start logging` > $SNAP_COMMON/var/log/microk8s.log
830+
}
831+
832+
log () {
833+
echo -n `date +"[%m-%d %H:%M:%S]"` >> $SNAP_COMMON/var/log/microk8s.log
834+
echo ": $@" >> $SNAP_COMMON/var/log/microk8s.log
835+
}
836+
828837
is_strict() {
829838
# Return 0 if we are in strict mode
830839
if cat $SNAP/meta/snap.yaml | grep confinement | grep -q strict
@@ -878,15 +887,14 @@ check_snap_interfaces() {
878887
then
879888
snapctl set-health blocked "You must connect ${missing[*]} before proceeding"
880889
exit 0
881-
else
882-
if [ $1 -gt 0 ]
883-
then
884-
snapctl start --enable ${SNAP_NAME}
885-
snapctl set-health okay
886-
fi
887890
fi
888891
}
889892

893+
enable_snap() {
894+
snapctl start --enable ${SNAP_NAME}
895+
snapctl set-health okay
896+
}
897+
890898
exit_if_not_root() {
891899
# test if we run with sudo
892900
if [ "$EUID" -ne 0 ]

snap/hooks/configure

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ fi
99

1010
source $SNAP/actions/common/utils.sh
1111

12-
check_snap_interfaces 0 # Check for interfaces but do not start until this script has run.
12+
ARCH="$($SNAP/bin/uname -m)"
13+
export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$ARCH-linux-gnu:$SNAP/usr/lib/$ARCH-linux-gnu"
14+
15+
check_snap_interfaces # Check for interfaces but do not start until this script has run.
1316

1417
need_api_restart=false
1518
need_proxy_restart=false
@@ -358,8 +361,6 @@ then
358361
chgrp snap_microk8s -R ${SNAP_COMMON}/addons ${SNAP_DATA}/credentials/ ${SNAP_DATA}/certs/ ${SNAP_DATA}/args/ ${SNAP_DATA}/var/lock/ ${SNAP_DATA}/var/kubernetes/backend/ ${SNAP_DATA}/tmp/ || true
359362
fi
360363

361-
try_copy_users_to_snap_microk8s
362-
363364
if ! [ -e "${SNAP_DATA}/opt/cni/bin/flanneld" ]
364365
then
365366
# cover situation where cilium was installed prior to this update
@@ -603,6 +604,8 @@ fi
603604
# Refresh calico if needed
604605
refresh_calico_if_needed
605606

607+
enable_snap
608+
606609
# Restart reconfigured services
607610
if ${need_api_restart} ||
608611
${need_proxy_restart} ||
@@ -654,4 +657,3 @@ then
654657
fi
655658
fi
656659

657-
check_snap_interfaces 1 # Check for interfaces and enable all services.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./configure

snap/snapcraft.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ slots:
5353
hooks:
5454
configure:
5555
plugs:
56+
- account-control
5657
- dot-kube
58+
- network
5759
install:
5860
plugs:
61+
- account-control
5962
- network-bind
6063
- firewall-control
6164
- network-control
@@ -69,93 +72,162 @@ hooks:
6972
connect-plug-network-control:
7073
plugs:
7174
- dot-kube
75+
- network
7276
- kernel-module-control
7377
- network-control
7478
disconnect-plug-network-control:
7579
plugs:
7680
- dot-kube
7781
- kernel-module-control
82+
- network
83+
- network-control
84+
connect-plug-account-control:
85+
plugs:
86+
- dot-kube
87+
- network
88+
- network-bind
7889
- network-control
7990
connect-plug-docker-privileged:
8091
plugs:
8192
- dot-kube
93+
- network
8294
- network-bind
95+
- network-control
8396
connect-plug-kubernetes-support:
8497
plugs:
8598
- dot-kube
99+
- network
86100
- network-bind
101+
- network-control
87102
connect-plug-k8s-kubelet:
88103
plugs:
89104
- dot-kube
105+
- network
90106
- network-bind
107+
- network-control
91108
connect-plug-k8s-kubeproxy:
92109
plugs:
93110
- dot-kube
111+
- network
94112
- network-bind
113+
- network-control
95114
connect-plug-dot-kube:
96115
plugs:
97116
- dot-kube
117+
- network
98118
- network-bind
119+
- network-control
99120
connect-plug-network:
100121
plugs:
101122
- dot-kube
123+
- network
102124
- network-bind
125+
- network-control
103126
connect-plug-network-bind:
104127
plugs:
105128
- dot-kube
129+
- network
106130
- network-bind
131+
- network-control
107132
connect-plug-network-observe:
108133
plugs:
109134
- dot-kube
135+
- network
110136
- network-bind
137+
- network-control
111138
connect-plug-firewall-control:
112139
plugs:
113140
- dot-kube
141+
- network
114142
- network-bind
143+
- network-control
115144
connect-plug-process-control:
116145
plugs:
117146
- dot-kube
147+
- network
118148
- network-bind
149+
- network-control
119150
connect-plug-kernel-module-observe:
120151
plugs:
121152
- dot-kube
153+
- network
122154
- network-bind
155+
- network-control
123156
connect-plug-mount-observe:
124157
plugs:
125158
- dot-kube
159+
- network
126160
- network-bind
161+
- network-control
127162
connect-plug-hardware-observe:
128163
plugs:
129164
- dot-kube
165+
- network
130166
- network-bind
167+
- network-control
131168
connect-plug-system-observe:
132169
plugs:
133170
- dot-kube
171+
- network
134172
- network-bind
173+
- network-control
135174
connect-plug-home:
136175
plugs:
137176
- dot-kube
177+
- network
138178
- network-bind
179+
- network-control
139180
connect-plug-opengl:
140181
plugs:
141182
- dot-kube
183+
- network
142184
- network-bind
185+
- network-control
143186
connect-plug-k8s-journald:
144187
plugs:
145188
- dot-kube
189+
- network
146190
- network-bind
191+
- network-control
147192
connect-plug-cifs-mount:
148193
plugs:
149194
- dot-kube
195+
- network
150196
- network-bind
151197
connect-plug-fuse-support:
152198
plugs:
153199
- dot-kube
200+
- network
154201
- network-bind
155202
connect-plug-kernel-crypto-api:
156203
plugs:
157204
- dot-kube
205+
- network
206+
- network-bind
207+
connect-plug-dot-config-helm:
208+
plugs:
209+
- dot-kube
210+
- network
211+
- network-bind
212+
- network-control
213+
connect-plug-log-observe:
214+
plugs:
215+
- dot-kube
216+
- network
158217
- network-bind
218+
- network-control
219+
connect-plug-login-session-observe:
220+
plugs:
221+
- dot-kube
222+
- network
223+
- network-bind
224+
- network-control
225+
connect-plug-home-read-all:
226+
plugs:
227+
- dot-kube
228+
- network
229+
- network-bind
230+
- network-control
159231

160232
apps:
161233
microk8s:
@@ -337,6 +409,7 @@ apps:
337409
plugs:
338410
- docker-unprivileged
339411
- dot-kube
412+
- network
340413
- home-read-all
341414
- firewall-control
342415
- network-bind

tests/connect-all-interfaces.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ fi
1010
for i in account-control \
1111
docker-privileged \
1212
kubernetes-support \
13-
k8s-journald k8s-kubelet \
13+
k8s-journald \
14+
k8s-kubelet \
1415
k8s-kubeproxy \
1516
dot-kube \
1617
network \
@@ -23,7 +24,8 @@ for i in account-control \
2324
mount-observe \
2425
hardware-observe \
2526
system-observe \
26-
home opengl \
27+
home \
28+
opengl \
2729
home-read-all \
2830
login-session-observe \
2931
log-observe \

0 commit comments

Comments
 (0)