Skip to content

Commit

Permalink
add custom sa not found
Browse files Browse the repository at this point in the history
Signed-off-by: rashmi_kh <[email protected]>
  • Loading branch information
rashmi43 committed Nov 18, 2024
1 parent 6062677 commit 738a59c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/authentication/tokengetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ type TokenGetter struct {

type TokenGetterOption func(*TokenGetter)

type SANotFoundError struct {
Msg string
}

func (e *SANotFoundError) Error() string {
return fmt.Sprintf(" %s", e.Msg)
}

const (
rotationThresholdFraction = 0.1
DefaultExpirationDuration = 5 * time.Minute
Expand Down Expand Up @@ -88,11 +96,10 @@ func (t *TokenGetter) getToken(ctx context.Context, key types.NamespacedName) (*
Spec: authenticationv1.TokenRequestSpec{ExpirationSeconds: ptr.To(int64(t.expirationDuration / time.Second))},
}, metav1.CreateOptions{})
if err != nil {
if errors.IsNotFound(err) {
var saNotFoundError = fmt.Errorf("service account not found")
return nil, saNotFoundError
}
return nil, err
errMsg := err.Error()
stripErrMsg := errMsg[strings.LastIndex(errMsg, ":")+1:]

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

View workflow job for this annotation

GitHub Actions / unit-test-basic

undefined: strings

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

View workflow job for this annotation

GitHub Actions / goreleaser

undefined: strings

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

View workflow job for this annotation

GitHub Actions / e2e-kind

undefined: strings

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

View workflow job for this annotation

GitHub Actions / lint

undefined: strings) (typecheck)

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

View workflow job for this annotation

GitHub Actions / lint

undefined: strings) (typecheck)

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

View workflow job for this annotation

GitHub Actions / lint

undefined: strings (typecheck)

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

View workflow job for this annotation

GitHub Actions / extension-developer-e2e

undefined: strings

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

View workflow job for this annotation

GitHub Actions / verify

undefined: strings

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

View workflow job for this annotation

GitHub Actions / upgrade-e2e

undefined: strings
saErr := &SANotFoundError{stripErrMsg}
return nil, saErr
}
return &req.Status, nil
}
Expand Down

0 comments on commit 738a59c

Please sign in to comment.