Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
906bd63
modifying import paths and making a temporary copy of testutil/annota…
Nov 22, 2022
bd20d59
removed testutil, dockerized cni installer tests now pass
Nov 23, 2022
b00fc23
moving internal to pkg/linkerd-, removing Dockerfile until fixed, cha…
Dec 1, 2022
c212c91
gofmt install-cni_test.go
Dec 1, 2022
0ad053f
go mod updates
Dec 1, 2022
839b80b
adding pkg to Docker image
Dec 1, 2022
8bb3c2f
updating dev from v32 to v35 for go
Dec 1, 2022
35e5d12
moving back to old dev image
Dec 1, 2022
976c910
use dev:v32-go for go lint workflow
Dec 2, 2022
95620d6
fixing linter complaints
Dec 2, 2022
9d8b1d9
fixing linter complaints
Dec 2, 2022
9613bc6
turning off noisy lint #1
Dec 2, 2022
c5b6130
turning off noisy lint #2
Dec 2, 2022
b439f84
turning off noisy lint #3
Dec 3, 2022
0990cf0
turning off noisy lint #4
Dec 3, 2022
e85e73d
turning off noisy lint #5
Dec 3, 2022
9010489
turning off noisy lint #6
Dec 3, 2022
2e46623
adding in Dockerfile, just rules for building, and a workflow for tes…
Dec 5, 2022
48be4dc
remember to setup docker
Dec 7, 2022
9e3e7f6
remember to setup docker-qemu
Dec 7, 2022
8c550e3
where is docker?
Dec 7, 2022
189abac
back to a named ubuntu version, removing devcontainer
Dec 7, 2022
69d3f39
we need just
Dec 7, 2022
634f6f2
WIP import of CNI plugin integration test environment. does not run d…
Dec 13, 2022
aa569a9
Resolved merge conflicts
Dec 13, 2022
3df15ca
rewriting just rules to match new rules
Dec 13, 2022
a3e9801
bumping dev version, renaming smoke test
Dec 14, 2022
8644b70
WIP for running smoke tests
Dec 15, 2022
cf20b3c
go workflow fix
Dec 15, 2022
0b20651
also rid ourselves of ioutil in this branch
Dec 15, 2022
6e784ce
adding a second, passing test
Dec 15, 2022
50d13a0
let's run the test in CI
Dec 15, 2022
68a06f5
name the test properly for CI to run it
Dec 15, 2022
215ef8b
made the installer integration tests more in-line with the other inte…
Dec 15, 2022
b1d9b6b
cni-plugin integration test workflow
Dec 15, 2022
8aead66
breaking up steps, renaming test
Dec 15, 2022
d1ca77a
just
Dec 15, 2022
00352b7
bringing changes from linkerd2 over
Dec 15, 2022
15a4f63
tests running within cni-plugin context
Dec 15, 2022
56a5da5
create service account and don't delete so we can inspect
Dec 29, 2022
58c073c
fix namespaces, use matei's k3d/k3s mountPaths in the hopes that CNI …
Dec 29, 2022
8a40a69
WIP for debugging why CNI won't run in my own pods despite everything…
Jan 3, 2023
ffd1e04
fixing merge conflicts, updating test runner to use linkerd-cni
Jan 4, 2023
b999f5a
adding whitespace, fixing comment, removing unneeded variable
Jan 4, 2023
1875ead
fixing some small things
Jan 5, 2023
a13af2d
improving Dockerfile, going back to edge for linkerd-cni
Jan 5, 2023
52327f9
cleaned up Dockerfile
Jan 10, 2023
e084f54
using --link for 50% size improvement
Jan 10, 2023
ab1ed29
cleanup unusued functions, run network-validator before test suite
Jan 10, 2023
cd3286d
Merge branch 'main' into stevej/cni-plugin-build-workflow
Jan 10, 2023
2b9d540
remove qemu setup, add comment about log level
Jan 10, 2023
1b477c2
add wiring to see cni-net-dir and check for kubeconfig
Jan 10, 2023
52b7212
checking that linkerd-cni is the last plugin in the conflist
Jan 11, 2023
960759a
renaming smoke_test to flannel
Jan 11, 2023
29f9a65
rename files, update justfile
Jan 11, 2023
6015555
name a test file _test so the test runner will run my test
Jan 11, 2023
e30cd69
renaming to flannel
Jan 11, 2023
880404d
Merge branch 'main' into stevej/cni-plugin-build-workflow
Jan 11, 2023
e79b7a1
remove hardcoded filename
Jan 11, 2023
6215df3
clarified comment
Jan 11, 2023
46e7ebe
fixed merge conflict error
Jan 11, 2023
8ad4fbf
fix log levels
Jan 11, 2023
2686a61
fix a log level
Jan 11, 2023
a74b0ab
run test on all files in ./cni-plugin
Jan 12, 2023
367d112
hcomment explaining why there's no ENTRYPOINT
Jan 12, 2023
4cb47d5
use a map instead of an array for simplicity
Jan 12, 2023
0c1b31c
abstract which integration test subdirectory gets used, add internal …
Jan 13, 2023
c426066
go.yml is already running these tests are there no integration tests …
Jan 13, 2023
9712052
breaking up a line
Jan 13, 2023
aef27c6
renaming SUBDIRECTORY to SCENARIO and renaming a run just target to f…
Jan 14, 2023
96e2825
merge main
Jan 14, 2023
cc78037
better error handling of the cleanup() function, print more diagnosti…
Jan 17, 2023
edf6db5
add error handling for describe ds and logs
Jan 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/cni-plugin-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: cni-plugin-integration

on:
workflow_dispatch:
pull_request:
paths:
- Dockerfile-cni-plugin
- cni-plugin/integration/flannel/Dockerfile-tester
- cni-plugin/integration/run.sh
- cni-plugin/**

jobs:
integration:
timeout-minutes: 15
runs-on: ubuntu-20.04
steps:
- uses: linkerd/dev/actions/setup-tools@v38
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- run: just k3d-create
- run: just build-cni-plugin-image
- run: just build-cni-plugin-test-image
- run: just cni-plugin-test-integration
18 changes: 18 additions & 0 deletions cni-plugin/integration/Dockerfile-tester
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1.4
#
# A single container holds all of the test code and it must be
# specified in `run.sh` which tests you want to run.
#
# There's no ENTRYPOINT as integration test runners will require
# two things:
# 1) a specific k3d cluster configured with CNI
# 2) a test suite (e.g. `flannel.go`) runs with a configured CNI plugin.

FROM golang:1.18-alpine AS build
ENV GOCACHE=/tmp/
WORKDIR /src
COPY --link go.mod go.sum .
COPY --link cni-plugin cni-plugin
COPY --link internal internal
COPY --link proxy-init proxy-init
RUN go mod tidy && go mod download
91 changes: 91 additions & 0 deletions cni-plugin/integration/flannel/flannel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package flannel

import (
"encoding/json"
"flag"
"fmt"
"os"
"testing"
)

const (
ConfigDirectory = "/var/lib/rancher/k3s/agent/etc/cni/net.d"
FlannelConflist = "10-flannel.conflist"
)

// Given a directory, return a map of filename->struct{}
func files(directory string) (map[string]struct{}, error) {
files, err := os.ReadDir(directory)
if err != nil {
return nil, err
}

fileNames := make(map[string]struct{}, len(files))
for _, f := range files {
fileNames[f.Name()] = struct{}{}
}

return fileNames, nil
}

func TestMain(m *testing.M) {
runTests := flag.Bool("integration-tests", false, "must be provided to run the integration tests")
flag.Parse()

if !*runTests {
fmt.Fprintln(os.Stderr, "integration tests not enabled: enable with -integration-tests")
os.Exit(0)
}

os.Exit(m.Run())
}

// TODO(stevej): this could be a test helper as we want it to be true for every CNI integration
func TestLinkerdIsLastCNIPlugin(t *testing.T) {
t.Parallel()

t.Run("succeeds when linkerd-cni is the last plugin", func(t *testing.T) {
if _, err := os.Stat(ConfigDirectory); os.IsNotExist(err) {
t.Fatalf("Directory does not exist. Check if volume mount exists: %s", ConfigDirectory)
}

filenames, err := files(ConfigDirectory)

if err != nil {
t.Fatalf("unable to read files from directory %s due to error: %e", ConfigDirectory, err)
}

if len(filenames) == 0 {
t.Fatalf("no files found in %s", ConfigDirectory)
}

if len(filenames) > 2 {
t.Fatalf("too many files found in %s: %s ", ConfigDirectory, filenames)
}

if _, ok := filenames[FlannelConflist]; !ok {
t.Fatalf("filenames does not contain %s, instead it contains: %s", FlannelConflist, filenames)
}

conflistFile, err := os.ReadFile(ConfigDirectory + "/" + FlannelConflist)
if err != nil {
t.Fatalf("could not read %s: %e", FlannelConflist, err)
}

var conflist map[string]any
err = json.Unmarshal(conflistFile, &conflist)
if err != nil {
t.Fatalf("unmarshaling conflist json failed: %e", err)
}

if conflist["cniVersion"] != "1.0.0" {
t.Fatalf("expected cniVersion 1.0.0, instead saw %s", conflistFile)
}

plugins := conflist["plugins"].([]interface{})
lastPlugin := plugins[len(plugins)-1].(map[string]any)
if lastPlugin["name"] != "linkerd-cni" {
t.Fatalf("linkerd-cni was not last in the plugins list")
}
})
}
177 changes: 177 additions & 0 deletions cni-plugin/integration/manifests/linkerd-cni.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
##
## Everything below here is generated from the output `linkerd install-cni`
## and modified with the test image of the cni-plugin.
##
## `linkerd install-cni \
## --dest-cni-net-dir "/var/lib/rancher/k3s/agent/etc/cni/net.d/" \
## --dest-cni-bin-dir "/bin"`
## These flags are meant to enable cni to work properly with k3d/k3s.
## Also the log level is set to debug to simplify development.
##
## DO NOT hand edit.
##
kind: Namespace
apiVersion: v1
metadata:
name: linkerd-cni
labels:
linkerd.io/cni-resource: "true"
config.linkerd.io/admission-webhooks: disabled
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: linkerd-cni
namespace: linkerd-cni
labels:
linkerd.io/cni-resource: "true"
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: linkerd-cni
labels:
linkerd.io/cni-resource: "true"
rules:
- apiGroups: [""]
resources: ["pods", "nodes", "namespaces", "services"]
verbs: ["list", "get", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: linkerd-cni
labels:
linkerd.io/cni-resource: "true"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: linkerd-cni
subjects:
- kind: ServiceAccount
name: linkerd-cni
namespace: linkerd-cni
---
kind: ConfigMap
apiVersion: v1
metadata:
name: linkerd-cni-config
namespace: linkerd-cni
labels:
linkerd.io/cni-resource: "true"
data:
dest_cni_net_dir: "/var/lib/rancher/k3s/agent/etc/cni/net.d"
dest_cni_bin_dir: "/bin"
# The CNI network configuration to install on each node. The special
# values in this config will be automatically populated.
cni_network_config: |-
{
"name": "linkerd-cni",
"type": "linkerd-cni",
"log_level": "debug",
"policy": {
"type": "k8s",
"k8s_api_root": "https://__KUBERNETES_SERVICE_HOST__:__KUBERNETES_SERVICE_PORT__",
"k8s_auth_token": "__SERVICEACCOUNT_TOKEN__"
},
"kubernetes": {
"kubeconfig": "__KUBECONFIG_FILEPATH__"
},
"linkerd": {
"incoming-proxy-port": 4143,
"outgoing-proxy-port": 4140,
"proxy-uid": 2102,
"ports-to-redirect": [],
"inbound-ports-to-ignore": ["4191","4190"],
"simulate": false,
"use-wait-flag": false
}
}
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
name: linkerd-cni
namespace: linkerd-cni
labels:
k8s-app: linkerd-cni
linkerd.io/cni-resource: "true"
annotations:
linkerd.io/created-by: linkerd/cli edge-22.12.1
spec:
selector:
matchLabels:
k8s-app: linkerd-cni
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
template:
metadata:
labels:
k8s-app: linkerd-cni
annotations:
linkerd.io/created-by: linkerd/cli edge-22.12.1
linkerd.io/cni-resource: "true"
linkerd.io/inject: disabled
spec:
tolerations:
- operator: Exists
nodeSelector:
kubernetes.io/os: linux
hostNetwork: true
serviceAccountName: linkerd-cni
containers:
# This container installs the linkerd CNI binaries
# and CNI network config file on each node. The install
# script copies the files into place and then sleeps so
# that Kubernetes doesn't keep trying to restart it.
- name: install-cni
#image: test.l5d.io/linkerd/cni-plugin:test
image: cr.l5d.io/linkerd/cni-plugin:edge-22.12.1
env:
- name: DEST_CNI_NET_DIR
valueFrom:
configMapKeyRef:
name: linkerd-cni-config
key: dest_cni_net_dir
- name: DEST_CNI_BIN_DIR
valueFrom:
configMapKeyRef:
name: linkerd-cni-config
key: dest_cni_bin_dir
- name: CNI_NETWORK_CONFIG
valueFrom:
configMapKeyRef:
name: linkerd-cni-config
key: cni_network_config
- name: SLEEP
value: "true"
lifecycle:
# In some edge-cases this helps ensure that cleanup() is called in the container's script
# https://github.com/linkerd/linkerd2/issues/2355
preStop:
exec:
command:
- /bin/sh
- -c
- kill -15 1; sleep 15s
volumeMounts:
- mountPath: /host/bin
name: cni-bin-dir
- mountPath: /host/var/lib/rancher/k3s/agent/etc/cni/net.d
name: cni-net-dir
- mountPath: /tmp
name: linkerd-tmp-dir
securityContext:
readOnlyRootFilesystem: true
privileged:
volumes:
- name: cni-bin-dir
hostPath:
path: /bin
- name: cni-net-dir
hostPath:
path: /var/lib/rancher/k3s/agent/etc/cni/net.d
- name: linkerd-tmp-dir
emptyDir: {}
Loading