Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ resources:
code: customPreCompare(delta, a, b)
sdk_read_many_post_set_output:
template_path: hooks/load_balancer/sdk_read_many_post_set_output.go.tpl
sdk_create_post_set_output:
template_path: hooks/load_balancer/sdk_create_post_set_output.go.tpl
sdk_update_pre_build_request:
template_path: hooks/load_balancer/sdk_update_pre_build_request.go.tpl
sdk_read_many_post_build_request:
template_path: hooks/load_balancer/sdk_update_post_build_request.go.tpl
Listener:
fields:
DefaultActions.TargetGroupARN:
Expand Down Expand Up @@ -162,6 +168,10 @@ resources:
hooks:
sdk_read_many_post_build_request:
template_path: hooks/listener/sdk_read_many_post_build_request.go.tpl
sdk_create_post_set_output:
template_path: hooks/listener/sdk_create_post_set_output.go.tpl
sdk_update_pre_build_request:
template_path: hooks/target_group/sdk_update_pre_build_request.go.tpl
TargetGroup:
fields:
Name:
Expand Down Expand Up @@ -234,3 +244,5 @@ resources:
template_path: hooks/rule/sdk_update_pre_build_request.go.tpl
sdk_read_many_post_set_output:
template_path: hooks/rule/sdk_read_many_post_set_output.go.tpl
sdk_create_post_build_request:
template_path: hooks/rule/sdk_create_post_build_request.go.tpl
31 changes: 31 additions & 0 deletions pkg/resource/listener/hooks.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
package listener

import (
"context"
"time"

ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
"github.com/aws-controllers-k8s/elbv2-controller/pkg/resource/tags"
svcapitypes "github.com/aws-controllers-k8s/elbv2-controller/apis/v1alpha1"
)

var (
RequeueAfterUpdateDuration = 5 * time.Second
)

// customCheckRequiredFieldsMissingMethod returns true if there are any fields
// for the ReadOne Input shape that are required but not present in the
// resource's Spec or Status.
Expand All @@ -8,3 +21,21 @@ func (rm *resourceManager) customCheckRequiredFieldsMissingMethod(
) bool {
return r.Identifiers().ARN() == 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(
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)
}
18 changes: 17 additions & 1 deletion pkg/resource/listener/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 66 additions & 1 deletion pkg/resource/load_balancer/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The 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,
)
}
7 changes: 7 additions & 0 deletions pkg/resource/load_balancer/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions pkg/resource/rule/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ import (
"context"
"errors"
"strconv"
"time"

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"
svcapitypes "github.com/aws-controllers-k8s/elbv2-controller/apis/v1alpha1"
"github.com/aws-controllers-k8s/elbv2-controller/pkg/resource/tags"
)

var (
// ErrInvalidPriority is an error that is returned when the priority value is invalid.
ErrInvalidPriority = errors.New("invalid priority value")
RequeueAfterUpdateDuration = 5 * time.Second
)

// setRulePriority sets the priority of the rule.
Expand Down Expand Up @@ -81,3 +85,21 @@ func int32OrNil(val *int64) *int32 {
}
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(
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)
}
16 changes: 16 additions & 0 deletions pkg/resource/rule/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading