Skip to content

Commit b8da31c

Browse files
authored
make hostname configurable (#1386)
Signed-off-by: zwwhdls <weiwei.zhu@juicefs.io>
1 parent e06ca6b commit b8da31c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

pkg/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ type MountPodPatch struct {
207207
Annotations map[string]string `json:"annotations,omitempty"`
208208
HostNetwork *bool `json:"hostNetwork,omitempty" `
209209
HostPID *bool `json:"hostPID,omitempty" `
210+
HostnameKey string `json:"hostnameKey,omitempty"`
210211
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty"`
211212
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`
212213
StartupProbe *corev1.Probe `json:"startupProbe,omitempty"`
@@ -345,6 +346,9 @@ func (mpp *MountPodPatch) merge(mp MountPodPatch) {
345346
if mp.CacheDirs != nil {
346347
mpp.CacheDirs = mp.CacheDirs
347348
}
349+
if mp.HostnameKey != "" {
350+
mpp.HostnameKey = mp.HostnameKey
351+
}
348352
}
349353

350354
// TODO: migrate more config for here

pkg/config/setting.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ type PodAttr struct {
157157
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
158158
Env []corev1.EnvVar `json:"env,omitempty"`
159159
CacheDirs []MountPatchCacheDir `json:"cacheDirs,omitempty"`
160+
HostnameKey string `json:"-"`
160161

161162
// inherit from csi
162163
Image string
@@ -1083,6 +1084,9 @@ func applyConfigPatch(setting *JfsSetting) {
10831084
if patch.Resources != nil {
10841085
attr.Resources = *patch.Resources
10851086
}
1087+
if patch.HostnameKey != "" {
1088+
attr.HostnameKey = patch.HostnameKey
1089+
}
10861090
attr.Lifecycle = util.CpNotNil(patch.Lifecycle, attr.Lifecycle)
10871091
attr.LivenessProbe = util.CpNotNil(patch.LivenessProbe, attr.LivenessProbe)
10881092
attr.ReadinessProbe = util.CpNotNil(patch.ReadinessProbe, attr.ReadinessProbe)

pkg/juicefs/mount/builder/common.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ func (r *BaseBuilder) genCommonJuicePod(cnGen func() corev1.Container) *corev1.P
8585
pod.Spec.ServiceAccountName = r.jfsSetting.Attr.ServiceAccountName
8686
pod.Spec.PriorityClassName = config.JFSMountPriorityName
8787
pod.Spec.RestartPolicy = corev1.RestartPolicyAlways
88-
pod.Spec.Hostname = r.jfsSetting.VolumeId
88+
if hostname := r.genHostname(); hostname != "" {
89+
pod.Spec.Hostname = hostname
90+
}
8991
gracePeriod := int64(10)
9092
if r.jfsSetting.Attr.TerminationGracePeriodSeconds != nil {
9193
gracePeriod = *r.jfsSetting.Attr.TerminationGracePeriodSeconds
@@ -145,6 +147,21 @@ func (r *BaseBuilder) genCommonJuicePod(cnGen func() corev1.Container) *corev1.P
145147
return pod
146148
}
147149

150+
func (r *BaseBuilder) genHostname() string {
151+
// set hostname according to jfsSetting.Attr.HostnameKey
152+
// default is volumeid
153+
hostnameKey := strings.ToLower(r.jfsSetting.Attr.HostnameKey)
154+
switch hostnameKey {
155+
case "podname":
156+
// if hostname is none, use pod name by default
157+
return ""
158+
case "volumeid":
159+
fallthrough
160+
default:
161+
return r.jfsSetting.VolumeId
162+
}
163+
}
164+
148165
// genMountCommand generates mount command
149166
func (r *BaseBuilder) genMountCommand() string {
150167
cmd := ""

0 commit comments

Comments
 (0)