-
Notifications
You must be signed in to change notification settings - Fork 30
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
controller: bugfix aws oidc secret upsert process #397
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Xiaolin Lin <xlin158@bloomberg.net>
Can you write a test? |
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.
Thank you for putting up a fix for this bug! Just minor comments added 🙇
|
||
return r.client.Update(ctx, secret) | ||
} else { | ||
r.logger.Info(fmt.Sprintf("creating aws secret %s for backend security policy namespace: %s, name: %s", |
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.
Could you change the log to specify new aws credential secret
? or however to make it clear that a new secret containing aws credentials will be created
return fmt.Errorf("failed to create secret: %w", err) | ||
} | ||
if secretFound { | ||
r.logger.Info(fmt.Sprintf("updating aws secret %s for backend security policy namespace: %s, name: %s", |
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.
similar to below
if err != nil { | ||
if !apierrors.IsNotFound(err) { | ||
return 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.
Consider adding a comment to explain this? (Could also add it on line 133?)
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.
How about rewrite the code to
if err == nil {
updateSecret
} else if apierrors.IsNotFound(err) {
createSecret
}
@@ -130,11 +130,15 @@ func (r *AWSOIDCRotator) Rotate(ctx context.Context, token string) error { | |||
return err | |||
} | |||
|
|||
secretFound := true |
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.
I think the code can be written without using this variable.
if err != nil { | ||
if !apierrors.IsNotFound(err) { | ||
return 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.
How about rewrite the code to
if err == nil {
updateSecret
} else if apierrors.IsNotFound(err) {
createSecret
}
Commit Message
This commit fixes the bug when creating secret for AWS OIDC rotation and streamlines secret upsert operation into Kubernetes.
Detailed explanation:
In aws_oidc_rotator.go [1], existing buggy code snippet:
The intention of above code is to create secret regardless of its existence, then check if k8s returns
AlreadyExist
error.However, k8s returns
BadRequest
error with messageresourceVersion can not be set for Create requests
if debug through and inspect err at [2]Discussed with original commit author and fixed the bug by changing secret upsert process with a control flag to improve readability instead of a quick fix to switch condition from
errors.IsAlreadyExists
toerrors.IsBadRequest
.Related Issues/PRs (if applicable)
Related PR: #306
1:
ai-gateway/internal/controller/rotators/aws_oidc_rotator.go
Lines 162 to 168 in 1192716
2:
ai-gateway/internal/controller/rotators/aws_oidc_rotator.go
Line 164 in 1192716