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

Add crio runtime #31

Merged
merged 3 commits into from
Oct 10, 2022
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ IMAGE_NAME ?= multus-dynamic-networks-controller
IMAGE_TAG ?= latest-amd64
NAMESPACE ?= kube-system

CRI_SOCKET_PATH ?= "/host/run/containerd/containerd.sock"
CONTAINERD_SOCKET_PATH ?= "/run/containerd/containerd.sock"
CRIO_SOCKET_PATH ?= "/run/crio/crio.sock"

.PHONY: manifests

Expand All @@ -22,7 +23,8 @@ img-build: build test
$(OCI_BIN) build -t ${IMAGE_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG} -f images/Dockerfile .

manifests:
IMAGE_REGISTRY=${IMAGE_REGISTRY} IMAGE_TAG=${IMAGE_TAG} CRI_SOCKET_PATH=${CRI_SOCKET_PATH} NAMESPACE=${NAMESPACE} hack/generate_manifests.sh
IMAGE_REGISTRY=${IMAGE_REGISTRY} IMAGE_TAG=${IMAGE_TAG} CRI_SOCKET_PATH=${CONTAINERD_SOCKET_PATH} NAMESPACE=${NAMESPACE} hack/generate_manifests.sh
CRIO_RUNTIME="yes" IMAGE_REGISTRY=${IMAGE_REGISTRY} IMAGE_TAG=${IMAGE_TAG} CRI_SOCKET_PATH=${CRIO_SOCKET_PATH} NAMESPACE=${NAMESPACE} hack/generate_manifests.sh

test:
$(GO) test -v ./pkg/...
Expand Down
11 changes: 8 additions & 3 deletions cmd/dynamic-networks-controller/networks-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/signal"
"time"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/maiqueb/multus-dynamic-networks-controller/pkg/controller"
"github.com/maiqueb/multus-dynamic-networks-controller/pkg/cri"
"github.com/maiqueb/multus-dynamic-networks-controller/pkg/cri/containerd"
"github.com/maiqueb/multus-dynamic-networks-controller/pkg/cri/crio"
"github.com/maiqueb/multus-dynamic-networks-controller/pkg/logging"
"github.com/maiqueb/multus-dynamic-networks-controller/pkg/multuscni"
)
Expand Down Expand Up @@ -89,7 +91,7 @@ func newController(stopChannel chan struct{}, configuration *config.Multus) (*co

containerRuntime, err := newContainerRuntime(configuration)
if err != nil {
return nil, fmt.Errorf("failed to create the CRI: %v", err)
return nil, fmt.Errorf("failed to create CRI type %s: %v", configuration.CriType, err)
}

podNetworksController, err := controller.NewPodNetworksController(
Expand Down Expand Up @@ -145,6 +147,9 @@ func handleSignals(stopChannel chan struct{}, signals ...os.Signal) {
}

func newContainerRuntime(configuration *config.Multus) (cri.ContainerRuntime, error) {
const withoutTimeout = 0
return containerd.NewContainerdRuntime(configuration.CriSocketPath, withoutTimeout)
const shortTimeout = 5 * time.Second
if configuration.CriType == cri.Crio {
return crio.NewRuntime(configuration.CriSocketPath, shortTimeout)
}
return containerd.NewContainerdRuntime(configuration.CriSocketPath, shortTimeout)
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ require (
github.com/onsi/ginkgo/v2 v2.1.3
github.com/onsi/gomega v1.17.0
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
google.golang.org/grpc v1.43.0
gopkg.in/k8snetworkplumbingwg/multus-cni.v3 v3.9.1
k8s.io/api v0.24.4
k8s.io/apimachinery v0.24.4
k8s.io/client-go v0.24.4
k8s.io/cri-api v0.23.1
k8s.io/klog/v2 v2.60.1
)

Expand Down Expand Up @@ -73,7 +75,6 @@ require (
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/grpc v1.43.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ k8s.io/code-generator v0.24.4/go.mod h1:dpVhs00hTuTdTY6jvVxvTFCk6gSMrtfRydbhZwHI
k8s.io/component-base v0.24.4/go.mod h1:sWxkgcMfbYHadw0OJ0N+vIscd14/nqSIM2veCdg843o=
k8s.io/component-helpers v0.24.4/go.mod h1:xAHlOKU8rAjLgXWJEsueWLR1LDMThbaPf2YvgKpSyQ8=
k8s.io/controller-manager v0.24.4/go.mod h1:1Tkmq5m8POXAv0JQr2BDSp95psbaXP2iYLvNftpn1Ds=
k8s.io/cri-api v0.24.4 h1:wBj7/kRuY38TPham9HIWlX0t42LiWX8COnYeWVZEeHg=
k8s.io/cri-api v0.24.4/go.mod h1:t3tImFtGeStN+ES69bQUX9sFg67ek38BM9YIJhMmuig=
k8s.io/csi-translation-lib v0.24.4/go.mod h1:Ov9lVXDEI3AGXYVO5TTK+o7nRa2GdlsLVvpo86Xy6x4=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
Expand Down
6 changes: 5 additions & 1 deletion hack/generate_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ templates_dir="$ROOT/templates"

for file in `ls $templates_dir/`; do
echo $file
j2 -e IMAGE_REGISTRY -e IMAGE_TAG -e CRI_SOCKET_PATH -e NAMESPACE ${templates_dir}/$file -o manifests/${file%.j2}
if [ -z $CRIO_RUNTIME ]; then
j2 -e IMAGE_REGISTRY -e IMAGE_TAG -e CRI_SOCKET_PATH -e NAMESPACE ${templates_dir}/$file -o "manifests/${file%.j2}"
else
j2 -e CRIO_RUNTIME -e IMAGE_REGISTRY -e IMAGE_TAG -e CRI_SOCKET_PATH -e NAMESPACE ${templates_dir}/$file -o "manifests/crio-${file%.j2}"
fi
done
unset IMAGE_REGISTRY
unset IMAGE_TAG
Expand Down
138 changes: 138 additions & 0 deletions manifests/crio-dynamic-networks-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: dynamic-networks-controller
rules:
- apiGroups: ["k8s.cni.cncf.io"]
resources:
- network-attachment-definitions
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- pods
- pods/status
verbs:
- get
- list
- update
- watch
- apiGroups:
- ""
- events.k8s.io
resources:
- events
verbs:
- create
- patch
- update
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: dynamic-networks-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: dynamic-networks-controller
subjects:
- kind: ServiceAccount
name: dynamic-networks-controller
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: dynamic-networks-controller
namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
name: dynamic-networks-controller-config
namespace: kube-system
labels:
tier: node
app: multus-dynamic-networks-controller
data:
dynamic-networks-config.json: |
{
"criType": "crio",
"criSocketPath": "/host/run/crio/crio.sock",
"multusSocketPath": "/host/run/multus/multus.sock"
}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: dynamic-networks-controller-ds
namespace: kube-system
labels:
tier: node
app: dynamic-networks-controller
name: dynamic-networks-controller
spec:
selector:
matchLabels:
name: dynamic-networks-controller
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
tier: node
app: dynamic-networks-controller
name: dynamic-networks-controller
spec:
tolerations:
- operator: Exists
effect: NoSchedule
- operator: Exists
effect: NoExecute
serviceAccountName: dynamic-networks-controller
containers:
- name: dynamic-networks-controller
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: ghcr.io/maiqueb/multus-dynamic-networks-controller:latest-amd64
command: [ "/dynamic-networks-controller" ]
args:
- "-config=/etc/dynamic-networks-controller/dynamic-networks-config.json"
- "-v=5"
resources:
requests:
cpu: "100m"
memory: "50Mi"
securityContext:
privileged: true
volumeMounts:
- name: dynamic-networks-controller-config-dir
mountPath: /etc/dynamic-networks-controller/
readOnly: true
- name: multus-server-socket
mountPath: /host/run/multus/multus.sock
- name: cri-socket
mountPath: /host/run/crio/crio.sock
terminationGracePeriodSeconds: 10
volumes:
- name: dynamic-networks-controller-config-dir
configMap:
name: dynamic-networks-controller-config
items:
- key: dynamic-networks-config.json
path: dynamic-networks-config.json
- name: multus-server-socket
hostPath:
path: /run/multus/multus.sock
type: Socket
- name: cri-socket
hostPath:
path: /run/crio/crio.sock
type: Socket
4 changes: 2 additions & 2 deletions manifests/dynamic-networks-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ spec:
readOnly: true
- name: multus-server-socket
mountPath: /host/run/multus/multus.sock
- name: containerd-socket
- name: cri-socket
mountPath: /host/run/containerd/containerd.sock
terminationGracePeriodSeconds: 10
volumes:
Expand All @@ -131,7 +131,7 @@ spec:
hostPath:
path: /run/multus/multus.sock
type: Socket
- name: containerd-socket
- name: cri-socket
hostPath:
path: /run/containerd/containerd.sock
type: Socket
Loading