Skip to content

Commit

Permalink
Merge pull request k8snetworkplumbingwg#119 from andreaskaris/upstrea…
Browse files Browse the repository at this point in the history
…m-sync-2023-03-22

Upstream sync 2023 03 29
  • Loading branch information
openshift-merge-robot authored Mar 30, 2023
2 parents 8ae1e41 + 1631544 commit f6c4d02
Show file tree
Hide file tree
Showing 161 changed files with 4,983 additions and 1,754 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
build:
strategy:
matrix:
go-version: [1.17.x, 1.18.x]
go-version: [1.19.x]
#goarch: [386, amd64, arm, ppc64le, arm64]
goarch: [amd64, arm64]
os: [ubuntu-latest] #, macos-latest, windows-latest]
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

Expand All @@ -54,3 +57,4 @@ jobs:
push: false
tags: ghcr.io/${{ github.repository }}:latest-arm64
file: Dockerfile.arm64
platforms: linux/arm64
23 changes: 22 additions & 1 deletion .github/workflows/image-push-master.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Image push for master
on:
on:
push:
branches:
- master
Expand Down Expand Up @@ -59,3 +59,24 @@ jobs:
push: true
tags: ghcr.io/${{ github.repository }}:latest-ocp
file: Dockerfile.openshift

push-arm64:
name: Image build/arm64
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build container image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest-arm64
file: Dockerfile.arm64
6 changes: 5 additions & 1 deletion .github/workflows/image-push-release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Image push release
on:
on:
push:
tags:
- v*
Expand Down Expand Up @@ -48,6 +48,9 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

Expand Down Expand Up @@ -75,3 +78,4 @@ jobs:
tags: |
${{ steps.docker_meta.outputs.tags }}-arm64
file: Dockerfile
platforms: linux/arm64
45 changes: 31 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ jobs:
test:
strategy:
matrix:
#go-version: [1.15.x, 1.16.x]
go-version: [1.17.x]
go-version: [1.19.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -17,49 +16,55 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Get all changed files excluding docs and README
id: changed-files
uses: tj-actions/changed-files@v35
with:
files_ignore: |
**/*.md
doc/*.{json,png,svg}
- name: Run Revive Action by building from repository
uses: morphy2k/[email protected]
uses: morphy2k/[email protected]
if: steps.changed-files.outputs.any_changed == 'true'
with:
exclude: "./vendor/..."
name: "Revive"

- name: Install kubebuilder tools
if: steps.changed-files.outputs.any_changed == 'true'
run: ./hack/install-kubebuilder-tools.sh

- name: Generate code
if: steps.changed-files.outputs.any_changed == 'true'
run: ./hack/generate-code.sh && hack/verify-codegen.sh

- name: Run go fmt
if: steps.changed-files.outputs.any_changed == 'true'
run: go fmt ./...
#run: diff -u <(echo -n) <(gofmt -d -s .)

- name: Run go vet
if: steps.changed-files.outputs.any_changed == 'true'
run: go vet --tags=test ./...

- name: Install static check
if: steps.changed-files.outputs.any_changed == 'true'
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Test
if: steps.changed-files.outputs.any_changed == 'true'
run: sudo PATH=${PATH}:./bin ./hack/test-go.sh

- name: Send coverage
if: steps.changed-files.outputs.any_changed == 'true'
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
flag-name: Go-${{ matrix.go }}
parallel: true
env:
KUBEBUILDER_ASSETS: "$(pwd)/bin"

# notifies that all test jobs are finished.
finish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true

e2e-test:
name: e2e test
runs-on: ubuntu-latest
Expand All @@ -69,21 +74,33 @@ jobs:
- name: Set up Go version
uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.19.x

- name: Checkout code into the Go module directory
uses: actions/checkout@v2

- name: Get all changed files excluding docs and README
id: changed-files
uses: tj-actions/changed-files@v35
with:
files_ignore: |
**/*.md
doc/*.{json,png,svg}
- name: Install requirements
if: steps.changed-files.outputs.any_changed == 'true'
run: sudo apt-get install nmap jq && ./hack/build-go.sh

- name: Get tools, setup KinD cluster test environment
if: steps.changed-files.outputs.any_changed == 'true'
run: source hack/e2e-get-test-tools.sh && ./hack/e2e-setup-kind-cluster.sh --number-of-compute $NUMBER_OF_COMPUTE_NODES

- name: Clear test-cache
if: steps.changed-files.outputs.any_changed == 'true'
run: go clean -testcache

- name: Execute golang based E2E tests
if: steps.changed-files.outputs.any_changed == 'true'
env:
KUBECONFIG: /home/runner/.kube/config
NUMBER_OF_THRASH_ITER: 20
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17
FROM golang:1.19
ADD . /usr/src/whereabouts
RUN mkdir -p $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts
WORKDIR $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17
FROM golang:1.19
ADD . /usr/src/whereabouts

ENV GOARCH "arm64"
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ IMAGE_NAME ?= whereabouts
IMAGE_REGISTRY ?= ghcr.io/k8snetworkplumbingwg
IMAGE_PULL_POLICY ?= Always
IMAGE_TAG ?= latest
COMPUTE_NODES ?= 2

OCI_BIN ?= docker

Expand All @@ -20,3 +21,6 @@ install-tools:

test: build install-tools
hack/test-go.sh

kind:
hack/e2e-setup-kind-cluster.sh -n $(COMPUTE_NODES)
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,67 @@ Run the build command from the `./hack` directory:
./hack/build-go.sh
```

## Running whereabouts CNI in a local kind cluster

You can start a kind cluster to run local changes with:
```
make kind
# or make kind COMPUTE_NODES=<desired number of worker nodes>
```

You can then create a NetworkAttachmentDefinition with:
```
cat <<'EOF' | kubectl apply -f -
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: whereabouts-conf
spec:
config: '{
"cniVersion": "0.3.0",
"name": "whereaboutsexample",
"type": "macvlan",
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "whereabouts",
"range": "192.168.2.225/28"
}
}'
EOF
```

Create a deployment that uses the NetworkAttachmentDefinition, for example:
```
cat <<'EOF' | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: netshoot-deployment
labels:
app: netshoot-deployment
spec:
replicas: 1
selector:
matchLabels:
app: netshoot-pod
template:
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: whereabouts-conf
labels:
app: netshoot-pod
spec:
containers:
- name: netshoot
image: nicolaka/netshoot
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
EOF
```

## Acknowledgements

Thanks big time to [Tomofumi Hayashi](https://github.com/s1061123), I utilized his [static CNI IPAM plugin](https://github.com/containernetworking/plugins/tree/master/plugins/ipam/static) as a basis for this project to give me a head start!
Expand Down
16 changes: 4 additions & 12 deletions cmd/controlloop/controlloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (

gocron "github.com/go-co-op/gocron"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
v1coreinformerfactory "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
Expand Down Expand Up @@ -132,15 +129,10 @@ func newPodController(stopChannel chan struct{}) (*controlloop.PodController, er
const noResyncPeriod = 0
ipPoolInformerFactory := wbinformers.NewSharedInformerFactory(wbClientSet, noResyncPeriod)
netAttachDefInformerFactory := nadinformers.NewSharedInformerFactory(nadK8sClientSet, noResyncPeriod)
podInformerFactory := v1coreinformerfactory.NewSharedInformerFactoryWithOptions(
k8sClientSet, noResyncPeriod, v1coreinformerfactory.WithTweakListOptions(
func(options *v1.ListOptions) {
const (
filterKey = "spec.nodeName"
hostnameEnvVariable = "HOSTNAME"
)
options.FieldSelector = fields.OneTermEqualSelector(filterKey, os.Getenv(hostnameEnvVariable)).String()
}))
podInformerFactory, err := controlloop.PodInformerFactory(k8sClientSet)
if err != nil {
return nil, err
}

controller := controlloop.NewPodController(
k8sClientSet,
Expand Down
Loading

0 comments on commit f6c4d02

Please sign in to comment.