Support extended pod logging options
Increase the supported controls on pod logging. Add validaiton to pod log options. Ensure the Kubelet is using a consistent, structured way to process pod log arguments. Add ?sinceSeconds=<durationInSeconds>, &sinceTime=<RFC3339>, ?timestamps=<bool>, ?tailLines=<number>, and ?limitBytes=<number>
This commit is contained in:
@@ -1950,3 +1950,23 @@ func ValidateThirdPartyResource(obj *api.ThirdPartyResource) errs.ValidationErro
|
||||
func ValidateSchemaUpdate(oldResource, newResource *api.ThirdPartyResource) errs.ValidationErrorList {
|
||||
return errs.ValidationErrorList{fmt.Errorf("Schema update is not supported.")}
|
||||
}
|
||||
|
||||
func ValidatePodLogOptions(opts *api.PodLogOptions) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
if opts.TailLines != nil && *opts.TailLines < 0 {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("tailLines", *opts.TailLines, "tailLines must be a non-negative integer or nil"))
|
||||
}
|
||||
if opts.LimitBytes != nil && *opts.LimitBytes < 1 {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("limitBytes", *opts.LimitBytes, "limitBytes must be a positive integer or nil"))
|
||||
}
|
||||
switch {
|
||||
case opts.SinceSeconds != nil && opts.SinceTime != nil:
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("sinceSeconds", *opts.SinceSeconds, "only one of sinceTime or sinceSeconds can be provided"))
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("sinceTime", *opts.SinceTime, "only one of sinceTime or sinceSeconds can be provided"))
|
||||
case opts.SinceSeconds != nil:
|
||||
if *opts.SinceSeconds < 1 {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("sinceSeconds", *opts.SinceSeconds, "sinceSeconds must be a positive integer"))
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
@@ -3864,3 +3864,34 @@ func fakeValidSecurityContext(priv bool) *api.SecurityContext {
|
||||
Privileged: &priv,
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidPodLogOptions(t *testing.T) {
|
||||
now := unversioned.Now()
|
||||
negative := int64(-1)
|
||||
zero := int64(0)
|
||||
positive := int64(1)
|
||||
tests := []struct {
|
||||
opt api.PodLogOptions
|
||||
errs int
|
||||
}{
|
||||
{api.PodLogOptions{}, 0},
|
||||
{api.PodLogOptions{Previous: true}, 0},
|
||||
{api.PodLogOptions{Follow: true}, 0},
|
||||
{api.PodLogOptions{TailLines: &zero}, 0},
|
||||
{api.PodLogOptions{TailLines: &negative}, 1},
|
||||
{api.PodLogOptions{TailLines: &positive}, 0},
|
||||
{api.PodLogOptions{LimitBytes: &zero}, 1},
|
||||
{api.PodLogOptions{LimitBytes: &negative}, 1},
|
||||
{api.PodLogOptions{LimitBytes: &positive}, 0},
|
||||
{api.PodLogOptions{SinceSeconds: &negative}, 1},
|
||||
{api.PodLogOptions{SinceSeconds: &positive}, 0},
|
||||
{api.PodLogOptions{SinceSeconds: &zero}, 1},
|
||||
{api.PodLogOptions{SinceTime: &now}, 0},
|
||||
}
|
||||
for i, test := range tests {
|
||||
errs := ValidatePodLogOptions(&test.opt)
|
||||
if test.errs != len(errs) {
|
||||
t.Errorf("%d: Unexpected errors: %v", i, errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user