@@ -39,6 +39,7 @@ import (
39
39
"github.com/ghodss/yaml" //nolint:depguard
40
40
apierrors "k8s.io/apimachinery/pkg/api/errors"
41
41
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
42
+ "k8s.io/apimachinery/pkg/types"
42
43
"k8s.io/apimachinery/pkg/util/sets"
43
44
"k8s.io/apimachinery/pkg/util/wait"
44
45
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -149,12 +150,44 @@ func RunCreateDeleteTest(t *Harness, opt CreateDeleteTestOptions) {
149
150
if len (opt .Updates ) != 0 {
150
151
// treat as a patch
151
152
for _ , updateUnstruct := range opt .Updates {
153
+ // We compute the diff so we can see if we only update labels
154
+ old := & unstructured.Unstructured {}
155
+ old .SetGroupVersionKind (updateUnstruct .GroupVersionKind ())
156
+
157
+ id := types.NamespacedName {
158
+ Name : updateUnstruct .GetName (),
159
+ Namespace : updateUnstruct .GetNamespace (),
160
+ }
161
+
162
+ if err := t .GetClient ().Get (ctx , id , old ); err != nil {
163
+ t .Fatalf ("error getting existing resource: %v" , err )
164
+ }
165
+
166
+ oldGeneration := old .GetGeneration ()
167
+
152
168
if err := t .GetClient ().Patch (ctx , updateUnstruct , client .Apply , client .FieldOwner ("kcc-tests" ), client .ForceOwnership ); err != nil {
153
169
t .Fatalf ("error updating resource: %v" , err )
154
170
}
171
+
172
+ newGeneration := updateUnstruct .GetGeneration ()
173
+
174
+ // Check if we are going to update the metadata.generation; only spec updates increment generation.
175
+ // Note in particular that updates that only touch labels/annotations do not update the generation field
176
+ willUpdateMetadataGeneration := true
177
+ if newGeneration == oldGeneration {
178
+ willUpdateMetadataGeneration = false
179
+ t .Logf ("WARN: metadata.generation did not change for %v; consider updating this test to include an update to the spec" , id )
180
+ }
181
+
155
182
if opt .CreateInOrder && ! opt .SkipWaitForReady {
156
183
waitForReadySingleResource (t , updateUnstruct , DefaultWaitForReadyTimeout )
157
184
}
185
+
186
+ if ! willUpdateMetadataGeneration {
187
+ // Allow some time for reconciliation
188
+ t .Logf ("sleeping for two seconds to allow for reconiliation (on an update that did not update metadata.generation)" )
189
+ time .Sleep (2 * time .Second )
190
+ }
158
191
}
159
192
160
193
if ! opt .CreateInOrder && ! opt .SkipWaitForReady {
0 commit comments