@@ -17,7 +17,6 @@ limitations under the License.
17
17
package controller
18
18
19
19
import (
20
- "cmp"
21
20
"context"
22
21
"errors"
23
22
"fmt"
@@ -39,7 +38,6 @@ import (
39
38
apierrors "k8s.io/apimachinery/pkg/api/errors"
40
39
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
41
40
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
42
- "k8s.io/apimachinery/pkg/util/wait"
43
41
44
42
"github.com/sirupsen/logrus"
45
43
"sigs.k8s.io/yaml"
@@ -191,8 +189,9 @@ func (i *ClusterConfigInitializer) ensureClusterConfigExistence(ctx context.Cont
191
189
client := clientset .K0sV1beta1 ().ClusterConfigs (constant .ClusterConfigNamespace )
192
190
193
191
// We need to wait until the cluster configuration exists or we succeed in creating it.
192
+ start := time .Now ()
194
193
var stackApplied bool
195
- pollErr := wait . PollUntilContextTimeout ( ctx , 1 * time . Second , 20 * time . Second , true , func ( ctx context. Context ) ( bool , error ) {
194
+ for {
196
195
if i .leaderElector .IsLeader () {
197
196
if stackApplied {
198
197
err = nil
@@ -204,36 +203,39 @@ func (i *ClusterConfigInitializer) ensureClusterConfigExistence(ctx context.Cont
204
203
err = i .createClusterConfig (ctx , client )
205
204
if err == nil {
206
205
i .log .Debug ("Cluster configuration created" )
207
- return true , nil
206
+ return nil
208
207
}
209
208
if apierrors .IsAlreadyExists (err ) {
210
209
// An already existing configuration is just fine.
211
210
i .log .Debug ("Cluster configuration already exists" )
212
- return true , nil
211
+ return nil
213
212
}
214
213
}
215
214
} else {
216
215
err = i .clusterConfigExists (ctx , client )
217
216
if err == nil {
218
217
i .log .Debug ("Cluster configuration exists" )
219
- return true , nil
218
+ return nil
220
219
}
221
220
}
222
221
223
- i .log .WithError (err ).Debug ("Failed to ensure the existence of the cluster configuration" )
224
- return false , nil
225
- })
226
-
227
- if pollErr != nil {
228
- pollErr = cmp .Or (context .Cause (ctx ), pollErr )
229
- if err != nil {
230
- return fmt .Errorf ("%w (%w)" , pollErr , err )
222
+ var log func (... any )
223
+ if now := time .Now (); now .Sub (start ) >= (1 * time .Minute ) {
224
+ start = now
225
+ log = i .log .WithError (err ).Info
226
+ } else {
227
+ log = i .log .WithError (err ).Debug
231
228
}
232
229
233
- return pollErr
234
- }
230
+ log ("Still trying to ensure the existence of the cluster configuration" )
235
231
236
- return nil
232
+ select {
233
+ case <- time .After (1 * time .Second ):
234
+ continue
235
+ case <- ctx .Done ():
236
+ return fmt .Errorf ("%w (last error: %w)" , context .Cause (ctx ), err )
237
+ }
238
+ }
237
239
}
238
240
239
241
func (i * ClusterConfigInitializer ) applyAPIConfigStack (ctx context.Context ) error {
0 commit comments