-
Notifications
You must be signed in to change notification settings - Fork 10
Tags support for elbv2-controller resources #42
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
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 |
---|---|---|
|
@@ -15,13 +15,19 @@ package load_balancer | |
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
svcapitypes "github.com/aws-controllers-k8s/elbv2-controller/apis/v1alpha1" | ||
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" | ||
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
svcsdk "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" | ||
svcsdktypes "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types" | ||
"github.com/aws-controllers-k8s/elbv2-controller/pkg/resource/tags" | ||
) | ||
|
||
var( | ||
RequeueAfterUpdateDuration = 5 * time.Second | ||
) | ||
|
||
// setResourceAdditionalFields will describe the fields that are not return by the | ||
|
@@ -126,7 +132,11 @@ func (rm *resourceManager) customUpdateLoadBalancer( | |
} | ||
} | ||
// Leaving room for tag updates... | ||
// if delta.DifferentAt("Spec.Tags") {...} | ||
if delta.DifferentAt("Spec.Tags") { | ||
if err := rm.updateLoadBalancerTags(ctx, desired, latest); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return desired, nil | ||
} | ||
|
@@ -169,3 +179,58 @@ func (rm *resourceManager) updateLoadBalancerAttributes( | |
} | ||
return nil | ||
} | ||
|
||
func (rm *resourceManager) getTags( | ||
ctx context.Context, | ||
resourceARN string, | ||
) ([]*svcapitypes.Tag, error) { | ||
return tags.GetResourceTags(ctx, rm.sdkapi, rm.metrics, resourceARN ) | ||
} | ||
|
||
func (rm *resourceManager) updateTags( | ||
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. where is this used? |
||
ctx context.Context, | ||
desired *resource, | ||
latest *resource, | ||
) (err error) { | ||
rlog := ackrtlog.FromContext(ctx) | ||
exit := rlog.Trace("rm.describeTargets") | ||
defer func() { exit(err) }() | ||
return tags.SyncRecourseTags(ctx, rm.sdkapi, rm.metrics, string(*desired.ko.Status.ACKResourceMetadata.ARN), desired.ko.Spec.Tags, latest.ko.Spec.Tags) | ||
} | ||
|
||
// updateLoadBalancerTags updates the tags of the load balancer. | ||
func (rm *resourceManager) updateLoadBalancerTags( | ||
ctx context.Context, | ||
desired *resource, | ||
latest *resource, | ||
) error { | ||
rlog := ackrtlog.FromContext(ctx) | ||
exit := rlog.Trace("rm.updateLoadBalancerTags") | ||
var err error | ||
defer func() { exit(err) }() | ||
|
||
currentTags, err := rm.getTags( | ||
ctx, | ||
string(*desired.ko.Status.ACKResourceMetadata.ARN), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
desiredTags := []*svcapitypes.Tag{} | ||
for _, tag := range desired.ko.Spec.Tags { | ||
desiredTags = append(desiredTags, &svcapitypes.Tag{ | ||
Key: tag.Key, | ||
Value: tag.Value, | ||
}) | ||
} | ||
|
||
return tags.SyncRecourseTags( | ||
ctx, | ||
rm.sdkapi, | ||
rm.metrics, | ||
string(*desired.ko.Status.ACKResourceMetadata.ARN), | ||
currentTags, | ||
desiredTags, | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.