-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multus: add support for the Multus daemonset
Multus will be installed by default but can be turned off by setting the DeployMultus property of the Cluster Network Operator object to 'false'.
- Loading branch information
Showing
11 changed files
with
326 additions
and
19 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains 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,10 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: multus | ||
labels: | ||
name: multus | ||
openshift.io/run-level: "0" | ||
annotations: | ||
openshift.io/node-selector: "" #override default node selector | ||
openshift.io/description: "Multus network plugin components" |
This file contains 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,65 @@ | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: multus | ||
rules: | ||
- apiGroups: ["apiextensions.k8s.io"] | ||
resources: | ||
- customresourcedefinitions | ||
- customresourcedefinitions/status | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- apiGroups: ["k8s.cni.cncf.io"] | ||
resources: ["*"] | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- apiGroups: [""] | ||
resources: | ||
- namespaces | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- apiGroups: [""] | ||
resources: | ||
- pods | ||
- pods/status | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- patch | ||
- update | ||
- apiGroups: [""] | ||
resources: | ||
- events | ||
verbs: | ||
- create | ||
- patch | ||
- update | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: multus | ||
namespace: multus | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: multus | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: multus | ||
subjects: | ||
- kind: ServiceAccount | ||
name: multus | ||
namespace: multus |
This file contains 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,58 @@ | ||
kind: DaemonSet | ||
apiVersion: apps/v1 | ||
metadata: | ||
name: multus | ||
namespace: multus | ||
annotations: | ||
kubernetes.io/description: | | ||
This daemon set launches the Multus networking component on each node. | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: multus | ||
updateStrategy: | ||
type: RollingUpdate | ||
template: | ||
metadata: | ||
labels: | ||
app: multus | ||
component: network | ||
type: infra | ||
openshift.io/component: network | ||
annotations: | ||
scheduler.alpha.kubernetes.io/critical-pod: '' | ||
spec: | ||
hostNetwork: true | ||
nodeSelector: | ||
beta.kubernetes.io/os: linux | ||
tolerations: | ||
- operator: Exists | ||
serviceAccountName: multus | ||
containers: | ||
- name: kube-multus | ||
image: {{.MultusImage}} | ||
command: ["/entrypoint.sh"] | ||
args: | ||
- "--multus-conf-file=auto" | ||
resources: | ||
requests: | ||
cpu: "100m" | ||
memory: "50Mi" | ||
limits: | ||
cpu: "100m" | ||
memory: "50Mi" | ||
securityContext: | ||
privileged: true | ||
volumeMounts: | ||
- name: cni | ||
mountPath: /host/etc/cni/net.d | ||
- name: cnibin | ||
mountPath: /host/opt/cni/bin | ||
volumes: | ||
- name: cni | ||
hostPath: | ||
path: /etc/kubernetes/cni/net.d | ||
- name: cnibin | ||
hostPath: | ||
path: /opt/cni/bin | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,25 @@ | ||
package network | ||
|
||
import ( | ||
"github.com/openshift/cluster-network-operator/pkg/render" | ||
"github.com/pkg/errors" | ||
uns "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// renderMultusConfig returns the manifests of Multus | ||
func renderMultusConfig(manifestDir string) ([]*uns.Unstructured, error) { | ||
objs := []*uns.Unstructured{} | ||
|
||
// render the manifests on disk | ||
data := render.MakeRenderData() | ||
data.Data["MultusImage"] = os.Getenv("MULTUS_IMAGE") | ||
|
||
manifests, err := render.RenderDir(filepath.Join(manifestDir, "network/multus"), &data) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to render multus manifests") | ||
} | ||
objs = append(objs, manifests...) | ||
return objs, nil | ||
} |
This file contains 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,90 @@ | ||
package network | ||
|
||
import ( | ||
"testing" | ||
|
||
netv1 "github.com/openshift/cluster-network-operator/pkg/apis/networkoperator/v1" | ||
"github.com/openshift/cluster-network-operator/pkg/apply" | ||
|
||
uns "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var MultusConfig = netv1.NetworkConfig{ | ||
Spec: netv1.NetworkConfigSpec{ | ||
ServiceNetwork: "172.30.0.0/16", | ||
ClusterNetworks: []netv1.ClusterNetwork{ | ||
{ | ||
CIDR: "10.128.0.0/15", | ||
HostSubnetLength: 9, | ||
}, | ||
}, | ||
DefaultNetwork: netv1.DefaultNetworkDefinition{ | ||
Type: netv1.NetworkTypeOpenShiftSDN, | ||
OpenShiftSDNConfig: &netv1.OpenShiftSDNConfig{ | ||
Mode: netv1.SDNModeNetworkPolicy, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// TestRenderMultus has some simple rendering tests | ||
func TestRenderMultus(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
|
||
crd := MultusConfig.DeepCopy() | ||
config := &crd.Spec | ||
off := false | ||
config.DeployMultus = &off | ||
FillDefaults(config, nil) | ||
|
||
// disable Multus | ||
objs, err := RenderMultus(config, manifestDir) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(objs).NotTo(ContainElement(HaveKubernetesID("DaemonSet", "multus", "multus"))) | ||
|
||
// enable Multus | ||
on := true | ||
config.DeployMultus = &on | ||
objs, err = RenderMultus(config, manifestDir) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(objs).To(ContainElement(HaveKubernetesID("DaemonSet", "multus", "multus"))) | ||
|
||
// It's important that the namespace is first | ||
g.Expect(len(objs)).To(Equal(5)) | ||
g.Expect(objs[0]).To(HaveKubernetesID("Namespace", "", "multus")) | ||
g.Expect(objs).To(ContainElement(HaveKubernetesID("ClusterRole", "", "multus"))) | ||
g.Expect(objs).To(ContainElement(HaveKubernetesID("ServiceAccount", "multus", "multus"))) | ||
g.Expect(objs).To(ContainElement(HaveKubernetesID("ClusterRoleBinding", "", "multus"))) | ||
g.Expect(objs).To(ContainElement(HaveKubernetesID("DaemonSet", "multus", "multus"))) | ||
|
||
// make sure all deployments are in the master | ||
for _, obj := range objs { | ||
if obj.GetKind() != "Deployment" { | ||
continue | ||
} | ||
|
||
sel, found, err := uns.NestedStringMap(obj.Object, "spec", "template", "spec", "nodeSelector") | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
g.Expect(found).To(BeTrue()) | ||
|
||
_, ok := sel["node-role.kubernetes.io/master"] | ||
g.Expect(ok).To(BeTrue()) | ||
} | ||
|
||
// Make sure every obj is reasonable: | ||
// - it is supported | ||
// - it reconciles to itself (steady state) | ||
for _, obj := range objs { | ||
g.Expect(apply.IsObjectSupported(obj)).NotTo(HaveOccurred()) | ||
cur := obj.DeepCopy() | ||
upd := obj.DeepCopy() | ||
|
||
err = apply.MergeObjectForUpdate(cur, upd) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
|
||
tweakMetaForCompare(cur) | ||
g.Expect(cur).To(Equal(upd)) | ||
} | ||
} |
Oops, something went wrong.