forked from aws-controllers-k8s/community
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable multiple update operations support on single resource (aws-con…
…trollers-k8s#245) Issue aws-controllers-k8s#210 Description of changes: The changes in this PR are to enable custom resource update scenario where Update operation on given resource does not support fields that are supported by its Create method, and there exist specialized methods to update such fields. These specialized method response provides the Resource object indicating the Update on the resource. For example: create-replication-group API arguments include: num-node-groups replicas-per-node-group however, modify-replication-group API arguments does not, instead modify-replication-group-shard-configuration and increase-replica-count, decrease-replica-count APIs corresponds to the related Update. The approach taken in this PR is to add the details of such fields and corresponding custom update methods in the generator.yaml. For example: resources: ReplicationGroup: custom_update_operations: UpdateShardConfiguration: fields: - NumNodeGroups UpdateReplicaCount: fields: - ReplicasPerNodeGroup And custom update methods' (UpdateShardConfiguration and UpdateReplicaCount) implementation is provided in a separate code file: aws-controllers-k8s/services/elasticache/pkg/resource/replication_group/custom_update_api.go These methods are supplied with DiffReporter which helps the code in this file determine the specific Update API to invoke based on the difference in desired, current resource details. Co-authored-by: Kumar Gaurav Sharma <kumargsh@amazon.com>
- Loading branch information
1 parent
3a3a504
commit 28eabf6
Showing
50 changed files
with
718 additions
and
117 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package compare | ||
|
||
import ( | ||
"fmt" | ||
"github.com/google/go-cmp/cmp" | ||
"strings" | ||
) | ||
|
||
type DiffItem struct { | ||
Path string | ||
ValueA string | ||
ValueB string | ||
} | ||
|
||
func (diff *DiffItem) String() string { | ||
return fmt.Sprintf("%#v:\n\t-: %+v\n\t+: %+v\n", diff.Path, diff.ValueA, diff.ValueB) | ||
} | ||
|
||
type Reporter struct { | ||
path cmp.Path | ||
Differences []DiffItem | ||
} | ||
|
||
func (reporter *Reporter) PushStep(ps cmp.PathStep) { | ||
reporter.path = append(reporter.path, ps) | ||
} | ||
|
||
func (reporter *Reporter) PopStep() { | ||
reporter.path = reporter.path[:len(reporter.path)-1] | ||
} | ||
|
||
func (reporter *Reporter) Report(result cmp.Result) { | ||
if !result.Equal() { | ||
a, b := reporter.path.Last().Values() | ||
reporter.Differences = append(reporter.Differences, DiffItem{reporter.path.String(), fmt.Sprintf("%v",a), fmt.Sprintf("%v",b)}); | ||
} | ||
} | ||
|
||
func (reporter *Reporter) String() string { | ||
var diffs []string | ||
for _, diff := range reporter.Differences { | ||
diffs = append(diffs, diff.String()) | ||
} | ||
return strings.Join(diffs, "\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.