Repository: k3s-io/k3s
File: pkg/agent/config/config.go (Go)

Code before:

// Get returns a pointer to a completed Node configuration struct,
// containing a merging of the local CLI configuration with settings from the server.
// A call to this will bock until agent configuration is successfully returned by the
// server.
func Get(ctx context.Context, agent cmds.Agent, proxy proxy.Proxy) *config.Node {
	for {
		agentConfig, err := get(ctx, &agent, proxy)
		if err != nil {
			logrus.Errorf("Failed to configure agent: %v", err)
			select {
			case <-time.After(5 * time.Second):
				continue
			case <-ctx.Done():
				logrus.Fatal("Interrupted")
			}
		}
		return agentConfig
	}
}

// GetKubeProxyDisabled returns true if kube-proxy has been disabled in the server configuration.
// The server may not have a complete view of cluster configuration until after all startup
// hooks have completed, so a call to this will block until after the server's readyz endpoint
// returns OK.
func GetKubeProxyDisabled(ctx context.Context, node *config.Node, proxy proxy.Proxy) bool {
	for {
		disabled, err := getKubeProxyDisabled(ctx, node, proxy)
		if err != nil {
			logrus.Errorf("Failed to configure kube-proxy: %v", err)
			select {
			case <-time.After(5 * time.Second):
				continue
			case <-ctx.Done():
				logrus.Fatal("Interrupted")
			}
		}
		return disabled
	}
}

type HTTPRequester func(u string, client *http.Client, username, password string) ([]byte, error)

func Request(path string, info *clientaccess.Info, requester HTTPRequester) ([]byte, error) {
	u, err := url.Parse(info.BaseURL)
	if err != nil {
		return nil, err
	}
	u.Path = path
	return requester(u.String(), clientaccess.GetHTTPClient(info.CACerts), info.Username, info.Password)
}

Review comment (suggestion):
Nit: the "get" is unnecessary and reads a little cleaner without it.

```suggestion
func KubeProxyDisabled(ctx context.Context, node *config.Node, proxy proxy.Proxy) bool {
```

Code after:

// Get returns a pointer to a completed Node configuration struct,
// containing a merging of the local CLI configuration with settings from the server.
// A call to this will bock until agent configuration is successfully returned by the
// server.
func Get(ctx context.Context, agent cmds.Agent, proxy proxy.Proxy) *config.Node {
	ticker := time.NewTicker(5 * time.Second)
	defer ticker.Stop()
RETRY:
	for {
		agentConfig, err := get(ctx, &agent, proxy)
		if err != nil {
			logrus.Infof("Failed to retrieve agent configuration: %v", err)
			for range ticker.C {
				continue RETRY
			}
		}
		return agentConfig
	}
}

// KubeProxyDisabled returns a bool indicating whether or not kube-proxy has been disabled in the
// server configuration. The server may not have a complete view of cluster configuration until
// after all startup hooks have completed, so a call to this will block until after the server's
// readyz endpoint returns OK.
func KubeProxyDisabled(ctx context.Context, node *config.Node, proxy proxy.Proxy) bool {
	ticker := time.NewTicker(5 * time.Second)
	defer ticker.Stop()
RETRY:
	for {
		disabled, err := getKubeProxyDisabled(ctx, node, proxy)
		if err != nil {
			logrus.Infof("Failed to retrieve kube-proxy configuration: %v", err)
			for range ticker.C {
				continue RETRY
			}
		}
		return disabled
	}
}

type HTTPRequester func(u string, client *http.Client, username, password string) ([]byte, error)

func Request(path string, info *clientaccess.Info, requester HTTPRequester) ([]byte, error) {
	u, err := url.Parse(info.BaseURL)
	if err != nil {
		return nil, err
	}
	u.Path = path
	return requester(u.String(), clientaccess.GetHTTPClient(info.CACerts), info.Username, info.Password)
}