func KubeServerVersion(discoveryCl discovery.DiscoveryInterface, retryTimeout time.Duration) (*version.Info, error) {
	if serverVersion, found := cache.Cache.Get(serverVersionCacheKey); found {
		return serverVersion.(*version.Info), nil
	}

	serverVersion, err := newKubeServerVersion(retryTimeout, discoveryCl.ServerVersion)
	if err != nil {
		return nil, err
	}

	ctx, cancel := context.WithTimeout(context.Background(), retryTimeout)
	defer cancel()

	for {
		err := serverVersion.retrier.TriggerRetry()
		switch serverVersion.retrier.RetryStatus() {
		case retry.OK:
			cache.Cache.Set(serverVersionCacheKey, serverVersion.info, time.Hour)
			return serverVersion.info, nil
		case retry.PermaFail:
			return nil, err
		default:
			sleepFor := serverVersion.retrier.NextRetry().UTC().Sub(time.Now().UTC()) + time.Second
			log.Debugf("Waiting for getting Kubernetes server version, next retry: %v", sleepFor)
			select {
			case <-ctx.Done():
				return nil, fmt.Errorf("timeout reached while waiting for Kubernetes server version, last error: %w", err)
			case <-time.After(sleepFor):
			}
		}
	}
}
// KubeServerVersion returns the version of the kubernetes server using a Discovery Client.
// It retries with an exponential backoff until timeout.
// It caches the result in memory for 1 hour.
KubeServerVersion returns the version of the kubernetes server using a Discovery Client.
It retries with an exponential backoff until timeout.
It caches the result in memory for 1 hour.
// KubeServerVersion returns the version of the kubernetes server using a Discovery Client . // It retries with an exponential backoff until timeout . // It caches the result in memory for 1 hour .
func KubeServerVersion(discoveryCl discovery.DiscoveryInterface, retryTimeout time.Duration) (*version.Info, error) {
	if serverVersion, found := cache.Cache.Get(serverVersionCacheKey); found {
		return serverVersion.(*version.Info), nil
	}
	serverVersion, err := newKubeServerVersion(retryTimeout, discoveryCl.ServerVersion)
	if err != nil {
		return nil, err
	}
	ctx, cancel := context.WithTimeout(context.Background(), retryTimeout)
	defer cancel()
	for {
		err := serverVersion.retrier.TriggerRetry()
		switch serverVersion.retrier.RetryStatus() {
		case retry.OK:
			cache.Cache.Set(serverVersionCacheKey, serverVersion.info, time.Hour)
			return serverVersion.info, nil
		case retry.PermaFail:
			return nil, err
		default:
			sleepFor := serverVersion.retrier.NextRetry().UTC().Sub(time.Now().UTC()) + time.Second
			log.Debugf("Waiting for getting Kubernetes server version, next retry: %v", sleepFor)
			select {
			case <-ctx.Done():
				return nil, fmt.Errorf("timeout reached while waiting for Kubernetes server version, last error: %w", err)
			case <-time.After(sleepFor):
			}
		}
	}
}
func KubeServerVersion ( discoveryCl discovery . DiscoveryInterface , retryTimeout time . Duration ) ( * version . Info , error ) { if serverVersion , found := cache . Cache . Get ( serverVersionCacheKey ) ; found { return serverVersion . ( * version . Info ) , nil } serverVersion , err := newKubeServerVersion ( retryTimeout , discoveryCl . ServerVersion ) if err != nil { return nil , err } ctx , cancel := context . WithTimeout ( context . Background ( ) , retryTimeout ) defer cancel ( ) for { err := serverVersion . retrier . TriggerRetry ( ) switch serverVersion . retrier . RetryStatus ( ) { case retry . OK : cache . Cache . Set ( serverVersionCacheKey , serverVersion . info , time . Hour ) return serverVersion . info , nil case retry . PermaFail : return nil , err default : sleepFor := serverVersion . retrier . NextRetry ( ) . UTC ( ) . Sub ( time . Now ( ) . UTC ( ) ) + time . Second log . Debugf ( " " , sleepFor ) select { case <- ctx . Done ( ) : return nil , fmt . Errorf ( " " , err ) case <- time . After ( sleepFor ) : } } } }
KubeServerVersion returns the version of the kubernetes server using a Discovery Client.
KubeServerVersion returns the version of the kubernetes server using a Discovery Client .