Skip to content

Commit

Permalink
Merge pull request #194 from obnoxxx/host-network
Browse files Browse the repository at this point in the history
add a hostNetwork setting to the  Driver and ControllerPlugin   Specs
  • Loading branch information
Madhu-1 authored Feb 11, 2025
2 parents dadf901 + bca85a9 commit 6ce9837
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 7 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/driver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ type ControllerPluginResourcesSpec struct {
}

type ControllerPluginSpec struct {
// hostNetwork setting to be propagated to CSI controller plugin pods
HostNetwork *bool `json:"hostNetwork,omitempty"`
// Embedded common pods spec
PodCommonSpec `json:",inline"`

Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/crd/bases/csi.ceph.io_drivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,10 @@ spec:
Default is RollingUpdate.
type: string
type: object
hostNetwork:
description: hostNetwork setting to be propagated to CSI controller
plugin pods
type: boolean
imagePullPolicy:
description: To indicate the image pull policy to be applied to
all the containers in the csi driver pods.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/csi.ceph.io_operatorconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,10 @@ spec:
"RollingUpdate". Default is RollingUpdate.
type: string
type: object
hostNetwork:
description: hostNetwork setting to be propagated to CSI controller
plugin pods
type: boolean
imagePullPolicy:
description: To indicate the image pull policy to be applied
to all the containers in the csi driver pods.
Expand Down
8 changes: 8 additions & 0 deletions deploy/all-in-one/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,10 @@ spec:
Default is RollingUpdate.
type: string
type: object
hostNetwork:
description: hostNetwork setting to be propagated to CSI controller
plugin pods
type: boolean
imagePullPolicy:
description: To indicate the image pull policy to be applied to
all the containers in the csi driver pods.
Expand Down Expand Up @@ -8161,6 +8165,10 @@ spec:
"RollingUpdate". Default is RollingUpdate.
type: string
type: object
hostNetwork:
description: hostNetwork setting to be propagated to CSI controller
plugin pods
type: boolean
imagePullPolicy:
description: To indicate the image pull policy to be applied
to all the containers in the csi driver pods.
Expand Down
8 changes: 8 additions & 0 deletions deploy/multifile/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,10 @@ spec:
Default is RollingUpdate.
type: string
type: object
hostNetwork:
description: hostNetwork setting to be propagated to CSI controller
plugin pods
type: boolean
imagePullPolicy:
description: To indicate the image pull policy to be applied to
all the containers in the csi driver pods.
Expand Down Expand Up @@ -8152,6 +8156,10 @@ spec:
"RollingUpdate". Default is RollingUpdate.
type: string
type: object
hostNetwork:
description: hostNetwork setting to be propagated to CSI controller
plugin pods
type: boolean
imagePullPolicy:
description: To indicate the image pull policy to be applied
to all the containers in the csi driver pods.
Expand Down
25 changes: 21 additions & 4 deletions internal/controller/driver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
Spec: corev1.PodSpec{
ServiceAccountName: serviceAccountName,
PriorityClassName: ptr.Deref(pluginSpec.PrioritylClassName, ""),
HostNetwork: ptr.Deref(pluginSpec.HostNetwork, false),
Affinity: getControllerPluginPodAffinity(pluginSpec, &appSelector),
Tolerations: pluginSpec.Tolerations,
Containers: utils.Call(func() []corev1.Container {
Expand Down Expand Up @@ -758,6 +759,7 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
}
// Addons Sidecar Container
if !r.isNfsDriver() && ptr.Deref(r.driver.Spec.DeployCsiAddons, false) {
port := r.controllerPluginCsiAddonsContainerPort()
containers = append(containers, corev1.Container{
Name: "csi-addons",
Image: r.images["addons"],
Expand All @@ -771,15 +773,15 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
utils.PodContainerArg,
utils.PodUidContainerArg,
utils.CsiAddonsAddressContainerArg,
utils.ControllerPortContainerArg,
utils.ContainerPortArg(port),
utils.NamespaceContainerArg,
utils.If(logRotationEnabled, utils.LogToStdErrContainerArg, ""),
utils.If(logRotationEnabled, utils.AlsoLogToStdErrContainerArg, ""),
utils.If(logRotationEnabled, utils.LogFileContainerArg("csi-addons"), ""),
),
),
Ports: []corev1.ContainerPort{
utils.CsiAddonsContainerPort,
port,
},
Env: []corev1.EnvVar{
utils.NodeIdEnvVar,
Expand Down Expand Up @@ -921,6 +923,20 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
return err
}

func (r *driverReconcile) controllerPluginCsiAddonsContainerPort() corev1.ContainerPort {

// the cephFS and rbd drivers need to use different ports
// to avoid port collisions with host network.
port := utils.ControllerPluginCsiAddonsContainerRbdPort
if r.isCephFsDriver() {
port = utils.ControllerPluginCsiAddonsContainerCephFsPort

}

return port

}

func (r *driverReconcile) reconcileNodePluginDeamonSet() error {
daemonSet := &appsv1.DaemonSet{}
daemonSet.Name = r.generateName("nodeplugin")
Expand Down Expand Up @@ -1106,6 +1122,7 @@ func (r *driverReconcile) reconcileNodePluginDeamonSet() error {
}
// CSI Addons Sidecar Container
if r.isRdbDriver() && ptr.Deref(r.driver.Spec.DeployCsiAddons, false) {
port := utils.NodePluginCsiAddonsContainerPort
containers = append(containers, corev1.Container{
Name: "csi-addons",
Image: r.images["addons"],
Expand All @@ -1121,7 +1138,7 @@ func (r *driverReconcile) reconcileNodePluginDeamonSet() error {
utils.CsiAddonsNodeIdContainerArg,
utils.LogVerbosityContainerArg(logVerbosity),
utils.CsiAddonsAddressContainerArg,
utils.ControllerPortContainerArg,
utils.ContainerPortArg(port),
utils.PodContainerArg,
utils.NamespaceContainerArg,
utils.PodUidContainerArg,
Expand All @@ -1132,7 +1149,7 @@ func (r *driverReconcile) reconcileNodePluginDeamonSet() error {
},
),
Ports: []corev1.ContainerPort{
utils.CsiAddonsContainerPort,
port,
},
Env: []corev1.EnvVar{
utils.NodeIdEnvVar,
Expand Down
19 changes: 16 additions & 3 deletions internal/utils/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,25 @@ var DriverNamespaceEnvVar = corev1.EnvVar{
},
}

// CSI Addons container port definition
var CsiAddonsContainerPort = corev1.ContainerPort{
// CSI Addons container port definitions
var ControllerPluginCsiAddonsContainerRbdPort = corev1.ContainerPort{
ContainerPort: int32(9070),
}

var ControllerPluginCsiAddonsContainerCephFsPort = corev1.ContainerPort{
ContainerPort: int32(9080),
}

var NodePluginCsiAddonsContainerPort = corev1.ContainerPort{
ContainerPort: int32(9071),
}

func ContainerPortArg(port corev1.ContainerPort) string {

return fmt.Sprintf("--controller-port=%d", port.ContainerPort)

}

// Ceph CSI common container arguments
var CsiAddressContainerArg = fmt.Sprintf("--csi-address=%s", csiEndpoint)
var EndpointContainerArg = fmt.Sprintf("--endpoint=%s", csiEndpoint)
Expand All @@ -359,7 +373,6 @@ var HandleVolumeInuseErrorContainerArg = "--handle-volume-inuse-error=false"
var PodUidContainerArg = fmt.Sprintf("--pod-uid=$(%s)", PodUidEnvVar.Name)
var PodContainerArg = fmt.Sprintf("--pod=$(%s)", PodNameEnvVar.Name)
var NamespaceContainerArg = fmt.Sprintf("--namespace=$(%s)", PodNamespaceEnvVar.Name)
var ControllerPortContainerArg = fmt.Sprintf("--controller-port=%d", CsiAddonsContainerPort.ContainerPort)
var DriverNamespaceContainerArg = fmt.Sprintf("--drivernamespace=$(%s)", DriverNamespaceEnvVar.Name)
var MetricsPathContainerArg = "--metricspath=/metrics"
var PoolTimeContainerArg = "--polltime=60s"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ce9837

Please sign in to comment.