@@ -19,6 +19,7 @@ import (
19
19
"strings"
20
20
"time"
21
21
22
+ corev1 "k8s.io/api/core/v1"
22
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
24
"k8s.io/apimachinery/pkg/runtime/schema"
24
25
"k8s.io/apimachinery/pkg/types"
@@ -29,6 +30,7 @@ import (
29
30
"kpt.dev/configsync/e2e/nomostest/testwatcher"
30
31
"kpt.dev/configsync/pkg/api/configsync"
31
32
"kpt.dev/configsync/pkg/api/configsync/v1beta1"
33
+ "kpt.dev/configsync/pkg/api/kpt.dev/v1alpha1"
32
34
"kpt.dev/configsync/pkg/core/k8sobjects"
33
35
"kpt.dev/configsync/pkg/kinds"
34
36
"kpt.dev/configsync/pkg/reposync"
@@ -100,6 +102,14 @@ func SkipReadyCheck() WatchForAllSyncsOptions {
100
102
}
101
103
}
102
104
105
+ // SkipAllResourceGroupChecks is an optional parameter which specifies to skip
106
+ // ResourceGroup checks for all RSyncs after they finish syncing.
107
+ func SkipAllResourceGroupChecks () WatchForAllSyncsOptions {
108
+ return func (options * watchForAllSyncsOptions ) {
109
+ options .watchForSyncOpts = append (options .watchForSyncOpts , SkipResourceGroupCheck ())
110
+ }
111
+ }
112
+
103
113
// WatchForAllSyncs calls WatchForSync on all Syncs in nt.SyncSources.
104
114
//
105
115
// If you want to validate specific fields of a Sync object, use
@@ -159,7 +169,8 @@ func (nt *NT) WatchForAllSyncs(options ...WatchForAllSyncsOptions) error {
159
169
}
160
170
161
171
type watchForSyncOptions struct {
162
- watchOptions []testwatcher.WatchOption
172
+ watchOptions []testwatcher.WatchOption
173
+ skipResourceGroupCheck bool
163
174
}
164
175
165
176
// WatchForSyncOption is an optional parameter for WatchForSync.
@@ -173,6 +184,14 @@ func WithWatchOptions(watchOpts ...testwatcher.WatchOption) WatchForSyncOption {
173
184
}
174
185
}
175
186
187
+ // SkipResourceGroupCheck is an optional parameter to skip the ResourceGroup
188
+ // watch after the RSync finishes syncing.
189
+ func SkipResourceGroupCheck () WatchForSyncOption {
190
+ return func (options * watchForSyncOptions ) {
191
+ options .skipResourceGroupCheck = true
192
+ }
193
+ }
194
+
176
195
// WatchForSync watches the specified sync object until it's synced.
177
196
//
178
197
// - gvk (required) is the sync object GroupVersionKind
@@ -188,7 +207,8 @@ func (nt *NT) WatchForSync(
188
207
) error {
189
208
nt .T .Helper ()
190
209
opts := watchForSyncOptions {
191
- watchOptions : []testwatcher.WatchOption {},
210
+ skipResourceGroupCheck : false ,
211
+ watchOptions : []testwatcher.WatchOption {},
192
212
}
193
213
// Override defaults with specified options
194
214
for _ , option := range options {
@@ -239,6 +259,26 @@ func (nt *NT) WatchForSync(
239
259
return fmt .Errorf ("waiting for sync: %w" , err )
240
260
}
241
261
nt .T .Logf ("%s %s/%s is synced" , gvk .Kind , namespace , name )
262
+ if opts .skipResourceGroupCheck {
263
+ return nil
264
+ }
265
+ rgWatchOptions := []testwatcher.WatchOption {
266
+ testwatcher .WatchPredicates ([]testpredicates.Predicate {
267
+ // Wait until status.observedGeneration matches metadata.generation
268
+ testpredicates .HasObservedLatestGeneration (nt .Scheme ),
269
+ // Wait until metadata.deletionTimestamp is missing, and conditions do not include Reconciling=True or Stalled=True
270
+ testpredicates .StatusEquals (nt .Scheme , kstatus .CurrentStatus ),
271
+ // Make sure the ResourceGroup has the Stalled condition and it is "False"
272
+ // This ensures the condition exists and wasn't removed by the applier
273
+ testpredicates .HasConditionStatus (nt .Scheme , string (v1alpha1 .Stalled ), corev1 .ConditionFalse ),
274
+ // Wait until all resourceStatuses are consistent with spec and current/reconciled
275
+ resourceGroupHasReconciled (expectedCommit ),
276
+ }... ),
277
+ }
278
+ rgWatchOptions = append (rgWatchOptions , opts .watchOptions ... )
279
+ if err := nt .Watcher .WatchObject (kinds .ResourceGroup (), name , namespace , rgWatchOptions ... ); err != nil {
280
+ return fmt .Errorf ("waiting for ResourceGroup: %w" , err )
281
+ }
242
282
return nil
243
283
}
244
284
0 commit comments