-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for customer SA namespace in snap meta lister tool #81
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Rakshith-R The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @Rakshith-R. Thanks for your PR. I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good functional addition.
Some minor issues...
pkg/iterator/iter.go
Outdated
func (iter *iterator) createSecurityToken(ctx context.Context, | ||
serviceAccount, | ||
serviceAccountNamespace, | ||
audience string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please don't break the arguments over multiple lines.
- Since you've introduced
serviceAccountNamespace
please renameserviceAccount
toserviceAccountName
. It would be acceptable to shorten these tosaName
andsaNamespace
. - If possible, put the namespace argument before the name argument.
pkg/iterator/iter.go
Outdated
securityToken, err := iter.h.createSecurityToken(ctx, | ||
serviceAccount, | ||
serviceAccountNamespace, | ||
smsCR.Spec.Audience) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please stick with the style: I generally avoid multiple lines in a function call except if an argument data structure is assembled as part of the call. Exceptions are allowed of course, when the argument list gets complex, but this is not such a case.
pkg/iterator/iter.go
Outdated
tokenRequest := authv1.TokenRequest{ | ||
Spec: authv1.TokenRequestSpec{ | ||
Audiences: []string{audience}, | ||
ExpirationSeconds: &iter.TokenExpirySecs, | ||
}, | ||
} | ||
|
||
tokenResp, err := iter.KubeClient.CoreV1().ServiceAccounts(iter.Namespace).CreateToken(ctx, serviceAccount, &tokenRequest, apimetav1.CreateOptions{}) | ||
tokenResp, err := iter.KubeClient.CoreV1().ServiceAccounts(serviceAccountNamespace). | ||
CreateToken(ctx, serviceAccount, &tokenRequest, apimetav1.CreateOptions{}) | ||
if err != nil { | ||
return "", fmt.Errorf("ServiceAccounts.CreateToken(%s): %v", serviceAccount, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should change the error message to:
fmt.Errorf("ServiceAccounts.CreateToken(%s/%s): %v", serviceAccountNamespace, serviceAccount, err)
pkg/iterator/iter.go
Outdated
// ServiceAccountNamespace is the namespace of the ServiceAccount. | ||
ServiceAccountNamespace string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This is optional and should be stated so. I suggest combining the comment for the two as follows:
// Specify the ServiceAccount object used to construct a security token
// with the audience string from the SnapshotMetadataService CR.
// If either of the following fields are unspecified, the default for the given client will be used.
ServiceAccountNamespace string
ServiceAccount string
It would be good if ServiceAccount
was renamed to ServiceAccountName
.
- The
args.Validate
function should be enhanced to ensure that either both fields are empty or both are set - impacts validation UTs too.
pkg/iterator/iter.go
Outdated
@@ -191,9 +194,10 @@ func newIterator(args Args) *iterator { | |||
func (iter *iterator) run(ctx context.Context) error { | |||
var err error | |||
|
|||
serviceAccount := iter.ServiceAccount // optional field | |||
serviceAccount := iter.ServiceAccount // optional field | |||
serviceAccountNamespace := iter.ServiceAccountNamespace // optional field | |||
if serviceAccount == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for an empty name (only) is fine as long as args.Validate
ensures both or none semantics.
b0c095e
to
9c56b79
Compare
Signed-off-by: Rakshith R <[email protected]>
9c56b79
to
6623cdb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Minor nits ...
case a.SANamespace == "" && a.SAName != "": | ||
return fmt.Errorf("%w: ServiceAccountName provided but ServiceAccountNamespace missing", ErrInvalidArgs) | ||
case a.SANamespace != "" && a.SAName == "": | ||
return fmt.Errorf("%w: ServiceAccountNamespace provided but ServiceAccountName missing", ErrInvalidArgs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The error message should refer to the fields - you're now calling them SAName
and SANamespace
and not ServiceAccountName
and ServiceAccountNamespace
@@ -242,20 +248,19 @@ func (iter *iterator) run(ctx context.Context) error { | |||
return err | |||
} | |||
|
|||
func (iter *iterator) getDefaultServiceAccount(ctx context.Context) (string, error) { | |||
func (iter *iterator) getDefaultServiceAccount(ctx context.Context) (string, string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could you please make it clear in the function signature which return argument is the name and which is the namespace? e.g.
func (iter *iterator) getDefaultServiceAccount(ctx context.Context) (namespace string, name string, err error)
What type of PR is this?
/kind bug
What this PR does / why we need it:
Add support for customer SA namespace in snap meta lister tool.
Currently SA namespace is picked up from snapshot namespace which is very limiting.
Special notes for your reviewer:
Does this PR introduce a user-facing change?: