talos

Форк
0
/
kubeconfig.go 
51 строка · 1.2 Кб
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package conditions
6

7
import (
8
	"context"
9
	"fmt"
10
	"os"
11
	"time"
12

13
	"k8s.io/client-go/tools/clientcmd"
14
)
15

16
type kubeconfig string
17

18
func (filename kubeconfig) Wait(ctx context.Context) error {
19
	ticker := time.NewTicker(time.Second)
20
	defer ticker.Stop()
21

22
	for {
23
		_, err := os.Stat(string(filename))
24
		if err != nil && !os.IsNotExist(err) {
25
			return err
26
		}
27

28
		_, err = clientcmd.BuildConfigFromFlags("", string(filename))
29
		if err == nil {
30
			return nil
31
		}
32

33
		// TODO: we can't check for specific error here (looking for file not found for client key/cert):
34
		//       https://github.com/kubernetes/kubernetes/pull/105080
35

36
		select {
37
		case <-ctx.Done():
38
			return ctx.Err()
39
		case <-ticker.C:
40
		}
41
	}
42
}
43

44
func (filename kubeconfig) String() string {
45
	return fmt.Sprintf("kubeconfig %q to be ready", string(filename))
46
}
47

48
// WaitForKubeconfigReady is a condition that will wait for the kubeconfig to be ready.
49
func WaitForKubeconfigReady(filename string) Condition {
50
	return kubeconfig(filename)
51
}
52

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.