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

Supporting user-defined kubelet directory #2893

Merged
merged 1 commit into from
Jun 5, 2023
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
3 changes: 2 additions & 1 deletion charts/templates/ovncni-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ spec:
- --log_file=/var/log/kube-ovn/kube-ovn-cni.log
- --log_file_max_size=0
- --enable-metrics={{- .Values.networking.ENABLE_METRICS }}
- --kubelet-dir={{ .Values.kubelet_conf.KUBELET_DIR }}
securityContext:
runAsUser: 0
privileged: true
Expand Down Expand Up @@ -108,7 +109,7 @@ spec:
mountPath: /lib/modules
readOnly: true
- name: shared-dir
mountPath: /var/lib/kubelet/pods
mountPath: {{ .Values.kubelet_conf.KUBELET_DIR }}/pods
- mountPath: /etc/openvswitch
name: systemid
readOnly: true
Expand Down
2 changes: 1 addition & 1 deletion charts/templates/ovsovn-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spec:
{{- end }}
{{- if .Values.HYBRID_DPDK }}
- name: shareddir
mountPath: /var/lib/kubelet/pods
mountPath: {{ .Values.kubelet_conf.KUBELET_DIR }}/pods
{{- end }}
readinessProbe:
exec:
Expand Down
5 changes: 3 additions & 2 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3919,7 +3919,7 @@ spec:
- mountPath: /opt/ovs-config
name: host-config-ovs
- name: shareddir
mountPath: /var/lib/kubelet/pods
mountPath: $KUBELET_DIR/pods
- name: hugepage
mountPath: /dev/hugepages
- mountPath: /lib/modules
Expand Down Expand Up @@ -4253,6 +4253,7 @@ spec:
- --alsologtostderr=true
- --log_file=/var/log/kube-ovn/kube-ovn-cni.log
- --log_file_max_size=0
- --kubelet-dir=$KUBELET_DIR
securityContext:
runAsUser: 0
privileged: true
Expand Down Expand Up @@ -4284,7 +4285,7 @@ spec:
mountPath: /lib/modules
readOnly: true
- name: shared-dir
mountPath: /var/lib/kubelet/pods
mountPath: $KUBELET_DIR/pods
- mountPath: /etc/openvswitch
name: systemid
readOnly: true
Expand Down
3 changes: 3 additions & 0 deletions pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Configuration struct {
ExternalGatewaySwitch string // provider network underlay vlan subnet
EnableMetrics bool
EnableArpDetectIPConflict bool
KubeletDir string
}

// ParseFlags will parse cmd args then init kubeClient and configuration
Expand Down Expand Up @@ -92,6 +93,7 @@ func ParseFlags() *Configuration {
argExternalGatewaySwitch = pflag.String("external-gateway-switch", "external", "The name of the external gateway switch which is a ovs bridge to provide external network, default: external")
argEnableMetrics = pflag.Bool("enable-metrics", true, "Whether to support metrics query")
argEnableArpDetectIPConflict = pflag.Bool("enable-arp-detect-ip-conflict", true, "Whether to support arp detect ip conflict in vlan network")
argKubeletDir = pflag.String("kubelet-dir", "/var/lib/kubelet", "Path of the kubelet dir, default: /var/lib/kubelet")
)

// mute info log for ipset lib
Expand Down Expand Up @@ -142,6 +144,7 @@ func ParseFlags() *Configuration {
ExternalGatewaySwitch: *argExternalGatewaySwitch,
EnableMetrics: *argEnableMetrics,
EnableArpDetectIPConflict: *argEnableArpDetectIPConflict,
KubeletDir: *argKubeletDir,
}
return config
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
nicType = util.OffloadType
} else if podRequest.VhostUserSocketVolumeName != "" {
nicType = util.DpdkType
if err = createShortSharedDir(pod, podRequest.VhostUserSocketVolumeName); err != nil {
if err = createShortSharedDir(pod, podRequest.VhostUserSocketVolumeName, csh.Config.KubeletDir); err != nil {
klog.Error(err.Error())
if err = resp.WriteHeaderAndEntity(http.StatusInternalServerError, request.CniResponse{Err: err.Error()}); err != nil {
klog.Errorf("failed to write response: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/daemon/handler_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (csh cniServerHandler) validatePodRequest(req *request.CniRequest) error {
return nil
}

func createShortSharedDir(pod *v1.Pod, volumeName string) (err error) {
func createShortSharedDir(pod *v1.Pod, volumeName string, kubeletDir string) (err error) {
var volume *v1.Volume
for index, v := range pod.Spec.Volumes {
if v.Name == volumeName {
Expand All @@ -36,7 +36,7 @@ func createShortSharedDir(pod *v1.Pod, volumeName string) (err error) {
if volume.EmptyDir == nil {
return fmt.Errorf("volume %s is not empty dir", volume.Name)
}
originSharedDir := fmt.Sprintf("/var/lib/kubelet/pods/%s/volumes/kubernetes.io~empty-dir/%s", pod.UID, volumeName)
originSharedDir := fmt.Sprintf("%s/pods/%s/volumes/kubernetes.io~empty-dir/%s", kubeletDir, pod.UID, volumeName)
newSharedDir := getShortSharedDir(pod.UID, volumeName)
// set vhostuser dir 777 for qemu has the permission to create sock
mask := syscall.Umask(0)
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/handler_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (csh cniServerHandler) validatePodRequest(req *request.CniRequest) error {
return nil
}

func createShortSharedDir(pod *v1.Pod, volumeName string) error {
func createShortSharedDir(pod *v1.Pod, volumeName string, kubeletDir string) error {
// nothing to do on Windows
return nil
}
Expand Down