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

Use hostNetwork for sriov-cni daemonset #149

Merged
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
25 changes: 25 additions & 0 deletions bindata/manifests/daemon/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ spec:
serviceAccountName: sriov-network-config-daemon
priorityClassName: "system-node-critical"
containers:
- name: sriov-cni
image: {{.SRIOVCNIImage}}
securityContext:
privileged: true
resources:
requests:
cpu: 10m
memory: 10Mi
volumeMounts:
- name: cnibin
mountPath: /host/opt/cni/bin
- name: sriov-infiniband-cni
image: {{.SRIOVInfiniBandCNIImage}}
securityContext:
privileged: true
resources:
requests:
cpu: 10m
memory: 10Mi
volumeMounts:
- name: cnibin
mountPath: /host/opt/cni/bin
- name: sriov-network-config-daemon
image: {{.Image}}
command:
Expand Down Expand Up @@ -67,3 +89,6 @@ spec:
- name: host
hostPath:
path: /
- name: cnibin
hostPath:
path: {{.CNIBinPath}}
20 changes: 0 additions & 20 deletions bindata/manifests/plugins/002-rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sriov-cni
namespace: {{.Namespace}}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sriov-device-plugin
namespace: {{.Namespace}}
Expand All @@ -28,20 +22,6 @@ rules:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: sriov-cni
namespace: {{.Namespace}}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: sriov-plugin
subjects:
- kind: ServiceAccount
name: sriov-cni
namespace: {{.Namespace}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: sriov-device-plugin
namespace: {{.Namespace}}
Expand Down
60 changes: 0 additions & 60 deletions bindata/manifests/plugins/sriov-cni.yaml

This file was deleted.

64 changes: 54 additions & 10 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
errs "github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -315,21 +316,12 @@ func (r *SriovNetworkNodePolicyReconciler) syncPluginDaemonObjs(dp *sriovnetwork
logger := r.Log.WithName("syncPluginDaemonObjs")
logger.Info("Start to sync sriov daemons objects")

// render RawCNIConfig manifests
// render plugin manifests
data := render.MakeRenderData()
data.Data["Namespace"] = namespace
data.Data["SRIOVCNIImage"] = os.Getenv("SRIOV_CNI_IMAGE")
data.Data["SRIOVInfiniBandCNIImage"] = os.Getenv("SRIOV_INFINIBAND_CNI_IMAGE")
data.Data["SRIOVDevicePluginImage"] = os.Getenv("SRIOV_DEVICE_PLUGIN_IMAGE")
data.Data["ReleaseVersion"] = os.Getenv("RELEASEVERSION")
data.Data["ResourcePrefix"] = os.Getenv("RESOURCE_PREFIX")
envCniBinPath := os.Getenv("SRIOV_CNI_BIN_PATH")
if envCniBinPath == "" {
data.Data["CNIBinPath"] = "/var/lib/cni/bin"
} else {
logger.Info("New cni bin found", "CNIBinPath", envCniBinPath)
data.Data["CNIBinPath"] = envCniBinPath
}

objs, err := renderDsForCR(PLUGIN_PATH, &data)
if err != nil {
Expand Down Expand Up @@ -377,6 +369,58 @@ func (r *SriovNetworkNodePolicyReconciler) syncPluginDaemonObjs(dp *sriovnetwork
return err
}
}

// Sriov-cni container has been moved to sriov-network-config-daemon DaemonSet.
// Delete stale sriov-cni manifests. Revert this change once sriov-cni daemonSet
// is deprecated.
err = r.deleteSriovCniManifests()
if err != nil {
return err
}

return nil
}

func (r *SriovNetworkNodePolicyReconciler) deleteSriovCniManifests() error {
ds := &appsv1.DaemonSet{}
err := r.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: "sriov-cni"}, ds)
if err != nil {
if !errors.IsNotFound(err) {
return err
}
} else {
err = r.Delete(context.TODO(), ds)
if err != nil {
return err
}
}

rb := &rbacv1.RoleBinding{}
err = r.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: "sriov-cni"}, rb)
if err != nil {
if !errors.IsNotFound(err) {
return err
}
} else {
err = r.Delete(context.TODO(), rb)
if err != nil {
return err
}
}

sa := &corev1.ServiceAccount{}
err = r.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: "sriov-cni"}, sa)
if err != nil {
if !errors.IsNotFound(err) {
return err
}
} else {
err = r.Delete(context.TODO(), sa)
if err != nil {
return err
}
}

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions controllers/sriovoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,17 @@ func (r *SriovOperatorConfigReconciler) syncConfigDaemonSet(dc *sriovnetworkv1.S
data := render.MakeRenderData()
data.Data["Image"] = os.Getenv("SRIOV_NETWORK_CONFIG_DAEMON_IMAGE")
data.Data["Namespace"] = namespace
data.Data["SRIOVCNIImage"] = os.Getenv("SRIOV_CNI_IMAGE")
data.Data["SRIOVInfiniBandCNIImage"] = os.Getenv("SRIOV_INFINIBAND_CNI_IMAGE")
data.Data["ReleaseVersion"] = os.Getenv("RELEASEVERSION")
data.Data["ClusterType"] = utils.ClusterType
envCniBinPath := os.Getenv("SRIOV_CNI_BIN_PATH")
if envCniBinPath == "" {
data.Data["CNIBinPath"] = "/var/lib/cni/bin"
} else {
logger.Info("New cni bin found", "CNIBinPath", envCniBinPath)
data.Data["CNIBinPath"] = envCniBinPath
}
objs, err := render.RenderDir(CONFIG_DAEMON_PATH, &data)
if err != nil {
logger.Error(err, "Fail to render config daemon manifests")
Expand Down