@@ -37,13 +37,12 @@ import (
37
37
)
38
38
39
39
type watchForAllSyncsOptions struct {
40
- timeout time.Duration
41
40
readyCheck bool
42
41
syncRootRepos bool
43
42
syncNamespaceRepos bool
44
43
skipRootRepos map [string ]bool
45
44
skipNonRootRepos map [types.NamespacedName ]bool
46
- predicates []testpredicates. Predicate
45
+ watchForSyncOpts [] WatchForSyncOption
47
46
}
48
47
49
48
// WatchForAllSyncsOptions is an optional parameter for WaitForRepoSyncs.
@@ -52,14 +51,8 @@ type WatchForAllSyncsOptions func(*watchForAllSyncsOptions)
52
51
// WithTimeout provides the timeout to WaitForRepoSyncs.
53
52
func WithTimeout (timeout time.Duration ) WatchForAllSyncsOptions {
54
53
return func (options * watchForAllSyncsOptions ) {
55
- options .timeout = timeout
56
- }
57
- }
58
-
59
- // WithPredicates adds additional predicates for all reconcilers to WaitForRepoSyncs.
60
- func WithPredicates (predicates ... testpredicates.Predicate ) WatchForAllSyncsOptions {
61
- return func (options * watchForAllSyncsOptions ) {
62
- options .predicates = append (predicates , predicates ... )
54
+ options .watchForSyncOpts = append (options .watchForSyncOpts ,
55
+ WithWatchOptions (testwatcher .WatchTimeout (timeout )))
63
56
}
64
57
}
65
58
@@ -114,13 +107,12 @@ func SkipReadyCheck() WatchForAllSyncsOptions {
114
107
func (nt * NT ) WatchForAllSyncs (options ... WatchForAllSyncsOptions ) error {
115
108
nt .T .Helper ()
116
109
opts := watchForAllSyncsOptions {
117
- timeout : nt .DefaultWaitTimeout ,
118
110
readyCheck : true ,
119
111
syncRootRepos : true ,
120
112
syncNamespaceRepos : true ,
121
113
skipRootRepos : make (map [string ]bool ),
122
114
skipNonRootRepos : make (map [types.NamespacedName ]bool ),
123
- predicates : []testpredicates. Predicate {},
115
+ watchForSyncOpts : [] WatchForSyncOption {},
124
116
}
125
117
// Override defaults with specified options
126
118
for _ , option := range options {
@@ -133,13 +125,6 @@ func (nt *NT) WatchForAllSyncs(options ...WatchForAllSyncsOptions) error {
133
125
}
134
126
}
135
127
136
- watchOptions := []testwatcher.WatchOption {
137
- testwatcher .WatchTimeout (opts .timeout ),
138
- }
139
- if len (opts .predicates ) > 0 {
140
- watchOptions = append (watchOptions , testwatcher .WatchPredicates (opts .predicates ... ))
141
- }
142
-
143
128
tg := taskgroup .New ()
144
129
145
130
if opts .syncRootRepos {
@@ -151,7 +136,7 @@ func (nt *NT) WatchForAllSyncs(options ...WatchForAllSyncsOptions) error {
151
136
tg .Go (func () error {
152
137
return nt .WatchForSync (
153
138
kinds .RootSyncV1Beta1 (), idPtr .Name , idPtr .Namespace , source ,
154
- watchOptions ... )
139
+ opts . watchForSyncOpts ... )
155
140
})
156
141
}
157
142
}
@@ -165,14 +150,29 @@ func (nt *NT) WatchForAllSyncs(options ...WatchForAllSyncsOptions) error {
165
150
tg .Go (func () error {
166
151
return nt .WatchForSync (
167
152
kinds .RepoSyncV1Beta1 (), idPtr .Name , idPtr .Namespace , source ,
168
- watchOptions ... )
153
+ opts . watchForSyncOpts ... )
169
154
})
170
155
}
171
156
}
172
157
173
158
return tg .Wait ()
174
159
}
175
160
161
+ type watchForSyncOptions struct {
162
+ watchOptions []testwatcher.WatchOption
163
+ }
164
+
165
+ // WatchForSyncOption is an optional parameter for WatchForSync.
166
+ type WatchForSyncOption func (* watchForSyncOptions )
167
+
168
+ // WithWatchOptions is an optional parameter to specify WatchOptions used for
169
+ // both the RSync watch and ResourceGroup watch.
170
+ func WithWatchOptions (watchOpts ... testwatcher.WatchOption ) WatchForSyncOption {
171
+ return func (options * watchForSyncOptions ) {
172
+ options .watchOptions = append (options .watchOptions , watchOpts ... )
173
+ }
174
+ }
175
+
176
176
// WatchForSync watches the specified sync object until it's synced.
177
177
//
178
178
// - gvk (required) is the sync object GroupVersionKind
@@ -184,9 +184,16 @@ func (nt *NT) WatchForSync(
184
184
gvk schema.GroupVersionKind ,
185
185
name , namespace string ,
186
186
source syncsource.SyncSource ,
187
- opts ... testwatcher. WatchOption ,
187
+ options ... WatchForSyncOption ,
188
188
) error {
189
189
nt .T .Helper ()
190
+ opts := watchForSyncOptions {
191
+ watchOptions : []testwatcher.WatchOption {},
192
+ }
193
+ // Override defaults with specified options
194
+ for _ , option := range options {
195
+ option (& opts )
196
+ }
190
197
if namespace == "" {
191
198
// If namespace is empty, use the default namespace
192
199
namespace = configsync .ControllerNamespace
@@ -222,9 +229,12 @@ func (nt *NT) WatchForSync(
222
229
testpredicates .ErrWrongType , gvk .Kind ))
223
230
}
224
231
225
- opts = append (opts , testwatcher .WatchPredicates (predicates ... ))
232
+ rsyncWatchOptions := []testwatcher.WatchOption {
233
+ testwatcher .WatchPredicates (predicates ... ),
234
+ }
235
+ rsyncWatchOptions = append (rsyncWatchOptions , opts .watchOptions ... )
226
236
227
- err = nt .Watcher .WatchObject (gvk , name , namespace , opts ... )
237
+ err = nt .Watcher .WatchObject (gvk , name , namespace , rsyncWatchOptions ... )
228
238
if err != nil {
229
239
return fmt .Errorf ("waiting for sync: %w" , err )
230
240
}
0 commit comments