-
Notifications
You must be signed in to change notification settings - Fork 35
PoC spike for k8s-based linkerd-cni testing #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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…
bd20d59
removed testutil, dockerized cni installer tests now pass
b00fc23
moving internal to pkg/linkerd-, removing Dockerfile until fixed, cha…
c212c91
gofmt install-cni_test.go
0ad053f
go mod updates
839b80b
adding pkg to Docker image
8bb3c2f
updating dev from v32 to v35 for go
35e5d12
moving back to old dev image
976c910
use dev:v32-go for go lint workflow
95620d6
fixing linter complaints
9d8b1d9
fixing linter complaints
9613bc6
turning off noisy lint #1
c5b6130
turning off noisy lint #2
b439f84
turning off noisy lint #3
0990cf0
turning off noisy lint #4
e85e73d
turning off noisy lint #5
9010489
turning off noisy lint #6
2e46623
adding in Dockerfile, just rules for building, and a workflow for tes…
48be4dc
remember to setup docker
9e3e7f6
remember to setup docker-qemu
8c550e3
where is docker?
189abac
back to a named ubuntu version, removing devcontainer
69d3f39
we need just
634f6f2
WIP import of CNI plugin integration test environment. does not run d…
aa569a9
Resolved merge conflicts
3df15ca
rewriting just rules to match new rules
a3e9801
bumping dev version, renaming smoke test
8644b70
WIP for running smoke tests
cf20b3c
go workflow fix
0b20651
also rid ourselves of ioutil in this branch
6e784ce
adding a second, passing test
50d13a0
let's run the test in CI
68a06f5
name the test properly for CI to run it
215ef8b
made the installer integration tests more in-line with the other inte…
b1d9b6b
cni-plugin integration test workflow
8aead66
breaking up steps, renaming test
d1ca77a
just
00352b7
bringing changes from linkerd2 over
15a4f63
tests running within cni-plugin context
56a5da5
create service account and don't delete so we can inspect
58c073c
fix namespaces, use matei's k3d/k3s mountPaths in the hopes that CNI …
8a40a69
WIP for debugging why CNI won't run in my own pods despite everything…
ffd1e04
fixing merge conflicts, updating test runner to use linkerd-cni
b999f5a
adding whitespace, fixing comment, removing unneeded variable
1875ead
fixing some small things
a13af2d
improving Dockerfile, going back to edge for linkerd-cni
52327f9
cleaned up Dockerfile
e084f54
using --link for 50% size improvement
ab1ed29
cleanup unusued functions, run network-validator before test suite
cd3286d
Merge branch 'main' into stevej/cni-plugin-build-workflow
2b9d540
remove qemu setup, add comment about log level
1b477c2
add wiring to see cni-net-dir and check for kubeconfig
52b7212
checking that linkerd-cni is the last plugin in the conflist
960759a
renaming smoke_test to flannel
29f9a65
rename files, update justfile
6015555
name a test file _test so the test runner will run my test
e30cd69
renaming to flannel
880404d
Merge branch 'main' into stevej/cni-plugin-build-workflow
e79b7a1
remove hardcoded filename
6215df3
clarified comment
46e7ebe
fixed merge conflict error
8ad4fbf
fix log levels
2686a61
fix a log level
a74b0ab
run test on all files in ./cni-plugin
367d112
hcomment explaining why there's no ENTRYPOINT
4cb47d5
use a map instead of an array for simplicity
0c1b31c
abstract which integration test subdirectory gets used, add internal …
c426066
go.yml is already running these tests are there no integration tests …
9712052
breaking up a line
aef27c6
renaming SUBDIRECTORY to SCENARIO and renaming a run just target to f…
96e2825
merge main
cc78037
better error handling of the cleanup() function, print more diagnosti…
edf6db5
add error handling for describe ds and logs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| } | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: {} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.