-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
3b686c5
to
5fded91
Compare
5fded91
to
d2093f9
Compare
/hold |
/hold cancel |
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.
/hold
@cjwagner PTAL
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.
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:
test-infra/prow/pod-utils/decorate/podspec.go
Line 538 in dda2b80
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.
prow/cmd/build/controller.go
Outdated
dc.GracePeriod = &prowjobv1.Duration{ | ||
Duration: 0, | ||
} | ||
} |
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.
Why is this defaulting implemented in the build controller? These values should already have been defaulted before the build controller handles them.
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 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?
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.
/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.
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 could add a defaulting accessor to the config struct and disallow the use of direct references @droslean
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.
addressed
3cd1305
to
1a0e8e3
Compare
1a0e8e3
to
96b20cd
Compare
@cjwagner Should the defaults be different than zero? |
prow/config/config.go
Outdated
@@ -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 { |
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 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
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.
addressed
96b20cd
to
1572b49
Compare
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.
/hold
@cjwagner PTAL
LGTM label has been added. Git tree hash: f4b035678f44b46f063edda69217ecff8730788e
|
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 just have a couple nits.
prow/apis/prowjobs/v1/types.go
Outdated
return d.Timeout | ||
} | ||
|
||
func (d *DecorationConfig) GetGracePeriod() *Duration { |
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.
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.)
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.
nit: The GetTimeout
and GetGracePeriod
functions could be replaced with a single func (d *Duration) Get() time.Duration
function.
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.
addressed
1572b49
to
7088e00
Compare
7088e00
to
f333f20
Compare
LGTM label has been added. Git tree hash: c28475a9cc335a5da4fe4e08aa5f1c0c662cb901
|
[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 |
/hold cancel |
After #12100 landed,
omitempty
is ignored when unmarshaling a time.Duration.Example:
will be exported as
To fix this issue, the
Duration
should be a pointer.Related proposal fix: golang/go/issues/11939