Skip to content

Commit

Permalink
Supporting user-defined kubelet directory (#2893)
Browse files Browse the repository at this point in the history
Co-authored-by: yuanliu <yuanliu@cmss.chinamobile.com>
  • Loading branch information
2 people authored and zbb88888 committed Nov 14, 2023
1 parent 67adfd9 commit 1c94602
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
5 changes: 3 additions & 2 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,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 @@ -3171,6 +3171,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 @@ -3202,7 +3203,7 @@ spec:
mountPath: /lib/modules
readOnly: true
- name: shared-dir
mountPath: /var/lib/kubelet/pods
mountPath: $KUBELET_DIR/pods
- mountPath: /etc/openvswitch
name: systemid
- mountPath: /etc/cni/net.d
Expand Down
4 changes: 3 additions & 1 deletion kubeovn-helm/templates/ovncni-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ spec:
- --alsologtostderr=true
- --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 @@ -103,7 +105,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
- mountPath: /etc/cni/net.d
Expand Down
10 changes: 10 additions & 0 deletions kubeovn-helm/templates/ovsovn-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ spec:
name: kube-ovn-tls
- mountPath: /var/run/containerd
name: cruntime
{{- if or .Values.DPDK .Values.HYBRID_DPDK }}
- mountPath: /opt/ovs-config
name: host-config-ovs
- mountPath: /dev/hugepages
name: hugepage
{{- end }}
{{- if .Values.HYBRID_DPDK }}
- name: shareddir
mountPath: {{ .Values.kubelet_conf.KUBELET_DIR }}/pods
{{- end }}
readinessProbe:
exec:
command:
Expand Down
3 changes: 3 additions & 0 deletions pkg/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Configuration struct {
EnableVerboseConnCheck bool
TCPConnCheckPort int
UDPConnCheckPort int
KubeletDir string
}

// ParseFlags will parse cmd args then init kubeClient and configuration
Expand Down Expand Up @@ -97,6 +98,7 @@ func ParseFlags() *Configuration {
argEnableVerboseConnCheck = pflag.Bool("enable-verbose-conn-check", false, "enable TCP/UDP connectivity check listen port")
argTCPConnectivityCheckPort = pflag.Int("tcp-conn-check-port", 8100, "TCP connectivity Check Port")
argUDPConnectivityCheckPort = pflag.Int("udp-conn-check-port", 8101, "UDP connectivity Check Port")
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 @@ -149,6 +151,7 @@ func ParseFlags() *Configuration {
EnableVerboseConnCheck: *argEnableVerboseConnCheck,
TCPConnCheckPort: *argTCPConnectivityCheckPort,
UDPConnCheckPort: *argUDPConnectivityCheckPort,
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 @@ -133,7 +133,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

0 comments on commit 1c94602

Please sign in to comment.