-
Notifications
You must be signed in to change notification settings - Fork 246
Add new check job-ttl-seconds-after-finished (#963) #964
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
base: main
Are you sure you want to change the base?
Conversation
The new check advices for - Setting ttlSecondsAfterFinished for standalone Job objects whenever it's not set - Unsetting ttlSecondsAfterFinished for managed Job objects whenever it's set
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.
Hey @wissamir - I've reviewed your changes - here's some feedback:
- There's a typo in the diagnostic message: ‘stricktier’ should be ‘stricter tier’.
- In TestCronJobTTL the inline comment says “must be nil” despite expecting a diagnostic – please correct or remove it to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There's a typo in the diagnostic message: ‘stricktier’ should be ‘stricter tier’.
- In TestCronJobTTL the inline comment says “must be nil” despite expecting a diagnostic – please correct or remove it to avoid confusion.
## Individual Comments
### Comment 1
<location> `pkg/templates/jobttlsecondsafterfinished/internal/params/gen-params.go:1` </location>
<code_context>
+// Code generated by kube-linter template codegen. DO NOT EDIT.
+// +build !templatecodegen
+
</code_context>
<issue_to_address>
Consider updating your code generation logic to only emit parameter validation boilerplate when parameters are present.
```markdown
You can eliminate all of this “dead” boilerplate when there are no parameters to validate by guarding your codegen on “has any parameters?”. E.g. in your template:
```gotemplate
{{/* params.go.tmpl */}}
{{- if .HasParameters }}
// Code generated by kube-linter template codegen. DO NOT EDIT.
package params
import (
"fmt"
"strings"
"github.com/pkg/errors"
"golang.stackrox.io/kube-linter/pkg/check"
"golang.stackrox.io/kube-linter/pkg/templates/util"
)
var (
// ParamDescs is only non-empty if .HasParameters==true
ParamDescs = []check.ParameterDesc{
{{- range .Params }}
util.MustParseParameterDesc({{ . | printf "%q" }}),
{{- end }}
}
)
func (p *Params) Validate() error {
var errs []string
// your per‐param validation here
if len(errs) > 0 {
return errors.Errorf("invalid parameters: %s", strings.Join(errs, ", "))
}
return nil
}
func ParseAndValidate(m map[string]interface{}) (interface{}, error) {
var p Params
if err := util.DecodeMapStructure(m, &p); err != nil {
return nil, err
}
if err := p.Validate(); err != nil {
return nil, err
}
return p, nil
}
func WrapInstantiateFunc(
f func(p Params) (check.Func, error),
) func(interface{}) (check.Func, error) {
return func(i interface{}) (check.Func, error) {
return f(i.(Params))
}
}
{{- else }}
// Code generated by kube-linter template codegen. DO NOT EDIT.
// No parameters, so we only need an empty Params placeholder.
package params
// Params is empty because .HasParameters = false
type Params struct{}
{{- end }}
```
Then in your higher‐level template you pass a boolean `.HasParameters = len .Params > 0`. This way, when there are no params, you only get a trivial `type Params struct{}` and none of the unused Validate/ParseAndValidate/Wrappers.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -0,0 +1,52 @@ | |||
// Code generated by kube-linter template codegen. DO NOT EDIT. |
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.
issue (complexity): Consider updating your code generation logic to only emit parameter validation boilerplate when parameters are present.
You can eliminate all of this “dead” boilerplate when there are no parameters to validate by guarding your codegen on “has any parameters?”. E.g. in your template:
```gotemplate
{{/* params.go.tmpl */}}
{{- if .HasParameters }}
// Code generated by kube-linter template codegen. DO NOT EDIT.
package params
import (
"fmt"
"strings"
"github.com/pkg/errors"
"golang.stackrox.io/kube-linter/pkg/check"
"golang.stackrox.io/kube-linter/pkg/templates/util"
)
var (
// ParamDescs is only non-empty if .HasParameters==true
ParamDescs = []check.ParameterDesc{
{{- range .Params }}
util.MustParseParameterDesc({{ . | printf "%q" }}),
{{- end }}
}
)
func (p *Params) Validate() error {
var errs []string
// your per‐param validation here
if len(errs) > 0 {
return errors.Errorf("invalid parameters: %s", strings.Join(errs, ", "))
}
return nil
}
func ParseAndValidate(m map[string]interface{}) (interface{}, error) {
var p Params
if err := util.DecodeMapStructure(m, &p); err != nil {
return nil, err
}
if err := p.Validate(); err != nil {
return nil, err
}
return p, nil
}
func WrapInstantiateFunc(
f func(p Params) (check.Func, error),
) func(interface{}) (check.Func, error) {
return func(i interface{}) (check.Func, error) {
return f(i.(Params))
}
}
{{- else }}
// Code generated by kube-linter template codegen. DO NOT EDIT.
// No parameters, so we only need an empty Params placeholder.
package params
// Params is empty because .HasParameters = false
type Params struct{}
{{- end }}
Then in your higher‐level template you pass a boolean .HasParameters = len .Params > 0
. This way, when there are no params, you only get a trivial type Params struct{}
and none of the unused Validate/ParseAndValidate/Wrappers.
The new check advices for
Complete description can be found in #963