@@ -25,6 +25,7 @@ import (
25
25
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
26
26
"k8s.io/apiserver/pkg/registry/rest"
27
27
utilfeature "k8s.io/apiserver/pkg/util/feature"
28
+ utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing"
28
29
"k8s.io/kubernetes/pkg/api/testapi"
29
30
apitesting "k8s.io/kubernetes/pkg/api/testing"
30
31
"k8s.io/kubernetes/pkg/apis/batch"
@@ -121,6 +122,24 @@ func TestJobStrategy(t *testing.T) {
121
122
t .Errorf ("Job should only allow updating .spec.ttlSecondsAfterFinished when %v feature is enabled" , features .TTLAfterFinished )
122
123
}
123
124
125
+ // set TTLSecondsAfterFinished on both old and new jobs
126
+ job .Spec .TTLSecondsAfterFinished = newInt32 (1 )
127
+ updatedJob .Spec .TTLSecondsAfterFinished = newInt32 (2 )
128
+
129
+ // Existing TTLSecondsAfterFinished should be preserved when feature is on
130
+ defer utilfeaturetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .TTLAfterFinished , true )()
131
+ Strategy .PrepareForUpdate (ctx , updatedJob , job )
132
+ if job .Spec .TTLSecondsAfterFinished == nil || updatedJob .Spec .TTLSecondsAfterFinished == nil {
133
+ t .Errorf ("existing TTLSecondsAfterFinished should be preserved" )
134
+ }
135
+
136
+ // Existing TTLSecondsAfterFinished should be preserved when feature is off
137
+ defer utilfeaturetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .TTLAfterFinished , false )()
138
+ Strategy .PrepareForUpdate (ctx , updatedJob , job )
139
+ if job .Spec .TTLSecondsAfterFinished == nil || updatedJob .Spec .TTLSecondsAfterFinished == nil {
140
+ t .Errorf ("existing TTLSecondsAfterFinished should be preserved" )
141
+ }
142
+
124
143
// Make sure we correctly implement the interface.
125
144
// Otherwise a typo could silently change the default.
126
145
var gcds rest.GarbageCollectionDeleteStrategy = Strategy
0 commit comments