Skip to content

Commit b52c557

Browse files
authored
prevent DB Instance desired field state flapping (#151)
Both ModifyDBInstance and DescribeDBInstances returns a DBInstance struct that contains the *previously set* values for various mutable fields. This is problematic because it causes a "flopping" behaviour when the user has modified a Spec field from value A to value B but the output shape from ModifyDBInstance for that field contains value A, the standard SetOutput Go code generated above will set the Spec field to the *old* value again. The next time the reconciler runs, it will read the latest observed resource, see a difference between the desired and the latest state (that actually does not exist because the difference is comparing the value of the fields before they were changed) and attempt to modify the field from value B to value A again, causing a flop loop. Luckily, the Output shape's DBInstance struct contains a `PendingModifiedValues` struct which contains those field values that the user specified. So, we can use these to "reset" the Spec back to the appropriate user-specified values. This commit does exactly this. It looks in the `PendingModifiedValues` struct for any non-nil field that matches a field in the `Spec` and if it finds a match, sets the `Spec` field to the value in `PendingModifiedValues`. This solves the flapping problem for all of the fields in `PendingModifiedValues`, including `DBInstanceClass`, `AllocatedStorage`, `MultiAZ` and `StorageType`. Fixes Issue aws-controllers-k8s/community#1773 Fixes Issue aws-controllers-k8s/community#1716 Fixes Issue aws-controllers-k8s/community#1376 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 9867f34 commit b52c557

File tree

18 files changed

+457
-38
lines changed

18 files changed

+457
-38
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ack_generate_info:
2-
build_date: "2023-05-01T22:38:52Z"
3-
build_hash: 6657565bb742e5cd4cd340d01d5e4786b5fbabc0
4-
go_version: go1.19
5-
version: v0.26.0
2+
build_date: "2023-05-11T22:58:32Z"
3+
build_hash: 9e2542cf2c0f92c014524c269474055cca758d70
4+
go_version: go1.19.4
5+
version: v0.26.0-3-g9e2542c
66
api_directory_checksum: b3f33aebf366349bde7945f7b627ae788a18c0d5
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.232

config/controller/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ spec:
7373
capabilities:
7474
drop:
7575
- ALL
76+
securityContext:
77+
seccompProfile:
78+
type: RuntimeDefault
7679
terminationGracePeriodSeconds: 10
7780
serviceAccountName: ack-rds-controller
7881
hostIPC: false

helm/crds/services.k8s.aws_adoptedresources.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ spec:
145145
blockOwnerDeletion:
146146
description: If true, AND if the owner has the "foregroundDeletion"
147147
finalizer, then the owner cannot be deleted from the
148-
key-value store until this reference is removed. See
149-
https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion
150-
for how the garbage collector interacts with this
151-
field and enforces the foreground deletion. Defaults
148+
key-value store until this reference is removed. Defaults
152149
to false. To set this field, a user needs "delete"
153150
permission of the owner, otherwise 422 (Unprocessable
154151
Entity) will be returned.

helm/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ If release name contains chart name it will be used as a full name.
3333

3434
{{- define "watch-namespace" -}}
3535
{{- if eq .Values.installScope "namespace" -}}
36-
{{- .Release.Namespace -}}
36+
{{ .Values.watchNamespace | default .Release.Namespace }}
3737
{{- end -}}
3838
{{- end -}}
3939

helm/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ spec:
116116
capabilities:
117117
drop:
118118
- ALL
119+
securityContext:
120+
seccompProfile:
121+
type: RuntimeDefault
119122
terminationGracePeriodSeconds: 10
120123
nodeSelector: {{ toYaml .Values.deployment.nodeSelector | nindent 8 }}
121124
{{ if .Values.deployment.tolerations -}}

helm/values.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@
196196
"type": "string",
197197
"enum": ["cluster", "namespace"]
198198
},
199+
"watchNamespace": {
200+
"type": "string"
201+
},
199202
"resourceTags": {
200203
"type": "array",
201204
"items": {

helm/values.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ deployment:
3131

3232
# If "installScope: cluster" then these labels will be applied to ClusterRole
3333
role:
34-
labels: {}
34+
labels: {}
3535

3636
metrics:
3737
service:
@@ -72,6 +72,10 @@ log:
7272
# cluster wide.
7373
installScope: cluster
7474

75+
# Set the value of the "namespace" to be watched by the controller
76+
# This value is only used when the `installScope` is set to "namespace". If left empty, the default value is the release namespace for the chart.
77+
watchNamespace: ""
78+
7579
resourceTags:
7680
# Configures the ACK service controller to always set key/value pairs tags on
7781
# resources that it manages.

pkg/resource/db_cluster/resource.go

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

pkg/resource/db_cluster_parameter_group/resource.go

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

pkg/resource/db_instance/resource.go

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

0 commit comments

Comments
 (0)