File tree 5 files changed +60
-4
lines changed
5 files changed +60
-4
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func init() {
24
24
Parameters : params .ParamDescs ,
25
25
ParseAndValidateParams : params .ParseAndValidate ,
26
26
Instantiate : params .WrapInstantiateFunc (func (_ params.Params ) (check.Func , error ) {
27
- return util .PerContainerCheck (func (container * v1.Container ) []diagnostic.Diagnostic {
27
+ return util .PerNonInitContainerCheck (func (container * v1.Container ) []diagnostic.Diagnostic {
28
28
if container .LivenessProbe == nil {
29
29
return []diagnostic.Diagnostic {{Message : fmt .Sprintf ("container %q does not specify a liveness probe" , container .Name )}}
30
30
}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func init() {
24
24
Parameters : params .ParamDescs ,
25
25
ParseAndValidateParams : params .ParseAndValidate ,
26
26
Instantiate : params .WrapInstantiateFunc (func (_ params.Params ) (check.Func , error ) {
27
- return util .PerContainerCheck (func (container * v1.Container ) []diagnostic.Diagnostic {
27
+ return util .PerNonInitContainerCheck (func (container * v1.Container ) []diagnostic.Diagnostic {
28
28
if container .ReadinessProbe == nil {
29
29
return []diagnostic.Diagnostic {{Message : fmt .Sprintf ("container %q does not specify a readiness probe" , container .Name )}}
30
30
}
Original file line number Diff line number Diff line change @@ -25,3 +25,21 @@ func PerContainerCheck(matchFunc func(container *v1.Container) []diagnostic.Diag
25
25
return results
26
26
}
27
27
}
28
+
29
+ // PerNonInitContainerCheck returns a check that abstracts away some of the boilerplate of writing a check
30
+ // that applies to all non-init containers. The given function is passed each non-init container,
31
+ // and is allowed to return diagnostics if an error is found.
32
+ func PerNonInitContainerCheck (matchFunc func (container * v1.Container ) []diagnostic.Diagnostic ) check.Func {
33
+ return func (_ lintcontext.LintContext , object lintcontext.Object ) []diagnostic.Diagnostic {
34
+ podSpec , found := extract .PodSpec (object .K8sObject )
35
+ if ! found {
36
+ return nil
37
+ }
38
+ var results []diagnostic.Diagnostic
39
+ containers := podSpec .NonInitContainers ()
40
+ for i := range containers {
41
+ results = append (results , matchFunc (& containers [i ])... )
42
+ }
43
+ return results
44
+ }
45
+ }
Original file line number Diff line number Diff line change 51
51
template :
52
52
spec :
53
53
containers :
54
- - name : app2
54
+ - name : app2
55
+ ---
56
+ apiVersion : apps/v1
57
+ kind : Deployment
58
+ metadata :
59
+ name : dont-fire
60
+ spec :
61
+ template :
62
+ spec :
63
+ initContainers :
64
+ - name : some-container
65
+ containers :
66
+ - name : app
67
+ livenessProbe :
68
+ exec :
69
+ command :
70
+ - cat
71
+ - /tmp/healthy
72
+ initialDelaySeconds : 5
73
+ periodSeconds : 5
Original file line number Diff line number Diff line change 51
51
template :
52
52
spec :
53
53
containers :
54
- - name : app
54
+ - name : app
55
+ ---
56
+ apiVersion : apps/v1
57
+ kind : Deployment
58
+ metadata :
59
+ name : dont-fire
60
+ spec :
61
+ template :
62
+ spec :
63
+ initContainers :
64
+ - name : some-container
65
+ containers :
66
+ - name : app
67
+ readinessProbe :
68
+ exec :
69
+ command :
70
+ - cat
71
+ - /tmp/healthy
72
+ initialDelaySeconds : 5
73
+ periodSeconds : 5
You can’t perform that action at this time.
0 commit comments