func NewManager(c clientset.Interface) *Manager {
	// check whether the server supports token requests so we can give a more helpful error message
	supported := false
	once := &sync.Once{}
	tokenRequestsSupported := func() bool {
		once.Do(func() {
			resources, err := c.Discovery().ServerResourcesForGroupVersion("v1")
			if err != nil {
				return
			}
			for _, resource := range resources.APIResources {
				if resource.Name == "serviceaccounts/token" {
					supported = true
					return
				}
			}
		})
		return supported
	}

	m := &Manager{
		getToken: func(name, namespace string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error) {
			if c == nil {
				return nil, errors.New("cannot use TokenManager when kubelet is in standalone mode")
			}
			tokenRequest, err := c.CoreV1().ServiceAccounts(namespace).CreateToken(context.TODO(), name, tr, metav1.CreateOptions{})
			if apierrors.IsNotFound(err) && !tokenRequestsSupported() {
				return nil, fmt.Errorf("the API server does not have TokenRequest endpoints enabled")
			}
			return tokenRequest, err
		},
		cache: make(map[string]*authenticationv1.TokenRequest),
		clock: clock.RealClock{},
	}
	go wait.Forever(m.cleanup, gcPeriod)
	return m
}
// NewManager returns a new token manager.
NewManager returns a new token manager.
// NewManager returns a new token manager .
func NewManager(c clientset.Interface) *Manager {
	supported := false
	once := &sync.Once{}
	tokenRequestsSupported := func() bool {
		once.Do(func() {
			resources, err := c.Discovery().ServerResourcesForGroupVersion("v1")
			if err != nil {
				return
			}
			for _, resource := range resources.APIResources {
				if resource.Name == "serviceaccounts/token" {
					supported = true
					return
				}
			}
		})
		return supported
	}
	m := &Manager{
		getToken: func(name, namespace string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error) {
			if c == nil {
				return nil, errors.New("cannot use TokenManager when kubelet is in standalone mode")
			}
			tokenRequest, err := c.CoreV1().ServiceAccounts(namespace).CreateToken(context.TODO(), name, tr, metav1.CreateOptions{})
			if apierrors.IsNotFound(err) && !tokenRequestsSupported() {
				return nil, fmt.Errorf("the API server does not have TokenRequest endpoints enabled")
			}
			return tokenRequest, err
		},
		cache: make(map[string]*authenticationv1.TokenRequest),
		clock: clock.RealClock{},
	}
	go wait.Forever(m.cleanup, gcPeriod)
	return m
}
func NewManager ( c clientset . Interface ) * Manager { supported := false once := & sync . Once { } tokenRequestsSupported := func ( ) bool { once . Do ( func ( ) { resources , err := c . Discovery ( ) . ServerResourcesForGroupVersion ( " " ) if err != nil { return } for _ , resource := range resources . APIResources { if resource . Name == " " { supported = true return } } } ) return supported } m := & Manager { getToken : func ( name , namespace string , tr * authenticationv1 . TokenRequest ) ( * authenticationv1 . TokenRequest , error ) { if c == nil { return nil , errors . New ( " " ) } tokenRequest , err := c . CoreV1 ( ) . ServiceAccounts ( namespace ) . CreateToken ( context . TODO ( ) , name , tr , metav1 . CreateOptions { } ) if apierrors . IsNotFound ( err ) && ! tokenRequestsSupported ( ) { return nil , fmt . Errorf ( " " ) } return tokenRequest , err } , cache : make ( map [ string ] * authenticationv1 . TokenRequest ) , clock : clock . RealClock { } , } go wait . Forever ( m . cleanup , gcPeriod ) return m }
NewManager returns a new token manager.
NewManager returns a new token manager .
// check whether the server supports token requests so we can give a more helpful error message