-
Notifications
You must be signed in to change notification settings - Fork 52
chore: allow PIA adoption by clusterName, namespace, and ServiceAccount #193
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,63 @@ | |
| package pod_identity_association | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/aws-controllers-k8s/eks-controller/pkg/tags" | ||
| ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" | ||
| svcsdk "github.com/aws/aws-sdk-go-v2/service/eks" | ||
| ) | ||
|
|
||
| var syncTags = tags.SyncTags | ||
|
|
||
| func (rm *resourceManager) getAssociationID(ctx context.Context, r *resource) (id *string, err error) { | ||
| rlog := ackrtlog.FromContext(ctx) | ||
| exit := rlog.Trace("rm.getSecretID") | ||
| defer func() { | ||
| exit(err) | ||
| }() | ||
|
|
||
| // ClusterName is a required field for ListPodIdentityAssociations operation | ||
| // we treat an undefined ClusterName as not found. | ||
| if r.ko.Spec.ClusterName == nil { | ||
| return nil, nil | ||
| } | ||
|
|
||
| resp, err := rm.sdkapi.ListPodIdentityAssociations(ctx, &svcsdk.ListPodIdentityAssociationsInput{ | ||
| ClusterName: r.ko.Spec.ClusterName, | ||
| Namespace: r.ko.Spec.Namespace, | ||
| ServiceAccount: r.ko.Spec.ServiceAccount, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // if more than one are returned, we don't want to manage them | ||
| // and treat it as not found | ||
| if len(resp.Associations) != 1 { | ||
| return nil, nil | ||
| } | ||
|
Comment on lines
+48
to
+52
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a terminal condition? if we are in adoption mode
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will just be marked as not found, instead of terminal in sdkFind. This way we can trigger a creation during |
||
|
|
||
| // expect Namespace, ClusterName, and ServiceAccount defined by the user | ||
| // to match the returned association | ||
| pia := resp.Associations[0] | ||
| if !isPtrEqual(pia.ClusterName, r.ko.Spec.ClusterName) || | ||
| !isPtrEqual(pia.Namespace, r.ko.Spec.Namespace) || | ||
| !isPtrEqual(pia.ServiceAccount, r.ko.Spec.ServiceAccount) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| return resp.Associations[0].AssociationId, nil | ||
|
|
||
| } | ||
|
|
||
| func isPtrEqual(a, b *string) bool { | ||
|
knottnt marked this conversation as resolved.
|
||
| // we expect both to be non-nil, return false otherwise | ||
| if a == nil { | ||
| return false | ||
| } | ||
| if b == nil { | ||
| return false | ||
| } | ||
| return *a == *b | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Retrieve podIdentityAssociation ID only during adoption | ||
| if r.ko.Status.AssociationID == nil && runtime.NeedAdoption(r) { | ||
| r.ko.Status.AssociationID, err = rm.getAssociationID(ctx, r) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.