Skip to content

Commit

Permalink
update error message string
Browse files Browse the repository at this point in the history
Signed-off-by: rashmi_kh <[email protected]>
  • Loading branch information
rashmi43 committed Nov 19, 2024
1 parent 815115e commit 49549f2
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions internal/authentication/tokengetter.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package authentication

import (
"fmt"
"context"
"fmt"
"strings"
"sync"
"time"

authenticationv1 "k8s.io/api/authentication/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/utils/ptr"
)

Expand All @@ -23,16 +20,16 @@ type TokenGetter struct {
mu sync.RWMutex
}

type TokenGetterOption func(*TokenGetter)

type SANotFoundError struct {
Msg string
}

func (e *SANotFoundError) Error() string {
return fmt.Sprintf(" %s", e.Msg)
func (e *SANotFoundError) Error(serviceAccountName string) string {
return fmt.Sprintf(" Unable to authenticate with Kubernetes cluster using ServiceAccount \"%s\": ServiceAccount \"%s\" not found.", serviceAccountName, serviceAccountName)
}

type TokenGetterOption func(*TokenGetter)

const (
rotationThresholdFraction = 0.1
DefaultExpirationDuration = 5 * time.Minute
Expand Down Expand Up @@ -95,12 +92,10 @@ func (t *TokenGetter) getToken(ctx context.Context, key types.NamespacedName) (*
req, err := t.client.ServiceAccounts(key.Namespace).CreateToken(ctx,
key.Name,
&authenticationv1.TokenRequest{
Spec: authenticationv1.TokenRequestSpec{ExpirationSeconds: ptr.To(int64(t.expirationDuration / time.Second))},
Spec: authenticationv1.TokenRequestSpec{ExpirationSeconds: ptr.To[int64](int64(t.expirationDuration / time.Second))},
}, metav1.CreateOptions{})
if err != nil {
errMsg := err.Error()
stripErrMsg := errMsg[strings.LastIndex(errMsg, ":")+1:]
saErr := &SANotFoundError{stripErrMsg}
saErr := &SANotFoundError{key.Name}
return nil, saErr

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / unit-test-basic

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / e2e-kind

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / goreleaser

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / lint

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / lint

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / lint

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / verify

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / extension-developer-e2e

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)

Check failure on line 99 in internal/authentication/tokengetter.go

View workflow job for this annotation

GitHub Actions / upgrade-e2e

cannot use saErr (variable of type *SANotFoundError) as error value in return statement: *SANotFoundError does not implement error (wrong type for method Error)
}
return &req.Status, nil
Expand Down

0 comments on commit 49549f2

Please sign in to comment.