Skip to content
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

DecorationConfig: add pointers to Durations. #12414

Merged
merged 4 commits into from
May 3, 2019

Conversation

droslean
Copy link
Member

@droslean droslean commented Apr 30, 2019

After #12100 landed, omitempty is ignored when unmarshaling a time.Duration.
Example:

DecorationConfig: &v1.DecorationConfig{SkipCloning: true}

will be exported as

timeout: 0s
grace_period: 0s
skip_cloning: true

To fix this issue, the Duration should be a pointer.

Related proposal fix: golang/go/issues/11939

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 30, 2019
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. area/prow Issues or PRs related to prow sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Apr 30, 2019
@droslean droslean changed the title DecorationConfig: add pointers to Durations. [WIP] DecorationConfig: add pointers to Durations. Apr 30, 2019
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 30, 2019
@k8s-ci-robot k8s-ci-robot added area/prow/knative-build Issues or PRs related to prow's knative-build controller component area/prow/pod-utilities Issues or PRs related to prow's pod-utilities component size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 30, 2019
@droslean droslean changed the title [WIP] DecorationConfig: add pointers to Durations. DecorationConfig: add pointers to Durations. Apr 30, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 30, 2019
@droslean
Copy link
Member Author

droslean commented Apr 30, 2019

/hold
testing if these changes will break the rest of the logic.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 30, 2019
@droslean
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 30, 2019
@droslean
Copy link
Member Author

/cc @cjwagner @stevekuznetsov

Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold
@cjwagner PTAL

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 30, 2019
Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is going to be changed to a pointer we need to ensure that there is always a value specified once the config is loaded (or explicitly check for a nil pointer and handle defaulting separately everywhere which is not a good idea).
For example, if we merged this PR as is, this line could start segfaulting because the Timeout and GracePeriod fields could be nil:

wrapperOptions, err := InjectEntrypoint(&spec.Containers[0], pj.Spec.DecorationConfig.Timeout.Duration, pj.Spec.DecorationConfig.GracePeriod.Duration, prefix, previous, exitZero, logMount, toolsMount)

The easiest way around this would be to default the Timeout and GracePeriod fields in the DefaultDecorationConfig if they are unspecified. Around here.

dc.GracePeriod = &prowjobv1.Duration{
Duration: 0,
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this defaulting implemented in the build controller? These values should already have been defaulted before the build controller handles them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to make this comment then I channelled my inner @fejta and there is technically nothing stopping someone from making a nil entry with mkpj or something and then the defensive coding here is ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/shrug
We can keep it if that is a concern, but I'd like to see the proper defaulting as well at least (especially because there is the potential for segfaults with the current implementation).

mkpj will still properly default the field based on the default_decoration_config. The only concern would be hand crafted ProwJob yaml which can break prow in a lot of ways already. I think adding a ProwJob webhook admission controller is the right way to handle that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a defaulting accessor to the config struct and disallow the use of direct references @droslean

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@k8s-ci-robot k8s-ci-robot added ¯\_(ツ)_/¯ ¯\\\_(ツ)_/¯ and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Apr 30, 2019
@droslean droslean force-pushed the decoration-config branch 3 times, most recently from 3cd1305 to 1a0e8e3 Compare May 1, 2019 11:34
@droslean droslean changed the title WIP DecorationConfig: add pointers to Durations. DecorationConfig: add pointers to Durations. May 1, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 1, 2019
@droslean
Copy link
Member Author

droslean commented May 1, 2019

@cjwagner Should the defaults be different than zero?

@@ -668,6 +668,14 @@ func (c *Config) finalizeJobConfig() error {
return errors.New("no default GCS credentials secret provided for plank")
}

if c.Plank.DefaultDecorationConfig.Timeout == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is sufficient -- the issue is, this is for job configuration coming from the YAML on disk, but we want to make sure that when we read the values from a ProwJob CRD in etcd we get no nil pointers. I was thinking we have a

func (c *DecorationConfig) Timeout() Duration {
    if c.Timeout == nil {
        return &Duration{0}
    }
    return c.Timeout
}

And use that in the consumres

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 2, 2019
Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold
@cjwagner PTAL

@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: f4b035678f44b46f063edda69217ecff8730788e

Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a couple nits.

return d.Timeout
}

func (d *DecorationConfig) GetGracePeriod() *Duration {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Return time.Duration instead of *Duration. The time package type is directly usable and returning a pointer doesn't make much sense since this should always return a concrete value. (This applies to GetTimeout as well.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The GetTimeout and GetGracePeriod functions could be replaced with a single func (d *Duration) Get() time.Duration function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 3, 2019
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 3, 2019
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: c28475a9cc335a5da4fe4e08aa5f1c0c662cb901

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: droslean, stevekuznetsov

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cjwagner
Copy link
Member

cjwagner commented May 3, 2019

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 3, 2019
@k8s-ci-robot k8s-ci-robot merged commit 6e83130 into kubernetes:master May 3, 2019
@droslean droslean deleted the decoration-config branch May 7, 2019 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/prow/knative-build Issues or PRs related to prow's knative-build controller component area/prow/pod-utilities Issues or PRs related to prow's pod-utilities component area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. ¯\_(ツ)_/¯ ¯\\\_(ツ)_/¯
Projects
None yet
Development

Successfully merging this pull request may close these issues.

proposal: encoding/json, encoding/xml: support zero values of structs with omitempty
4 participants