Skip to content

Commit 52dc197

Browse files
authored
Merge pull request #5882 from k0sproject/backport-5873-to-release-1.33
[Backport release-1.33] Remove timeout from dynamic cluster config initializer
2 parents 212315a + beb5cd3 commit 52dc197

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

pkg/component/controller/clusterconfig.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package controller
1818

1919
import (
20-
"cmp"
2120
"context"
2221
"errors"
2322
"fmt"
@@ -39,7 +38,6 @@ import (
3938
apierrors "k8s.io/apimachinery/pkg/api/errors"
4039
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4140
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
42-
"k8s.io/apimachinery/pkg/util/wait"
4341

4442
"github.com/sirupsen/logrus"
4543
"sigs.k8s.io/yaml"
@@ -191,8 +189,9 @@ func (i *ClusterConfigInitializer) ensureClusterConfigExistence(ctx context.Cont
191189
client := clientset.K0sV1beta1().ClusterConfigs(constant.ClusterConfigNamespace)
192190

193191
// We need to wait until the cluster configuration exists or we succeed in creating it.
192+
start := time.Now()
194193
var stackApplied bool
195-
pollErr := wait.PollUntilContextTimeout(ctx, 1*time.Second, 20*time.Second, true, func(ctx context.Context) (bool, error) {
194+
for {
196195
if i.leaderElector.IsLeader() {
197196
if stackApplied {
198197
err = nil
@@ -204,36 +203,39 @@ func (i *ClusterConfigInitializer) ensureClusterConfigExistence(ctx context.Cont
204203
err = i.createClusterConfig(ctx, client)
205204
if err == nil {
206205
i.log.Debug("Cluster configuration created")
207-
return true, nil
206+
return nil
208207
}
209208
if apierrors.IsAlreadyExists(err) {
210209
// An already existing configuration is just fine.
211210
i.log.Debug("Cluster configuration already exists")
212-
return true, nil
211+
return nil
213212
}
214213
}
215214
} else {
216215
err = i.clusterConfigExists(ctx, client)
217216
if err == nil {
218217
i.log.Debug("Cluster configuration exists")
219-
return true, nil
218+
return nil
220219
}
221220
}
222221

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
231228
}
232229

233-
return pollErr
234-
}
230+
log("Still trying to ensure the existence of the cluster configuration")
235231

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+
}
237239
}
238240

239241
func (i *ClusterConfigInitializer) applyAPIConfigStack(ctx context.Context) error {

0 commit comments

Comments
 (0)