Skip to content

Commit 2121324

Browse files
committed
Add e2e tests for pipe resource
Signed-off-by: Amine Hilaly <hilalyamine@gmail.com>
1 parent 858d9fd commit 2121324

File tree

15 files changed

+393
-24
lines changed

15 files changed

+393
-24
lines changed

OWNERS_ALIASES

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# See the OWNERS docs at https://go.k8s.io/owners#owners_aliases
22

33
aliases:
4-
#emeritus_approvers:
5-
# - jaypipes
64
core-ack-team:
75
- a-hilaly
86
- RedbackThomson
9-
- vijtrip2
7+
- jaypipes
8+
- jljaco
109
service-team:
1110
- embano1
1211
- baldawar
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2023-03-10T16:01:20Z"
3-
build_hash: e371c4907f3a600b344b4fe2089ea6f47252309b
4-
go_version: go1.19.5
5-
version: v0.24.3-2-ge371c49
6-
api_directory_checksum: 4f1d7bb939ae0dff35a8ea8c96b15a150f40c60d
2+
build_date: "2023-03-14T23:37:52Z"
3+
build_hash: 0888419ec6825035cae1fdee2ceffd7c1ac73ca8
4+
go_version: go1.20
5+
version: v0.24.3-5-g0888419
6+
api_directory_checksum: 0501e26102bccaff71f18fddd72d0e48a5fdeeb6
77
api_version: v1alpha1
8-
aws_sdk_go_version: v1.44.209
8+
aws_sdk_go_version: v1.44.218
99
generator_config_info:
10-
file_checksum: 42f88108ea7243cba5c1a57aeb7e697df4466e87
10+
file_checksum: 43c88522fc802a0f70ed4c695964dfdca1a2fea2
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,5 @@ resources:
5757
json_path: .status.currentState
5858
type: string
5959
exceptions:
60-
errors:
61-
404:
62-
code: ""
63-
message_suffix: "does not exist."
6460
terminal_codes:
6561
- ValidationException

generator.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,5 @@ resources:
5757
json_path: .status.currentState
5858
type: string
5959
exceptions:
60-
errors:
61-
404:
62-
code: ""
63-
message_suffix: "does not exist."
6460
terminal_codes:
6561
- ValidationException

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/aws-controllers-k8s/runtime v0.24.1
7-
github.com/aws/aws-sdk-go v1.44.209
7+
github.com/aws/aws-sdk-go v1.44.218
88
github.com/go-logr/logr v1.2.3
99
github.com/spf13/pflag v1.0.5
1010
k8s.io/api v0.26.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
4040
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
4141
github.com/aws-controllers-k8s/runtime v0.24.1 h1:vmOWKlo4oPtPxeofRnd/dA49WR5VZSqSxHiSiNTiknY=
4242
github.com/aws-controllers-k8s/runtime v0.24.1/go.mod h1:jizDzKikL09cueIuA9ZxoZ+4pfn5U7oKW5s/ZAqOA6E=
43-
github.com/aws/aws-sdk-go v1.44.209 h1:wZuiaA4eaqYZmoZXqGgNHqVD7y7kUGFvACDGBgowTps=
44-
github.com/aws/aws-sdk-go v1.44.209/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
43+
github.com/aws/aws-sdk-go v1.44.218 h1:p707+xOCazWhkSpZOeyhtTcg7Z+asxxvueGgYPSitn4=
44+
github.com/aws/aws-sdk-go v1.44.218/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
4545
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
4646
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
4747
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=

pkg/resource/pipe/hooks.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ import (
2525
svcapitypes "github.com/aws-controllers-k8s/pipes-controller/apis/v1alpha1"
2626
)
2727

28+
// _____ _ _____ _ _____ ____ ____ _ ____ _____ _____
29+
// / __// \ |\/ __// \ /|/__ __\/ _ \/ __\/ \/ _ \/ __// __/
30+
// | \ | | //| \ | |\ || / \ | | //| \/|| || | \|| | _| \
31+
// | /_ | \// | /_ | | \|| | | | |_\\| /| || |_/|| |_//| /_
32+
// \____\\__/ \____\\_/ \| \_/ \____/\_/\_\\_/\____/\____\\____\
33+
//
34+
// _ _ _ ____ ___ __ _ ____ _ ____ _____ ____
35+
// \||/ / |/ _ \\ \//\||/ / __\/ \/ __\/ __// ___\
36+
// | || / \| \ / | \/|| || \/|| \ | \
37+
// /\_| || |-|| / / | __/| || __/| /_ \___ |
38+
// \____/\_/ \|/_/ \_/ \_/\_/ \____\\____/
39+
2840
const (
2941
defaultRequeueDelay = time.Second * 5
3042
)

pkg/resource/pipe/hooks_tags.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package pipe
15+
16+
import (
17+
"context"
18+
19+
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
20+
svcsdk "github.com/aws/aws-sdk-go/service/pipes"
21+
)
22+
23+
// updatePipeTags uses TagResource and UntagResource to add, remove and update
24+
// a pipe tags.
25+
func (rm *resourceManager) updatePipeTags(
26+
ctx context.Context,
27+
latest *resource,
28+
desired *resource,
29+
) error {
30+
var err error
31+
rlog := ackrtlog.FromContext(ctx)
32+
exit := rlog.Trace("rm.updatePipeTags")
33+
defer exit(err)
34+
35+
addedOrUpdated, removed := compareMaps(latest.ko.Spec.Tags, desired.ko.Spec.Tags)
36+
37+
if len(removed) > 0 {
38+
input := &svcsdk.UntagResourceInput{
39+
ResourceArn: (*string)(desired.ko.Status.ACKResourceMetadata.ARN),
40+
TagKeys: removed,
41+
}
42+
_, err = rm.sdkapi.UntagResourceWithContext(ctx, input)
43+
rm.metrics.RecordAPICall("UPDATE", "UntagResource", err)
44+
if err != nil {
45+
return err
46+
}
47+
}
48+
49+
if len(addedOrUpdated) > 0 {
50+
input := &svcsdk.TagResourceInput{
51+
ResourceArn: (*string)(desired.ko.Status.ACKResourceMetadata.ARN),
52+
Tags: addedOrUpdated,
53+
}
54+
_, err = rm.sdkapi.TagResourceWithContext(ctx, input)
55+
rm.metrics.RecordAPICall("UPDATE", "TagResource", err)
56+
if err != nil {
57+
return err
58+
}
59+
}
60+
61+
return nil
62+
}
63+
64+
// compareMaps compares two string to string maps and returns three outputs: a
65+
// map of the new key/values observed, a list of the keys of the removed values
66+
// and a map containing the updated keys and their new values.
67+
func compareMaps(
68+
a map[string]*string,
69+
b map[string]*string,
70+
) (addedOrUpdated map[string]*string, removed []*string) {
71+
addedOrUpdated = make(map[string]*string)
72+
visited := make(map[string]bool, len(a))
73+
for keyA, valueA := range a {
74+
valueB, found := b[keyA]
75+
if !found {
76+
removed = append(removed, &keyA)
77+
continue
78+
}
79+
if *valueA != *valueB {
80+
addedOrUpdated[keyA] = valueB
81+
}
82+
visited[keyA] = true
83+
}
84+
for keyB, valueB := range b {
85+
_, found := a[keyB]
86+
if !found {
87+
addedOrUpdated[keyB] = valueB
88+
}
89+
}
90+
return
91+
}

pkg/resource/pipe/sdk.go

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/hooks/pipe/sdk_update_pre_build_request.go.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ if pipeInMutatingState(latest) {
99
if !delta.DifferentExcept("Spec.CurrentState") {
1010
return latest, requeueWaitWhileUpdating
1111
}
12+
13+
if delta.DifferentAt("Spec.Tags") {
14+
err = rm.updatePipeTags(ctx, latest, desired)
15+
if err != nil {
16+
return nil, err
17+
}
18+
}
19+
20+
// If no other differences were observe, avoid making UpdatePipe API calls.
21+
if !delta.DifferentExcept("Spec.Tags") {
22+
return desired, nil
23+
}

0 commit comments

Comments
 (0)