Skip to content

Commit 916558e

Browse files
authored
Include CachePolicyConfig quantities in create and update requests (#31)
Fixes: aws-controllers-k8s/community#2025 CF controller is missing `CachePolicyConfig` header and cookie quantity fields. This patch adds a similar mechanism to what's used in Distribution and other resource in this controller. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 58dc7b4 commit 916558e

File tree

12 files changed

+80
-9
lines changed

12 files changed

+80
-9
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2024-02-19T19:45:25Z"
3-
build_hash: 9c8a01fdcb2bcf7448cd9f9549c8b480e424e927
2+
build_date: "2024-02-27T16:58:23Z"
3+
build_hash: c2165b65565ab3a094cfb474c4396f4d14c7ef1e
44
go_version: go1.22.0
5-
version: v0.30.0-6-g9c8a01f-dirty
5+
version: v0.31.0
66
api_directory_checksum: 86a18c0bfcc849ad234f64249fd8951ce418dd14
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.214
99
generator_config_info:
10-
file_checksum: 4faafc515699468a833ad70b7cbc8d2260477ea1
10+
file_checksum: 250151346bb9c7a0bcd8cdcdb77f482f2eee0d03
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ resources:
114114
template_path: hooks/cache_policy/sdk_read_one_post_set_output.go.tpl
115115
sdk_create_post_set_output:
116116
template_path: hooks/cache_policy/sdk_create_post_set_output.go.tpl
117+
sdk_create_post_build_request:
118+
template_path: hooks/cache_policy/sdk_create_post_build_request.go.tpl
117119
sdk_update_post_build_request:
118120
template_path: hooks/cache_policy/sdk_update_post_build_request.go.tpl
119121
sdk_update_post_set_output:

config/controller/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ kind: Kustomization
66
images:
77
- name: controller
88
newName: public.ecr.aws/aws-controllers-k8s/cloudfront-controller
9-
newTag: 0.0.7
9+
newTag: 0.0.8

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ resources:
114114
template_path: hooks/cache_policy/sdk_read_one_post_set_output.go.tpl
115115
sdk_create_post_set_output:
116116
template_path: hooks/cache_policy/sdk_create_post_set_output.go.tpl
117+
sdk_create_post_build_request:
118+
template_path: hooks/cache_policy/sdk_create_post_build_request.go.tpl
117119
sdk_update_post_build_request:
118120
template_path: hooks/cache_policy/sdk_update_post_build_request.go.tpl
119121
sdk_update_post_set_output:

helm/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apiVersion: v1
22
name: cloudfront-chart
33
description: A Helm chart for the ACK service controller for Amazon CloudFront (CloudFront)
4-
version: 0.0.7
5-
appVersion: 0.0.7
4+
version: 0.0.8
5+
appVersion: 0.0.8
66
home: https://github.com/aws-controllers-k8s/cloudfront-controller
77
icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png
88
sources:

helm/templates/NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{ .Chart.Name }} has been installed.
2-
This chart deploys "public.ecr.aws/aws-controllers-k8s/cloudfront-controller:0.0.7".
2+
This chart deploys "public.ecr.aws/aws-controllers-k8s/cloudfront-controller:0.0.8".
33

44
Check its status by running:
55
kubectl --namespace {{ .Release.Namespace }} get pods -l "app.kubernetes.io/instance={{ .Release.Name }}"

helm/values.yaml

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

55
image:
66
repository: public.ecr.aws/aws-controllers-k8s/cloudfront-controller
7-
tag: 0.0.7
7+
tag: 0.0.8
88
pullPolicy: IfNotPresent
99
pullSecrets: []
1010

pkg/resource/cache_policy/hooks.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 cache_policy
15+
16+
import (
17+
svcsdk "github.com/aws/aws-sdk-go/service/cloudfront"
18+
)
19+
20+
// setQuantityFields simply goes through the input shape and sets the Quantity
21+
// field for all list container parent shapes to the length of the Items field.
22+
// This is necessary because CloudFront's API will return an
23+
// `InconsistentQuantities` error message if Quantity != len(Items). This is
24+
// why we can't have nice things, apparently.
25+
func setQuantityFields(cp *svcsdk.CachePolicyConfig) {
26+
if cp == nil {
27+
return
28+
}
29+
if cp.ParametersInCacheKeyAndForwardedToOrigin != nil {
30+
cpp := cp.ParametersInCacheKeyAndForwardedToOrigin
31+
if cpp.CookiesConfig != nil {
32+
if cpp.CookiesConfig.Cookies != nil {
33+
cpp.CookiesConfig.Cookies.SetQuantity(int64(len(cpp.CookiesConfig.Cookies.Items)))
34+
}
35+
}
36+
if cpp.HeadersConfig != nil {
37+
if cpp.HeadersConfig.Headers != nil {
38+
cpp.HeadersConfig.Headers.SetQuantity(int64(len(cpp.HeadersConfig.Headers.Items)))
39+
}
40+
}
41+
if cpp.QueryStringsConfig != nil {
42+
if cpp.QueryStringsConfig.QueryStrings != nil {
43+
cpp.QueryStringsConfig.QueryStrings.SetQuantity(int64(len(cpp.QueryStringsConfig.QueryStrings.Items)))
44+
}
45+
}
46+
}
47+
}

pkg/resource/cache_policy/sdk.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// ¯\\\_(ツ)_/¯
2+
setQuantityFields(input.CachePolicyConfig)

0 commit comments

Comments
 (0)