Skip to content

Commit 2a58081

Browse files
committed
operator: API to configure kubelet directory path
Not all clusters use /var/lib/kubelet as state directory for kubelet (kubernetes-csi/csi-driver-host-path#71). There is no way for the operator to auto-detect this path. Hence, added a new field to deployment spec that could be used to provide the kubelet path to driver deployment. FIXES: intel#668
1 parent b0c90bf commit 2a58081

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

docs/install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ The current API for PMEM-CSI `Deployment` resources is:
844844
| nodeSelector | string map | [Labels to use for selecting Nodes](../docs/install.md#run-pmem-csi-on-kubernetes) on which PMEM-CSI driver should run. | `{ "storage": "pmem" }`|
845845
| pmemPercentage | integer | Percentage of PMEM space to be used by the driver on each node. This is only valid for a driver deployed in `lvm` mode. This field can be modified, but by that time the old value may have been used already. Reducing the percentage is not supported. | 100 |
846846
| labels | string map | Additional labels for all objects created by the operator. Can be modified after the initial creation, but removed labels will not be removed from existing objects because the operator cannot know which labels it needs to remove and which it has to leave in place. |
847+
| kubeletDir | string | Kubelet's root directory path | /var/lib/kubelet |
847848

848849
<sup>1</sup> To use the same container image as default driver image
849850
the operator pod must set with below environment variables with

pkg/apis/pmemcsi/v1alpha1/deployment_types.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ type DeploymentSpec struct {
9191
PMEMPercentage uint16 `json:"pmemPercentage,omitempty"`
9292
// Labels contains additional labels for all objects created by the operator.
9393
Labels map[string]string `json:"labels,omitempty"`
94+
// KubeletDir kubelet's root directory path
95+
KubeletDir string `json:"kubeletDir,omitempty"`
9496
}
9597

9698
// DeploymentStatus defines the observed state of Deployment
@@ -163,6 +165,8 @@ const (
163165
DefaultDeviceMode = DeviceModeLVM
164166
// DefaultPMEMPercentage PMEM space to reserve for the driver
165167
DefaultPMEMPercentage = 100
168+
// DefaultKubeletDir default kubelet's path
169+
DefaultKubeletDir = "/var/lib/kubelet"
166170
)
167171

168172
var (
@@ -204,6 +208,7 @@ const (
204208
RegistryKey
205209
NodeControllerCertificate
206210
NodeControllerKey
211+
KubeletDir
207212
)
208213

209214
func (c DeploymentChange) String() string {
@@ -224,6 +229,7 @@ func (c DeploymentChange) String() string {
224229
RegistryKey: "registryKey",
225230
NodeControllerCertificate: "nodeControllerCert",
226231
NodeControllerKey: "nodeControllerKey",
232+
KubeletDir: "kubeletDir",
227233
}[c]
228234
}
229235

@@ -293,6 +299,10 @@ func (d *Deployment) EnsureDefaults(operatorImage string) error {
293299
d.Spec.PMEMPercentage = DefaultPMEMPercentage
294300
}
295301

302+
if d.Spec.KubeletDir == "" {
303+
d.Spec.KubeletDir = DefaultKubeletDir
304+
}
305+
296306
return nil
297307
}
298308

@@ -357,6 +367,9 @@ func (d *Deployment) Compare(other *Deployment) map[DeploymentChange]struct{} {
357367
if bytes.Compare(d.Spec.NodeControllerPrivateKey, other.Spec.NodeControllerPrivateKey) != 0 {
358368
changes[NodeControllerKey] = struct{}{}
359369
}
370+
if d.Spec.KubeletDir != other.Spec.KubeletDir {
371+
changes[KubeletDir] = struct{}{}
372+
}
360373

361374
return changes
362375
}
@@ -460,7 +473,12 @@ func GetDeploymentCRDSchema() *apiextensions.JSONSchemaProps {
460473
Type: "string",
461474
},
462475
},
463-
}},
476+
},
477+
"kubeletDir": apiextensions.JSONSchemaProps{
478+
Type: "string",
479+
Description: "Kubelet root directory path",
480+
},
481+
},
464482
},
465483
"status": apiextensions.JSONSchemaProps{
466484
Type: "object",

pkg/deployments/load.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func LoadAndCustomizeObjects(kubernetes version.Version, deviceMode api.DeviceMo
4747
*yaml = bytes.ReplaceAll(*yaml, []byte("path: /var/lib/pmem-csi.intel.com"), []byte("path: /var/lib/"+deployment.Name))
4848
*yaml = bytes.ReplaceAll(*yaml, []byte("mountPath: /var/lib/pmem-csi.intel.com"), []byte("mountPath: /var/lib/"+deployment.Name))
4949

50+
// Update kubelet path
51+
if deployment.Spec.KubeletDir != api.DefaultKubeletDir {
52+
*yaml = bytes.ReplaceAll(*yaml, []byte("/var/lib/kubelet"), []byte(deployment.Spec.KubeletDir))
53+
}
54+
5055
// This assumes that all namespaced objects actually have "namespace: default".
5156
*yaml = bytes.ReplaceAll(*yaml, []byte("namespace: default"), []byte("namespace: "+namespace))
5257

pkg/pmem-csi-operator/controller/deployment/controller_driver.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ func (d *PmemCSIDriver) reconcileDeploymentChanges(r *ReconcileDeployment, chang
105105
updateAll = true
106106
case api.CACertificate, api.RegistryCertificate, api.NodeControllerCertificate:
107107
updateSecrets = true
108+
case api.KubeletDir:
109+
updateNodeDriver = true
108110
}
109111

110112
if err != nil {
@@ -717,7 +719,7 @@ func (d *PmemCSIDriver) getNodeDaemonSet() *appsv1.DaemonSet {
717719
Name: "registration-dir",
718720
VolumeSource: corev1.VolumeSource{
719721
HostPath: &corev1.HostPathVolumeSource{
720-
Path: "/var/lib/kubelet/plugins_registry/",
722+
Path: d.Spec.KubeletDir + "/plugins_registry/",
721723
Type: &directoryOrCreate,
722724
},
723725
},
@@ -726,7 +728,7 @@ func (d *PmemCSIDriver) getNodeDaemonSet() *appsv1.DaemonSet {
726728
Name: "mountpoint-dir",
727729
VolumeSource: corev1.VolumeSource{
728730
HostPath: &corev1.HostPathVolumeSource{
729-
Path: "/var/lib/kubelet/plugins/kubernetes.io/csi",
731+
Path: d.Spec.KubeletDir + "/plugins/kubernetes.io/csi",
730732
Type: &directoryOrCreate,
731733
},
732734
},
@@ -735,7 +737,7 @@ func (d *PmemCSIDriver) getNodeDaemonSet() *appsv1.DaemonSet {
735737
Name: "pods-dir",
736738
VolumeSource: corev1.VolumeSource{
737739
HostPath: &corev1.HostPathVolumeSource{
738-
Path: "/var/lib/kubelet/pods",
740+
Path: d.Spec.KubeletDir + "/pods",
739741
Type: &directoryOrCreate,
740742
},
741743
},
@@ -908,12 +910,12 @@ func (d *PmemCSIDriver) getNodeDriverContainer() corev1.Container {
908910
VolumeMounts: []corev1.VolumeMount{
909911
{
910912
Name: "mountpoint-dir",
911-
MountPath: "/var/lib/kubelet/plugins/kubernetes.io/csi",
913+
MountPath: d.Spec.KubeletDir + "/plugins/kubernetes.io/csi",
912914
MountPropagation: &bidirectional,
913915
},
914916
{
915917
Name: "pods-dir",
916-
MountPath: "/var/lib/kubelet/pods",
918+
MountPath: d.Spec.KubeletDir + "/pods",
917919
MountPropagation: &bidirectional,
918920
},
919921
{

pkg/pmem-csi-operator/controller/deployment/deployment_controller_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type pmemDeployment struct {
4545
controllerCPU, controllerMemory string
4646
nodeCPU, nodeMemory string
4747
caCert, regCert, regKey, ncCert, ncKey []byte
48+
kubeletDir string
4849
}
4950

5051
func getDeployment(d *pmemDeployment) *api.Deployment {
@@ -91,6 +92,9 @@ func getDeployment(d *pmemDeployment) *api.Deployment {
9192
spec.RegistryPrivateKey = d.regKey
9293
spec.NodeControllerCert = d.ncCert
9394
spec.NodeControllerPrivateKey = d.ncKey
95+
if d.kubeletDir != "" {
96+
spec.KubeletDir = d.kubeletDir
97+
}
9498

9599
return dep
96100
}
@@ -236,6 +240,7 @@ func TestDeploymentController(t *testing.T) {
236240
controllerMemory: "300Mi",
237241
nodeCPU: "1000m",
238242
nodeMemory: "500Mi",
243+
kubeletDir: "/some/directory",
239244
}
240245

241246
dep := getDeployment(d)

pkg/pmem-csi-operator/controller/deployment/testcases/testcases.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func UpdateTests() []UpdateTest {
7777
}
7878
d.Spec.Labels["foo"] = "bar"
7979
},
80+
"kubeletDir": func(d *api.Deployment) {
81+
d.Spec.KubeletDir = "/foo/bar"
82+
},
8083
}
8184

8285
full := api.Deployment{

0 commit comments

Comments
 (0)