Skip to content

Commit

Permalink
fix: Always mount tmp emptyDir. Fixes #1194 (#1196)
Browse files Browse the repository at this point in the history
* fix: Always mount tmp emptyDir

Signed-off-by: Derek Wang <whynowy@gmail.com>
  • Loading branch information
whynowy committed May 4, 2021
1 parent 071ca70 commit 6f9823f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
21 changes: 11 additions & 10 deletions controllers/eventsource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,18 @@ func buildDeployment(args *AdaptorArgs, eventBus *eventbusv1alpha1.EventBus) (*a
encodedBusConfig := base64.StdEncoding.EncodeToString(busConfigBytes)
envVars = append(envVars, corev1.EnvVar{Name: common.EnvVarEventBusConfig, Value: encodedBusConfig})
if eventBus.Status.Config.NATS != nil {
volumes := deploymentSpec.Template.Spec.Volumes
volumeMounts := deploymentSpec.Template.Spec.Containers[0].VolumeMounts
emptyDirVolName := "tmp"
volumes = append(volumes, corev1.Volume{
Name: emptyDirVolName, VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
})
volumeMounts = append(volumeMounts, corev1.VolumeMount{Name: emptyDirVolName, MountPath: "/tmp"})

natsConf := eventBus.Status.Config.NATS
if natsConf.Auth != nil && natsConf.AccessSecret != nil {
// Mount the secret as volume instead of using evnFrom to gain the ability
// for the sensor deployment to auto reload when the secret changes
volumes := deploymentSpec.Template.Spec.Volumes
// for the event source deployment to auto reload when the secret changes
volumes = append(volumes, corev1.Volume{
Name: "auth-volume",
VolumeSource: corev1.VolumeSource{
Expand All @@ -219,16 +226,10 @@ func buildDeployment(args *AdaptorArgs, eventBus *eventbusv1alpha1.EventBus) (*a
},
},
})
emptyDirVolName := "tmp"
volumes = append(volumes, corev1.Volume{
Name: emptyDirVolName, VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
})
deploymentSpec.Template.Spec.Volumes = volumes
volumeMounts := deploymentSpec.Template.Spec.Containers[0].VolumeMounts
volumeMounts = append(volumeMounts, corev1.VolumeMount{Name: "auth-volume", MountPath: common.EventBusAuthFileMountPath})
volumeMounts = append(volumeMounts, corev1.VolumeMount{Name: emptyDirVolName, MountPath: "/tmp"})
deploymentSpec.Template.Spec.Containers[0].VolumeMounts = volumeMounts
}
deploymentSpec.Template.Spec.Volumes = volumes
deploymentSpec.Template.Spec.Containers[0].VolumeMounts = volumeMounts
} else {
return nil, errors.New("unsupported event bus")
}
Expand Down
5 changes: 5 additions & 0 deletions controllers/eventsource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ func Test_BuildDeployment(t *testing.T) {
volumes := deployment.Spec.Template.Spec.Volumes
assert.True(t, len(volumes) > 0)
hasAuthVolume := false
hasTmpVolume := false
cmRefs, secretRefs := 0, 0
for _, vol := range volumes {
if vol.Name == "auth-volume" {
hasAuthVolume = true
}
if vol.Name == "tmp" {
hasTmpVolume = true
}
if strings.Contains(vol.Name, testEventSource.Spec.HDFS["test"].KrbCCacheSecret.Name) {
secretRefs++
}
Expand All @@ -59,6 +63,7 @@ func Test_BuildDeployment(t *testing.T) {
}
}
assert.True(t, hasAuthVolume)
assert.True(t, hasTmpVolume)
assert.True(t, len(deployment.Spec.Template.Spec.ImagePullSecrets) > 0)
assert.True(t, cmRefs > 0)
assert.True(t, secretRefs > 0)
Expand Down
19 changes: 10 additions & 9 deletions controllers/sensor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,18 @@ func buildDeployment(args *AdaptorArgs, eventBus *eventbusv1alpha1.EventBus) (*a
encodedBusConfig := base64.StdEncoding.EncodeToString(busConfigBytes)
envVars = append(envVars, corev1.EnvVar{Name: common.EnvVarEventBusConfig, Value: encodedBusConfig})
if eventBus.Status.Config.NATS != nil {
volumes := deploymentSpec.Template.Spec.Volumes
volumeMounts := deploymentSpec.Template.Spec.Containers[0].VolumeMounts
emptyDirVolName := "tmp"
volumes = append(volumes, corev1.Volume{
Name: emptyDirVolName, VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
})
volumeMounts = append(volumeMounts, corev1.VolumeMount{Name: emptyDirVolName, MountPath: "/tmp"})

natsConf := eventBus.Status.Config.NATS
if natsConf.Auth != nil && natsConf.AccessSecret != nil {
// Mount the secret as volume instead of using evnFrom to gain the ability
// for the sensor deployment to auto reload when the secret changes
volumes := deploymentSpec.Template.Spec.Volumes
volumes = append(volumes, corev1.Volume{
Name: "auth-volume",
VolumeSource: corev1.VolumeSource{
Expand All @@ -185,16 +192,10 @@ func buildDeployment(args *AdaptorArgs, eventBus *eventbusv1alpha1.EventBus) (*a
},
},
})
emptyDirVolName := "tmp"
volumes = append(volumes, corev1.Volume{
Name: emptyDirVolName, VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
})
deploymentSpec.Template.Spec.Volumes = volumes
volumeMounts := deploymentSpec.Template.Spec.Containers[0].VolumeMounts
volumeMounts = append(volumeMounts, corev1.VolumeMount{Name: "auth-volume", MountPath: common.EventBusAuthFileMountPath})
volumeMounts = append(volumeMounts, corev1.VolumeMount{Name: emptyDirVolName, MountPath: "/tmp"})
deploymentSpec.Template.Spec.Containers[0].VolumeMounts = volumeMounts
}
deploymentSpec.Template.Spec.Volumes = volumes
deploymentSpec.Template.Spec.Containers[0].VolumeMounts = volumeMounts
} else {
return nil, errors.New("unsupported event bus")
}
Expand Down
6 changes: 5 additions & 1 deletion controllers/sensor/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ func Test_BuildDeployment(t *testing.T) {
volumes := deployment.Spec.Template.Spec.Volumes
assert.True(t, len(volumes) > 0)
hasAuthVolume := false
hasTmpVolume := false
for _, vol := range volumes {
if vol.Name == "auth-volume" {
hasAuthVolume = true
break
}
if vol.Name == "tmp" {
hasTmpVolume = true
}
}
assert.True(t, hasAuthVolume)
assert.True(t, hasTmpVolume)
assert.True(t, len(deployment.Spec.Template.Spec.ImagePullSecrets) > 0)
assert.Equal(t, deployment.Spec.Template.Spec.PriorityClassName, "test-class")
})
Expand Down

0 comments on commit 6f9823f

Please sign in to comment.