@@ -17,6 +17,8 @@ import (
1717 "golang.stackrox.io/kube-linter/pkg/templates"
1818 "golang.stackrox.io/kube-linter/pkg/templates/updateconfig/internal/params"
1919
20+ ocsAppsv1 "github.com/openshift/api/apps/v1"
21+ appsv1 "k8s.io/api/apps/v1"
2022 "k8s.io/apimachinery/pkg/util/intstr"
2123)
2224
@@ -111,6 +113,21 @@ func needsRollingUpdateDefinition(p params.Params) bool {
111113 p .MinSurge != "" || p .MaxSurge != "" )
112114}
113115
116+ func defaultStrategyType (object lintcontext.Object ) (string , bool ) {
117+ switch object .K8sObject .(type ) {
118+ case * appsv1.Deployment :
119+ return string (appsv1 .RollingUpdateDeploymentStrategyType ), true
120+ case * appsv1.DaemonSet :
121+ return string (appsv1 .RollingUpdateDaemonSetStrategyType ), true
122+ case * appsv1.StatefulSet :
123+ return string (appsv1 .RollingUpdateStatefulSetStrategyType ), true
124+ case * ocsAppsv1.DeploymentConfig :
125+ return string (ocsAppsv1 .DeploymentStrategyTypeRolling ), true
126+ default :
127+ return "" , false
128+ }
129+ }
130+
114131func init () {
115132 templates .Register (check.Template {
116133 HumanName : "Update configuration" ,
@@ -165,10 +182,16 @@ func init() {
165182 if ! strategy .TypeExists {
166183 return nil
167184 }
168- if ! compiledRegex .MatchString (strategy .Type ) {
185+ strategyType := strategy .Type
186+ if strategyType == "" {
187+ if defaultType , ok := defaultStrategyType (object ); ok {
188+ strategyType = defaultType
189+ }
190+ }
191+ if ! compiledRegex .MatchString (strategyType ) {
169192 newD := diagnostic.Diagnostic {
170193 Message : fmt .Sprintf ("object has %s strategy type but must match regex %s" ,
171- stringutils .Ternary (strategy . Type != "" , strategy . Type , "no" ), p .StrategyTypeRegex )}
194+ stringutils .Ternary (strategyType != "" , strategyType , "no" ), p .StrategyTypeRegex )}
172195 diagnostics = append (diagnostics , newD )
173196 }
174197 if ! strategy .RollingConfigExists {
0 commit comments