Skip to content

Commit a8ea194

Browse files
authored
Merge pull request #15450 from AkihiroSuda/ci-rootless
CI: add functional_docker_rootless_containerd_ubuntu
2 parents 0b9cda9 + 6ab61b7 commit a8ea194

File tree

7 files changed

+194
-3
lines changed

7 files changed

+194
-3
lines changed

.github/workflows/pr.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,125 @@ jobs:
290290
if [ "$numPass" -lt 36 ];then echo "*** Failed to pass at least 36 ! ***";exit 2;fi
291291
if [ "$numPass" -eq 0 ];then echo "*** Passed! ***";exit 0;fi
292292
293+
functional_docker_rootless_containerd_ubuntu:
294+
permissions:
295+
contents: none
296+
needs: [build_minikube]
297+
env:
298+
TIME_ELAPSED: time
299+
JOB_NAME: "functional_docker_rootless_containerd_ubuntu"
300+
GOPOGH_RESULT: ""
301+
SHELL: "/bin/bash" # To prevent https://github.com/kubernetes/minikube/issues/6643
302+
DEBIAN_FRONTEND: noninteractive
303+
# ubuntu-22.04 is needed for cgroup v2
304+
runs-on: ubuntu-22.04
305+
steps:
306+
- name: Install kubectl
307+
shell: bash
308+
run: |
309+
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
310+
sudo install kubectl /usr/local/bin/kubectl
311+
kubectl version --client=true
312+
# https://rootlesscontaine.rs/getting-started/common/cgroup2/
313+
- name: Set up cgroup v2 delegation
314+
run: |
315+
sudo mkdir -p /etc/systemd/system/[email protected]
316+
cat <<EOF | sudo tee /etc/systemd/system/[email protected]/delegate.conf
317+
[Service]
318+
Delegate=cpu cpuset io memory pids
319+
EOF
320+
sudo systemctl daemon-reload
321+
- name: Set up Rootless Docker
322+
run: |
323+
sudo apt-get remove moby-engine-*
324+
curl https://get.docker.com | sudo sh
325+
dockerd-rootless-setuptool.sh install -f
326+
docker context use rootless
327+
- name: Docker Info
328+
shell: bash
329+
run: |
330+
echo "--------------------------"
331+
docker version || true
332+
echo "--------------------------"
333+
docker info || true
334+
echo "--------------------------"
335+
docker system df || true
336+
echo "--------------------------"
337+
docker system info --format='{{json .}}'|| true
338+
echo "--------------------------"
339+
docker ps || true
340+
echo "--------------------------"
341+
- uses: actions/setup-go@d0a58c1c4d2b25278816e339b944508c875f3613
342+
with:
343+
go-version: ${{env.GO_VERSION}}
344+
- name: Install gopogh
345+
346+
shell: bash
347+
run: |
348+
curl -LO https://github.com/medyagh/gopogh/releases/download/v0.13.0/gopogh-linux-amd64
349+
sudo install gopogh-linux-amd64 /usr/local/bin/gopogh
350+
- name: Download Binaries
351+
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7
352+
with:
353+
name: minikube_binaries
354+
path: minikube_binaries
355+
- name: Run Integration Test
356+
continue-on-error: false
357+
# bash {0} to allow test to continue to next step. in case of
358+
shell: bash {0}
359+
run: |
360+
cd minikube_binaries
361+
mkdir -p report
362+
mkdir -p testhome
363+
chmod a+x e2e-*
364+
chmod a+x minikube-*
365+
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
366+
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
367+
MINIKUBE_HOME=$(pwd)/testhome ./minikube-linux-amd64 delete --all --purge
368+
START_TIME=$(date -u +%s)
369+
KUBECONFIG=$(pwd)/testhome/kubeconfig MINIKUBE_HOME=$(pwd)/testhome ./e2e-linux-amd64 -minikube-start-args="--vm-driver=docker --rootless --container-runtime=containerd" -test.run TestFunctional -test.timeout=30m -test.v -timeout-multiplier=1.5 -binary=./minikube-linux-amd64 2>&1 | tee ./report/testout.txt
370+
END_TIME=$(date -u +%s)
371+
TIME_ELAPSED=$(($END_TIME-$START_TIME))
372+
min=$((${TIME_ELAPSED}/60))
373+
sec=$((${TIME_ELAPSED}%60))
374+
TIME_ELAPSED="${min} min $sec seconds "
375+
echo "TIME_ELAPSED=${TIME_ELAPSED}" >> $GITHUB_ENV
376+
- name: Generate HTML Report
377+
shell: bash
378+
run: |
379+
cd minikube_binaries
380+
export PATH=${PATH}:`go env GOPATH`/bin
381+
go tool test2json -t < ./report/testout.txt > ./report/testout.json || true
382+
STAT=$(gopogh -in ./report/testout.json -out_html ./report/testout.html -out_summary ./report/testout_summary.json -name "${JOB_NAME} ${GITHUB_REF}" -repo "${GITHUB_REPOSITORY}" -details "${GITHUB_SHA}") || true
383+
echo status: ${STAT}
384+
FailNum=$(echo $STAT | jq '.NumberOfFail')
385+
TestsNum=$(echo $STAT | jq '.NumberOfTests')
386+
GOPOGH_RESULT="${JOB_NAME} : completed with ${FailNum} / ${TestsNum} failures in ${TIME_ELAPSED}"
387+
echo "GOPOGH_RESULT=${GOPOGH_RESULT}" >> $GITHUB_ENV
388+
echo 'STAT<<EOF' >> $GITHUB_ENV
389+
echo "${STAT}" >> $GITHUB_ENV
390+
echo 'EOF' >> $GITHUB_ENV
391+
- uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb
392+
with:
393+
name: functional_docker_rootless_containerd_ubuntu
394+
path: minikube_binaries/report
395+
- name: The End Result functional_docker_rootless_containerd_ubuntu
396+
shell: bash
397+
run: |
398+
echo ${GOPOGH_RESULT}
399+
numFail=$(echo $STAT | jq '.NumberOfFail')
400+
numPass=$(echo $STAT | jq '.NumberOfPass')
401+
echo "*******************${numPass} Passes :) *******************"
402+
echo $STAT | jq '.PassedTests' || true
403+
echo "*******************************************************"
404+
echo "---------------- ${numFail} Failures :( ----------------------------"
405+
echo $STAT | jq '.FailedTests' || true
406+
echo "-------------------------------------------------------"
407+
if [ "$numFail" -gt 0 ];then echo "*** $numFail Failed ***";exit 2;fi
408+
if [ "$numPass" -eq 0 ];then echo "*** 0 Passed! ***";exit 2;fi
409+
if [ "$numPass" -lt 36 ];then echo "*** Failed to pass at least 36 ! ***";exit 2;fi
410+
if [ "$numPass" -eq 0 ];then echo "*** Passed! ***";exit 0;fi
411+
293412
functional_podman_ubuntu:
294413
permissions:
295414
contents: none
@@ -611,6 +730,7 @@ jobs:
611730
[
612731
functional_docker_ubuntu,
613732
functional_docker_containerd_ubuntu,
733+
functional_docker_rootless_containerd_ubuntu,
614734
functional_podman_ubuntu,
615735
functional_virtualbox_macos,
616736
functional_baremetal_ubuntu20_04,
@@ -627,6 +747,7 @@ jobs:
627747
ls -lah
628748
cp -r ./functional_docker_ubuntu ./all_reports/
629749
cp -r ./functional_docker_containerd_ubuntu ./all_reports/
750+
cp -r ./functional_docker_rootless_containerd_ubuntu ./all_reports/
630751
cp -r ./functional_podman_ubuntu ./all_reports/
631752
cp -r ./functional_virtualbox_macos ./all_reports/
632753
cp -r ./functional_baremetal_ubuntu20_04 ./all_reports/

cmd/minikube/main.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"crypto/sha1"
2222
"encoding/hex"
23+
"errors"
2324
"flag"
2425
"fmt"
2526
"log"
@@ -51,6 +52,10 @@ import (
5152
"k8s.io/minikube/pkg/minikube/machine"
5253
"k8s.io/minikube/pkg/minikube/out"
5354
_ "k8s.io/minikube/pkg/provision"
55+
56+
dconfig "github.com/docker/cli/cli/config"
57+
ddocker "github.com/docker/cli/cli/context/docker"
58+
dstore "github.com/docker/cli/cli/context/store"
5459
)
5560

5661
const minikubeEnableProfile = "MINIKUBE_ENABLE_PROFILING"
@@ -68,6 +73,8 @@ func main() {
6873
bridgeLogMessages()
6974
defer klog.Flush()
7075

76+
propagateDockerContextToEnv()
77+
7178
// Don't parse flags when running as kubectl
7279
_, callingCmd := filepath.Split(os.Args[0])
7380
callingCmd = strings.TrimSuffix(callingCmd, ".exe")
@@ -247,3 +254,54 @@ func setLastStartFlags() {
247254
klog.Warningf("Unable to set default flag value for log_file: %v", err)
248255
}
249256
}
257+
258+
// propagateDockerContextToEnv propagates the current context in ~/.docker/config.json to $DOCKER_HOST,
259+
// so that google/go-containerregistry can pick it up.
260+
func propagateDockerContextToEnv() {
261+
if os.Getenv("DOCKER_HOST") != "" {
262+
// Already explicitly set
263+
return
264+
}
265+
currentContext := os.Getenv("DOCKER_CONTEXT")
266+
if currentContext == "" {
267+
dockerConfigDir := dconfig.Dir()
268+
if _, err := os.Stat(dockerConfigDir); err != nil {
269+
if !errors.Is(err, os.ErrNotExist) {
270+
klog.Warning(err)
271+
}
272+
return
273+
}
274+
cf, err := dconfig.Load(dockerConfigDir)
275+
if err != nil {
276+
klog.Warningf("Unable to load the current Docker config from %q", dockerConfigDir)
277+
return
278+
}
279+
currentContext = cf.CurrentContext
280+
}
281+
if currentContext == "" {
282+
return
283+
}
284+
storeConfig := dstore.NewConfig(
285+
func() interface{} { return &ddocker.EndpointMeta{} },
286+
dstore.EndpointTypeGetter(ddocker.DockerEndpoint, func() interface{} { return &ddocker.EndpointMeta{} }),
287+
)
288+
st := dstore.New(dconfig.ContextStoreDir(), storeConfig)
289+
md, err := st.GetMetadata(currentContext)
290+
if err != nil {
291+
klog.Warningf("Unable to resolve the current Docker CLI context %q: %v", currentContext, err)
292+
return
293+
}
294+
dockerEP, ok := md.Endpoints[ddocker.DockerEndpoint]
295+
if !ok {
296+
// No warning (the context is not for Docker)
297+
return
298+
}
299+
dockerEPMeta, ok := dockerEP.(ddocker.EndpointMeta)
300+
if !ok {
301+
klog.Warningf("expected docker.EndpointMeta, got %T", dockerEP)
302+
return
303+
}
304+
if dockerEPMeta.Host != "" {
305+
os.Setenv("DOCKER_HOST", dockerEPMeta.Host)
306+
}
307+
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ require (
9696
require (
9797
github.com/Xuanwo/go-locale v1.1.0
9898
github.com/blang/semver v3.5.1+incompatible
99+
github.com/docker/cli v20.10.20+incompatible
99100
github.com/docker/go-connections v0.4.0
100101
github.com/google/go-github/v43 v43.0.0
101102
github.com/opencontainers/runc v1.1.4
@@ -128,13 +129,13 @@ require (
128129
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
129130
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
130131
github.com/davecgh/go-spew v1.1.1 // indirect
131-
github.com/docker/cli v20.10.20+incompatible // indirect
132132
github.com/docker/distribution v2.8.1+incompatible // indirect
133133
github.com/docker/docker-credential-helpers v0.7.0 // indirect
134134
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
135135
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
136136
github.com/fatih/color v1.13.0 // indirect
137137
github.com/fsnotify/fsnotify v1.6.0 // indirect
138+
github.com/fvbommel/sortorder v1.0.1 // indirect
138139
github.com/go-fonts/liberation v0.2.0 // indirect
139140
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 // indirect
140141
github.com/go-logr/logr v1.2.3 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
411411
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
412412
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
413413
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
414+
github.com/fvbommel/sortorder v1.0.1 h1:dSnXLt4mJYH25uDDGa3biZNQsozaUWDSWeKJ0qqFfzE=
415+
github.com/fvbommel/sortorder v1.0.1/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
414416
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
415417
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
416418
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=

pkg/minikube/image/cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func saveToTarFile(iname, rawDest string, overwrite bool) error {
131131

132132
img, cname, err := retrieveImage(ref, iname)
133133
if err != nil {
134+
klog.V(2).ErrorS(err, "an error while retrieving the image")
134135
return errCacheImageDoesntExist
135136
}
136137
if img == nil {

test/integration/functional_test_mount_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { // no
5252
if HyperVDriver() {
5353
t.Skip("skipping: mount broken on hyperv: https://github.com/kubernetes/minikube/issues/5029")
5454
}
55+
if RootlessDriver() {
56+
t.Skip("skipping: rootless driver does not support mount (because 9p is not mountable inside UserNS)")
57+
}
5558

5659
if runtime.GOOS == "windows" {
5760
t.Skip("skipping: mount broken on windows: https://github.com/kubernetes/minikube/issues/8303")

test/integration/main_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func PodmanDriver() bool {
149149
return strings.Contains(*startArgs, "--driver=podman") || strings.Contains(*startArgs, "--vm-driver=podman")
150150
}
151151

152+
// Rootless returns whether or not this test is using the rootless KIC driver
153+
func RootlessDriver() bool {
154+
return strings.Contains(*startArgs, "--rootless")
155+
}
156+
152157
// KicDriver returns whether or not this test is using the docker or podman driver
153158
func KicDriver() bool {
154159
return DockerDriver() || PodmanDriver()
@@ -171,9 +176,9 @@ func arm64Platform() bool {
171176
}
172177

173178
// NeedsPortForward returns access to endpoints with this driver needs port forwarding
174-
// (Docker on non-Linux platforms requires ports to be forwarded to 127.0.0.1)
179+
// (Docker on non-Linux platforms and rootless KIC requires ports to be forwarded to 127.0.0.1)
175180
func NeedsPortForward() bool {
176-
return KicDriver() && (runtime.GOOS == "windows" || runtime.GOOS == "darwin") || detect.IsMicrosoftWSL()
181+
return KicDriver() && (runtime.GOOS == "windows" || runtime.GOOS == "darwin") || detect.IsMicrosoftWSL() || RootlessDriver()
177182
}
178183

179184
// CanCleanup returns if cleanup is allowed

0 commit comments

Comments
 (0)