-
Notifications
You must be signed in to change notification settings - Fork 521
CLOUDP-73217: fix volumes merging #204
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,26 +304,26 @@ func TestMergeVolumes_DoesNotAddDuplicatesWithSameName(t *testing.T) { | |
| }) | ||
|
|
||
| overridePodSpec := getDefaultPodSpec() | ||
| defaultPodSpec.Spec.Volumes = append(defaultPodSpec.Spec.Volumes, corev1.Volume{ | ||
| overridePodSpec.Spec.Volumes = append(overridePodSpec.Spec.Volumes, corev1.Volume{ | ||
| Name: "new-volume", | ||
| VolumeSource: corev1.VolumeSource{ | ||
| HostPath: &corev1.HostPathVolumeSource{ | ||
| Path: "updated-host-path", | ||
| }, | ||
| }, | ||
| }) | ||
| defaultPodSpec.Spec.Volumes = append(defaultPodSpec.Spec.Volumes, corev1.Volume{ | ||
| overridePodSpec.Spec.Volumes = append(overridePodSpec.Spec.Volumes, corev1.Volume{ | ||
| Name: "new-volume-3", | ||
| }) | ||
|
|
||
| mergedPodSpecTemplate, err := MergePodTemplateSpecs(defaultPodSpec, overridePodSpec) | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.Len(t, mergedPodSpecTemplate.Spec.Volumes, 3) | ||
| assert.Equal(t, mergedPodSpecTemplate.Spec.Volumes[0].Name, "new-volume") | ||
| assert.Equal(t, mergedPodSpecTemplate.Spec.Volumes[0].VolumeSource.HostPath.Path, "updated-host-path") | ||
| assert.Equal(t, mergedPodSpecTemplate.Spec.Volumes[1].Name, "new-volume-2") | ||
| assert.Equal(t, mergedPodSpecTemplate.Spec.Volumes[2].Name, "new-volume-3") | ||
| assert.Equal(t, "new-volume", mergedPodSpecTemplate.Spec.Volumes[0].Name) | ||
| assert.Equal(t, "updated-host-path", mergedPodSpecTemplate.Spec.Volumes[0].VolumeSource.HostPath.Path) | ||
| assert.Equal(t, "new-volume-2", mergedPodSpecTemplate.Spec.Volumes[1].Name) | ||
| assert.Equal(t, "new-volume-3", mergedPodSpecTemplate.Spec.Volumes[2].Name) | ||
| } | ||
|
|
||
| func TestMergeVolumeMounts(t *testing.T) { | ||
|
|
@@ -342,6 +342,57 @@ func TestMergeVolumeMounts(t *testing.T) { | |
| assert.Equal(t, []corev1.VolumeMount{vol2, vol0}, mergedVolumeMounts) | ||
| } | ||
|
|
||
| func TestMergeVolumesSecret(t *testing.T) { | ||
| permission := int32(416) | ||
| vol0 := []corev1.Volume{{Name: "volume", VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{SecretName: "Secret-name"}}}} | ||
| vol1 := []corev1.Volume{{Name: "volume", VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{DefaultMode: &permission}}}} | ||
| mergedVolumes := mergeVolumes(vol0, vol1) | ||
| assert.Len(t, mergedVolumes, 1) | ||
| volume := mergedVolumes[0] | ||
| assert.Equal(t, "volume", volume.Name) | ||
| assert.Equal(t, corev1.SecretVolumeSource{SecretName: "Secret-name", DefaultMode: &permission}, *volume.Secret) | ||
| } | ||
|
|
||
| func TestMergeNonNilValueNotFilledByOperator(t *testing.T) { | ||
| // Tests that providing a custom volume with a volume source | ||
| // That the operator does not manage overwrites the original | ||
| vol0 := []corev1.Volume{{Name: "volume", VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{SecretName: "Secret-name"}}}} | ||
| vol1 := []corev1.Volume{{Name: "volume", VolumeSource: corev1.VolumeSource{GCEPersistentDisk: &corev1.GCEPersistentDiskVolumeSource{}}}} | ||
| mergedVolumes := mergeVolumes(vol0, vol1) | ||
| assert.Len(t, mergedVolumes, 1) | ||
| volume := mergedVolumes[0] | ||
| assert.Equal(t, "volume", volume.Name) | ||
| assert.Equal(t, corev1.GCEPersistentDiskVolumeSource{}, *volume.GCEPersistentDisk) | ||
|
Comment on lines
+356
to
+365
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one tests the case in which the user provides a custom config with one of the values that the operator do not manage . We expect the original one to be set to nil and to just see the new one |
||
| assert.Nil(t, volume.Secret) | ||
| } | ||
|
|
||
| func TestMergeNonNilValueFilledByOperatorButDifferent(t *testing.T) { | ||
| // Tests that providing a custom volume with a volume source | ||
| // That the operator does manage, but different from the one | ||
| // That already exists, overwrites the original | ||
| vol0 := []corev1.Volume{{Name: "volume", VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{SecretName: "Secret-name"}}}} | ||
| vol1 := []corev1.Volume{{Name: "volume", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}}} | ||
| mergedVolumes := mergeVolumes(vol0, vol1) | ||
| assert.Len(t, mergedVolumes, 1) | ||
| volume := mergedVolumes[0] | ||
| assert.Equal(t, "volume", volume.Name) | ||
| assert.Equal(t, corev1.EmptyDirVolumeSource{}, *volume.EmptyDir) | ||
| assert.Nil(t, volume.Secret) | ||
| } | ||
|
Comment on lines
+369
to
+381
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one tests the case in which the user provides a custom config with one of the values that the operator manages. We expect the original one to be set to nil and to just see the new one |
||
|
|
||
| func TestMergeVolumeAddVolume(t *testing.T) { | ||
| vol0 := []corev1.Volume{{Name: "volume0", VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{}}}} | ||
| vol1 := []corev1.Volume{{Name: "volume1", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}}} | ||
| mergedVolumes := mergeVolumes(vol0, vol1) | ||
| assert.Len(t, mergedVolumes, 2) | ||
| volume0 := mergedVolumes[0] | ||
| assert.Equal(t, "volume0", volume0.Name) | ||
| assert.Equal(t, corev1.SecretVolumeSource{}, *volume0.Secret) | ||
| volume1 := mergedVolumes[1] | ||
| assert.Equal(t, "volume1", volume1.Name) | ||
| assert.Equal(t, corev1.EmptyDirVolumeSource{}, *volume1.EmptyDir) | ||
| } | ||
|
Comment on lines
+383
to
+394
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably unnecessary, but I wanted to also have a "simple" tests that just performs the very basic |
||
|
|
||
| func int64Ref(i int64) *int64 { | ||
| return &i | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are merging the secretSource so we expect it to contain both values