-
Notifications
You must be signed in to change notification settings - Fork 43
fix update of maintenance window #43
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| ack_generate_info: | ||
| build_date: "2021-07-16T03:54:07Z" | ||
| build_date: "2021-07-16T19:55:47Z" | ||
| build_hash: 7832e9aa4a48565302cd440f4cdf2267f04adfed | ||
| go_version: go1.15.2 darwin/amd64 | ||
| version: v0.5.0 | ||
| api_directory_checksum: 04701e412e7e4597466c1d56571be2c5de2b1e27 | ||
| api_version: v1alpha1 | ||
| aws_sdk_go_version: "" | ||
| generator_config_info: | ||
| file_checksum: cc29e8be7c6f65ef2f8db75fc3752adbf18590df | ||
| file_checksum: 821cc69bbfdafc0bb1302bb609f7b92774448303 | ||
| original_file_name: generator.yaml | ||
| last_modification: | ||
| reason: API generation | ||
| timestamp: 2021-07-16 03:54:15.20368 +0000 UTC | ||
| timestamp: 2021-07-16 19:55:56.542005 +0000 UTC |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file is distributed | ||
| // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| // express or implied. See the License for the specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| package common | ||
|
|
||
| import ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" | ||
|
|
||
| // remove the Difference corresponding to the given subject from the delta struct | ||
| //TODO: ideally this would have a common implementation in compare/delta.go | ||
| func RemoveFromDelta( | ||
| delta *ackcompare.Delta, | ||
| subject string, | ||
| ) { | ||
| // copy slice | ||
| differences := delta.Differences | ||
|
|
||
| // identify index of Difference to remove | ||
| //TODO: this could require a stricter Path.Equals down the road | ||
| var i *int = nil | ||
| for j, diff := range differences { | ||
| if diff.Path.Contains(subject) { | ||
| i = &j | ||
| break | ||
| } | ||
| } | ||
|
|
||
| // if found, create a new slice and replace the original | ||
| if i != nil { | ||
| differences = append(differences[:*i], differences[*i+1:]...) | ||
| delta.Differences = differences | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file is distributed | ||
| // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| // express or implied. See the License for the specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| package replication_group | ||
|
|
||
| import ( | ||
| "strings" | ||
| "regexp" | ||
|
|
||
| ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" | ||
|
|
||
| "github.com/aws-controllers-k8s/elasticache-controller/pkg/common" | ||
| ) | ||
|
|
||
| // remove non-meaningful differences from delta | ||
| func filterDelta( | ||
| delta *ackcompare.Delta, | ||
| desired *resource, | ||
| latest *resource, | ||
| ) { | ||
|
Comment on lines
+26
to
+30
Contributor
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. Nice. Not related to this PR but mentioning it here due to its context: I think this is where Server defaults can be handled: Remove differences from delta when corresponding spec field is nil if last applied spec also had that field nil.
Contributor
Author
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. Yep this should enable us to (at least temporarily) handle defaults before the framework-level solution is ready |
||
|
|
||
| if delta.DifferentAt("Spec.EngineVersion") { | ||
| if desired.ko.Spec.EngineVersion != nil && latest.ko.Spec.EngineVersion != nil { | ||
| if engineVersionsMatch(*desired.ko.Spec.EngineVersion, *latest.ko.Spec.EngineVersion) { | ||
| common.RemoveFromDelta(delta, "Spec.EngineVersion") | ||
| } | ||
| } | ||
| // TODO: handle the case of a nil difference (especially when desired EV is nil) | ||
| } | ||
| } | ||
|
|
||
| // returns true if desired and latest engine versions match and false otherwise | ||
| // precondition: both desiredEV and latestEV are non-nil | ||
| // this handles the case where only the major EV is specified, e.g. "6.x" (or similar), but the latest | ||
| // version shows the minor version, e.g. "6.0.5" | ||
| func engineVersionsMatch( | ||
| desiredEV string, | ||
| latestEV string, | ||
| ) bool { | ||
| if desiredEV == latestEV { | ||
| return true | ||
| } | ||
|
|
||
| // if the last character of desiredEV is "x", only check for a major version match | ||
| last := len(desiredEV) - 1 | ||
| if desiredEV[last:] == "x" { | ||
| // cut off the "x" and replace all occurrences of '.' with '\.' (as '.' is a special regex character) | ||
| desired := strings.Replace(desiredEV[:last], ".", "\\.", -1) | ||
| r, _ := regexp.Compile(desired + ".*") | ||
| return r.MatchString(latestEV) | ||
| } | ||
|
|
||
| return false | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file is distributed | ||
| // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| // express or implied. See the License for the specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| package replication_group | ||
|
|
||
| import "testing" | ||
| import "github.com/stretchr/testify/require" | ||
|
|
||
| func TestEngineVersionsMatch(t *testing.T) { | ||
| require := require.New(t) | ||
|
|
||
| require.True(engineVersionsMatch("6.x", "6.0.5")) | ||
| require.False(engineVersionsMatch("13.x", "6.0.6")) | ||
| require.True(engineVersionsMatch("5.0.3", "5.0.3")) | ||
| require.False(engineVersionsMatch("5.0.3", "5.0.4")) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,9 +42,13 @@ func (rm *resourceManager) updateSpecFields( | |
| latestCacheCluster, err := rm.describeCacheCluster(ctx, resource) | ||
| if err == nil && latestCacheCluster != nil { | ||
| setEngineVersion(latestCacheCluster, resource) | ||
| setMaintenanceWindow(latestCacheCluster, resource) | ||
| } | ||
| } | ||
|
|
||
| //TODO: for all the fields here, reevaluate if the latest observed state should always be populated, | ||
| // even if the corresponding field was not specified in desired | ||
|
|
||
|
Comment on lines
+49
to
+51
Contributor
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. I think it should be fine to populate observed state fields here, the filterDelta() should determine if the diff is to be ignored.
Contributor
Author
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. Agreed |
||
| // if ReplicasPerNodeGroup was given in desired.Spec, update ko.Spec with the latest observed value | ||
| func setReplicasPerNodeGroup( | ||
| respRG *svcsdk.ReplicationGroup, | ||
|
|
@@ -72,3 +76,15 @@ func setEngineVersion( | |
| *ko.Spec.EngineVersion = *latestCacheCluster.EngineVersion | ||
| } | ||
| } | ||
|
|
||
| // update maintenance window (if non-nil in API response) regardless of whether it was specified in desired | ||
| func setMaintenanceWindow( | ||
| latestCacheCluster *svcsdk.CacheCluster, | ||
| resource *resource, | ||
| ) { | ||
| ko := resource.ko | ||
| if latestCacheCluster.PreferredMaintenanceWindow != nil { | ||
| pmw := *latestCacheCluster.PreferredMaintenanceWindow | ||
| ko.Spec.PreferredMaintenanceWindow = &pmw | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This method may return boolean indicating if there was a removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, not sure how we would use that return value but we can add it on later if there is a use for it