-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add support for emptydir rw access and e2e testing #11705
Conversation
Codecov Report
@@ Coverage Diff @@
## main #11705 +/- ##
==========================================
+ Coverage 87.80% 87.83% +0.02%
==========================================
Files 190 190
Lines 9275 9279 +4
==========================================
+ Hits 8144 8150 +6
Misses 878 878
+ Partials 253 251 -2
Continue to review full report at Codecov.
|
6b30d5d
to
adfe004
Compare
/retest |
/assign @dprotaso |
pkg/apis/serving/k8s_validation.go
Outdated
@@ -105,8 +106,11 @@ func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes set | |||
} | |||
errs = errs.Also(validateVolume(ctx, volume).ViaIndex(i)) | |||
volumes.Insert(volume.Name) | |||
if volume.EmptyDir != nil { | |||
nonReadOnlyVolumes.Insert(volume.Name) |
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.
the variable is called nonReadOnlyVolumes
, but it seems like it actually contains nonEmptyDirVolumes. When we actually use it we end up negating it again (!nonReadOnlyValumes.Has(..)
) which is a lot of negations for my mind to follow and confused me a bit: maybe this could be emptyDirVolumes
or allowedReadWriteVolumes
or something like that?
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.
(see suggested alternative approach in 3rd comment though which makes this comment and the next redundant if it works!)
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.
I can change the name but the var contains only emptyDirs as they are the only ones which are supported and can have rw access. At least this is the intention here.
but it seems like it actually contains nonEmptyDirVolumes
Don't parse this part. Could you explain a bit more?
pkg/apis/serving/k8s_validation.go
Outdated
@@ -82,8 +82,9 @@ var ( | |||
) | |||
|
|||
// ValidateVolumes validates the Volumes of a PodSpec. | |||
func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes sets.String) (sets.String, *apis.FieldError) { | |||
func ValidateVolumes(ctx context.Context, vs []corev1.Volume, mountedVolumes sets.String) (sets.String, sets.String, *apis.FieldError) { |
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.
since we have two sets.String in the return section now I'd probably add variable names for them and maybe add to the method comment to indicate what each is
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.
Yes ok.
pkg/apis/serving/k8s_validation.go
Outdated
volumes := make(sets.String, len(vs)) | ||
nonReadOnlyVolumes := make(sets.String) |
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.
thinking out loud: a nice alternative approach might be to make the return value of this method a map[string]corev1.Volume
(rather than two sets.Strings each with different semantics, which is maybe a bit unwieldy and slightly hard to document). The volume.EmptyDir != nil
in this method would then not be needed at all, and in validateVolumeMounts
you could do: if volumes[vm.Name].EmptyDir != nil && !vm.ReadOnly
(which means the logic would only be in only one place).
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.
Yeah I also thought of returning volumes instead or some data structure but didnt want to change the signature for existing code (less changes).
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.
Right but we have to change the signature anyway since we pass two sets.Strings around everywhere now?
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.
Yes but didnt touch some other parts though eg. accessing the first string set stayed the same. Anyway I can take a look and refactor it ;)
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.
Heheheh yeah, worth a go anyway I think since it'd move all the logic to one place and avoid having two pass two things up and down the stack
@@ -1509,7 +1509,7 @@ func TestContainerValidation(t *testing.T) { | |||
ctx = config.ToContext(ctx, cfg) | |||
} | |||
|
|||
got := ValidateContainer(ctx, test.c, test.volumes) | |||
got := ValidateContainer(ctx, test.c, test.volumes, make(sets.String)) |
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.
probably worth a unit test for the new behaviour here too I think
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.
Yes we can cover more cases there by adding a test case field.
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.
nice! lgtm bar a formatting nit in the tests and I think it's probably worth logging the errors in the test image in this case
volumes: map[string]corev1.Volume{ | ||
"the-name": { | ||
Name: "the-name", | ||
VolumeSource: corev1.VolumeSource{ | ||
ConfigMap: &corev1.ConfigMapVolumeSource{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: "test-cm", | ||
}}, | ||
}, | ||
}}, |
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.
total nit, but I think for consistency the formatting here should be:
volumes: map[string]corev1.Volume{ | |
"the-name": { | |
Name: "the-name", | |
VolumeSource: corev1.VolumeSource{ | |
ConfigMap: &corev1.ConfigMapVolumeSource{ | |
LocalObjectReference: corev1.LocalObjectReference{ | |
Name: "test-cm", | |
}}, | |
}, | |
}}, | |
volumes: map[string]corev1.Volume{ | |
"the-name": { | |
Name: "the-name", | |
VolumeSource: corev1.VolumeSource{ | |
ConfigMap: &corev1.ConfigMapVolumeSource{ | |
LocalObjectReference: corev1.LocalObjectReference{ | |
Name: "test-cm", | |
}, | |
}, | |
}, | |
}, | |
}, |
(basically line the braces up under the first column of where the opening brace is)
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.
ok
}) | ||
|
||
withVolume2 := WithVolume("cache", "/cache", corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{}, |
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.
I dont think we actually try reading/writing to this, but I guess we just want to test the validation allows this since we tested read/write on the other volume?
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.
Yes to show that we can have multiple ones.
if path == "" { | ||
path = "/data" | ||
} | ||
f, _ := os.OpenFile(path+"/testfile", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) |
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.
worth logging the error here, since it may help with debugging if e.g. the volume was mounted read-only?
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.
Ok let me add that
/assign @julz |
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.
/lgtm
/approve
nice, thanks @skonto!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: julz, skonto The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* add support for emptydir rw access, e2e * fix header * fix quantity * set to alpha feature * toggle feature * fixes * fix fmt * fix nit
* add support for emptydir rw access, e2e * fix header * fix quantity * set to alpha feature * toggle feature * fixes * fix fmt * fix nit
* Add support for emptyDir volume type (knative#11669) * support emptyDir volume * fixes * reorder feature * Add support for emptydir rw access and e2e testing (knative#11705) * add support for emptydir rw access, e2e * fix header * fix quantity * set to alpha feature * toggle feature * fixes * fix fmt * fix nit Co-authored-by: Stavros Kontopoulos <[email protected]>
Part of the work in #11664.
/cc @julz @dprotaso @markusthoemmes @nak3