// Execute removes old service account tokens.
Execute removes old service account tokens.
// Execute removes old service account tokens .
func (p *tokensExecutor) Execute(ctx context.Context) error {
	p.Progress.NextStep("Cleaning up Kubernetes service account tokens")
	secrets, err := p.Client.CoreV1().Secrets(constants.AllNamespaces).List(ctx, metav1.ListOptions{})
	if err != nil {
		return rigging.ConvertError(err)
	}
	for _, secret := range secrets.Items {
		if secret.Type != v1.SecretTypeServiceAccountToken {
			p.Infof("Skipping secret %v/%v", secret.Namespace, secret.Name)
			continue
		}
		if secret.Namespace == metav1.NamespaceSystem && strings.Contains(secret.Name, "controller") {
			p.Infof("Skipping secret %v/%v", secret.Namespace, secret.Name)
			continue
		}
		err := p.Client.CoreV1().Secrets(secret.Namespace).Delete(ctx, secret.Name, metav1.DeleteOptions{})
		if err != nil {
			return trace.Wrap(err, "failed to remove secret %v/%v: %v", secret.Namespace, secret.Name, err)
		} else {
			p.Infof("Removed secret %v/%v", secret.Namespace, secret.Name)
		}
	}
	return nil
}
func ( p * tokensExecutor ) Execute ( ctx context . Context ) error { p . Progress . NextStep ( " " ) secrets , err := p . Client . CoreV1 ( ) . Secrets ( constants . AllNamespaces ) . List ( ctx , metav1 . ListOptions { } ) if err != nil { return rigging . ConvertError ( err ) } for _ , secret := range secrets . Items { if secret . Type != v1 . SecretTypeServiceAccountToken { p . Infof ( " " , secret . Namespace , secret . Name ) continue } if secret . Namespace == metav1 . NamespaceSystem && strings . Contains ( secret . Name , " " ) { p . Infof ( " " , secret . Namespace , secret . Name ) continue } err := p . Client . CoreV1 ( ) . Secrets ( secret . Namespace ) . Delete ( ctx , secret . Name , metav1 . DeleteOptions { } ) if err != nil { return trace . Wrap ( err , " " , secret . Namespace , secret . Name , err ) } else { p . Infof ( " " , secret . Namespace , secret . Name ) } } return nil }
Execute removes old service account tokens.
Execute removes old service account tokens .
// Remove service account tokens. // Only remove service account tokens. // Do not remove tokens for system controllers, Kubernetes will refresh those on its own.