Skip to content
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

Refactor #24

Merged
merged 26 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
27 changes: 10 additions & 17 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ on:
workflow_dispatch:

env:
GO_VERSION: "1.20.1"
K8S_VERSION: "v1.26.2"
GO_VERSION: "1.22.3"
K8S_VERSION: "v1.30.0"
KIND_VERSION: "v0.22.0"
KIND_CLUSTER_NAME: "kindnet"
REGISTRY: ghcr.io
IMAGE_NAME: aojea/kindnetd

jobs:
build:
name: build
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
Expand All @@ -44,17 +45,16 @@ jobs:

e2e:
name: e2e
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
timeout-minutes: 100
needs:
- build
strategy:
fail-fast: false
matrix:
ipFamily: ["ipv4", "ipv6", "dual"]
cniMode: ["ptp", "bridge"]
env:
JOB_NAME: "kindnetd-e2e-${{ matrix.ipFamily }}-${{ matrix.cniMode }}"
JOB_NAME: "kindnetd-e2e-${{ matrix.ipFamily }}"
IP_FAMILY: ${{ matrix.ipFamily }}
steps:
- name: Check out code
Expand All @@ -76,18 +76,18 @@ jobs:
# kubectl
curl -L https://dl.k8s.io/${{ env.K8S_VERSION }}/bin/linux/amd64/kubectl -o ${TMP_DIR}/kubectl
# kind
curl -Lo ${TMP_DIR}/kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64
curl -Lo ${TMP_DIR}/kind https://kind.sigs.k8s.io/dl/${{ env.KIND_VERSION }}/kind-linux-amd64
# Install
sudo cp ${TMP_DIR}/ginkgo /usr/local/bin/ginkgo
sudo cp ${TMP_DIR}/e2e.test /usr/local/bin/e2e.test
sudo cp ${TMP_DIR}/kubectl /usr/local/bin/kubectl
sudo cp ${TMP_DIR}/kind /usr/local/bin/kind
sudo chmod +x /usr/local/bin/*
# Create folder to store artifacts
mkdir -p _artifacts

- name: Create multi node cluster
run: |
# output_dir
mkdir -p _artifacts
# create cluster
cat <<EOF | /usr/local/bin/kind create cluster \
--name ${{ env.KIND_CLUSTER_NAME}} \
Expand Down Expand Up @@ -117,17 +117,10 @@ jobs:
/usr/local/bin/kind load docker-image ghcr.io/aojea/kindnetd:test --name ${{ env.KIND_CLUSTER_NAME}}

- name: install ptp plugin
if: ${{ matrix.cniMode == 'ptp' }}
run: |
sed -i s#aojea/kindnetd.*#aojea/kindnetd:test# install-kindnet.yaml
/usr/local/bin/kubectl apply -f ./install-kindnet.yaml

- name: install bridge plugin
if: ${{ matrix.cniMode == 'bridge' }}
run: |
sed -i s#aojea/kindnetd.*#aojea/kindnetd:test# install-kindnet-bridge.yaml
/usr/local/bin/kubectl apply -f ./install-kindnet-bridge.yaml

- name: Get Cluster status
run: |
# wait network is ready
Expand Down Expand Up @@ -203,7 +196,7 @@ jobs:

publish:
name: publish
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
timeout-minutes: 10
needs:
- e2e
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test

on: [push, pull_request]

env:
REGISTRY: ghcr.io
IMAGE_NAME: aojea/kindnetd
permissions: write-all

jobs:
test:
strategy:
fail-fast: false
matrix:
go-version: [1.22.x]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- run: make test
- run: make lint

15 changes: 15 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
run:
timeout: 30m
tests: false # TODO lint tests too

linters:
disable-all: true
enable:
- gocritic
- gosimple
- govet
- errcheck
- ineffassign
- staticcheck
- stylecheck
- typecheck
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

ARG GOARCH="amd64"
# STEP 1: Build kindnetd binary
FROM golang:1.20 AS builder
FROM golang:1.22 AS builder
# golang envs
ARG GOARCH="amd64"
ARG CNI_VERSION="v1.2.0"
ARG CNI_VERSION="v1.5.0"
ARG GOOS=linux
ENV CGO_ENABLED=0
ENV GO111MODULE="on"
Expand All @@ -36,14 +36,13 @@ RUN echo "Installing CNI binaries ..." \
&& tar -C /opt/cni/bin -xzf /tmp/cni.tgz \
&& rm -rf /tmp/cni.tgz \
&& find /opt/cni/bin -type f -not \( \
-iname host-local \
-o -iname ptp \
-o -iname bridge \
-o -iname portmap \
\) \
-delete
-iname host-local \
-o -iname ptp \
-o -iname portmap \
\) \
-delete
# STEP 2: Build small image
FROM registry.k8s.io/build-image/distroless-iptables:v0.2.1
FROM registry.k8s.io/build-image/distroless-iptables:v0.5.2
COPY --from=builder --chown=root:root /go/bin/kindnetd /bin/kindnetd
COPY --from=builder --chown=root:root /opt/cni/bin /opt/cni/bin
CMD ["/bin/kindnetd"]
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
REPO_ROOT:=${CURDIR}
OUT_DIR=$(REPO_ROOT)/bin
BINARY_NAME?=kindnet

# disable CGO by default for static binaries
CGO_ENABLED=0
export GOROOT GO111MODULE CGO_ENABLED


build:
go build -v -o "$(OUT_DIR)/$(BINARY_NAME)" ./cmd/kindnetd/

clean:
rm -rf "$(OUT_DIR)/"

test:
CGO_ENABLED=1 go test -v -race -count 1 ./...

# code linters
lint:
hack/lint.sh

update:
go mod tidy && go mod vendor

# get image name from directory we're building
IMAGE_NAME=kindnetd
# docker image registry, default to upstream
REGISTRY?=ghcr.io/aojea
# tag based on date-sha
TAG?=$(shell echo "$$(date +v%Y%m%d)-$$(git describe --always --dirty)")
# the full image tag
IMAGE?=$(REGISTRY)/$(IMAGE_NAME):$(TAG)

# required to enable buildx
export DOCKER_CLI_EXPERIMENTAL=enabled
image-build:
# docker buildx build --platform=${PLATFORMS} $(OUTPUT) --progress=$(PROGRESS) -t ${IMAGE} --pull $(EXTRA_BUILD_OPT) .
docker build . -t ${IMAGE}
22 changes: 5 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# Simple CNI plugin with IPv4, IPv6 and DualStack support
# Simple Kubernetes Networking Plugin with IPv4, IPv6 and DualStack support

The main goal of the project is to have a simple CNI plugin for Kubernetes with
The main goal of the project is to have a simple Kubernetes Networking Plugin plugin for Kubernetes with
IPv4 and IPv6 support that provides the [Cluster
Networking](https://kubernetes.io/docs/concepts/cluster-administration/networking/)

The idea was born because of the lack of IPv6 support in current CNI plugins
and because there are no automatic alternatives to create a multinode kubernetes
cluster with IPv6.

The plugin only works on "simple" network environments, when all the cluster nodes
belong to the same subnet.

Kindnet evolved adding new features, as an embedded ipmasq agent and nowadays,
Kindnet evolved adding new features, as an embedded ipmasq agent and nowadays,
is the default CNI plugin for [KIND](https://github.com/kubernetes-sigs/kind)

All the stable code was moved to the KIND project in-tree.
This repo is kept only for new features development and for experimenting
using it on "real" clusters.
All the original code was moved to the KIND project in-tree.
This repo is kept for new features development and for using it on "real" clusters.


## Kindnet components
Expand All @@ -25,7 +21,6 @@ It uses the following [standard CNI
plugins](https://github.com/containernetworking/plugins)

* `ptp`: creates a veth pair and adds the host and the container to it.
* `bridge`: creates a bridge, adds the host and the container to it.
* `host-local`: maintains a local database of allocated IPs. It uses the
`ipRanges` capability to provide dynamic configuration for the Pods subnets.
* `portmap`: An iptables-based portmapping plugin. Maps ports from the host's
Expand All @@ -44,12 +39,6 @@ Kindnet can be installed on your cluster using the manifest [install-kindnet.yam
`kubectl create -f
https://raw.githubusercontent.com/aojea/kindnet/master/install-kindnet.yaml`

By default, the `ptp` CNI plugin is used, but the `bridge` plugin can be selected by setting the environment
variable `CNI_BRIDGE` in the `kindnet-cni` container. You can use the following manifest directly:

`kubectl create -f
https://raw.githubusercontent.com/aojea/kindnet/master/install-kindnet-bridge.yaml`


Kindnet installation manifest has an init container that drop the CNI binaries in the folder `/opt/cni/bin/`, however, you can install them directly supressing the init container in the manifest and
following the next steps:
Expand All @@ -64,4 +53,3 @@ mkdir -p /opt/cni/bin
tar -C /opt/cni/bin -xzf /tmp/cni.tgz
rm -rf /tmp/cni.tgz
```

37 changes: 0 additions & 37 deletions build.sh

This file was deleted.

Loading
Loading