Skip to content
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

Support for CacheCluster resource #137

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

cPu1
Copy link
Contributor

@cPu1 cPu1 commented Jun 28, 2024

Issue #, if available: aws-controllers-k8s/community#2079

Description of changes:

This changelist adds support for the ElastiCache CacheCluster resource. The generated code did not account for many fields in the call to ModifyCacheCluster, and the DescribeCacheClusters API does not return all fields in the spec and values for some fields are reported in the PendingModifiedValues field instead. To handle this, the last requested configuration for Spec.PreferredAvailabilityZones is stored as annotations and used to compute NewAvailabilityZones. Moreover, CacheNodeIdsToRemove is computed using Spec.NumCacheNodes and PendingModifiedValues.NumCacheNodes. Support for Spec.LogDeliveryConfigurations is explicitly removed and parked for later because the Describe API does not return all fields for this struct. There were many changes to other ElastiCache resources introduced in the newer SDK, so they have been removed for now and not ignored. As a result, a subsequent make build-controller will result in new changes.

The logic for syncing tags and comparing engine versions has been refactored to promote reusability.

Closes aws-controllers-k8s/community#2079.

Signed-off-by: cPu1 patwal.chetan@gmail.com

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-prow ack-prow bot requested review from a-hilaly and nmvk June 28, 2024 13:48
Copy link

ack-prow bot commented Jun 28, 2024

Hi @cPu1. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ack-prow ack-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 28, 2024
@a-hilaly
Copy link
Member

/ok-to-test

@ack-prow ack-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 28, 2024
@a-hilaly
Copy link
Member

a-hilaly commented Jul 8, 2024

/test all

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cPu1 thank you so much! this is great. I left few comments in-line

pkg/util/tags.go Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can import and reuse this for the other resource in a seperate PR

test/e2e/tests/test_cache_cluster.py Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice testing

if len(parts) == 0 {
return major, minor, patch
}
major, _ = strconv.Atoi(parts[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to handle the error here - if a user provides a completely wrong version we need to set the resource ona terminal condition stating that the engine version format is incorrect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@cPu1 cPu1 Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't introduced in this PR, the function was merely moved from pkg/resource/replication_group/delta_util.go. I did notice this but refactoring ReplicationGroup was out of scope for this PR, and this is only used for the delta comparison so the controller will still set the resource in a terminal condition after receiving one of the configured terminal error codes from the API. If we do add this validation, we'll have to do this for both create and update.

patch, _ = strconv.Atoi(parts[2])
}
}
return major, minor, patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the patch variable is never used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was also moved from pkg/resource/replication_group/delta_util.go.


// if the last character of desiredEV is "x" or the major version is higher than 5, ignore patch version when comparing.
// See https://github.com/aws-controllers-k8s/community/issues/1737
if dMaj > 5 || desiredEV[last:] == "x" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: why 5? what if a user provides 4.x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also moved from pkg/resource/replication_group/delta_util.go. The reason is mentioned in this PR: #115.

The purpose of this changes is to avoid the controller to compare patch versions when Redis version is >=6, since It's managed by AWS. More details aws-controllers-k8s/community#1737.

return diff.Path.Contains("Spec.PreferredAvailabilityZones")
}); idx != -1 && desired.ko.Spec.PreferredAvailabilityZones != nil {
if nodesDelta >= 0 {
return errors.New("spec.preferredAvailabilityZones can only be changed when new nodes are being added via spec.numCacheNodes")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to make those terminal errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a terminal error. Any error returned from this function is treated as a terminal error.

oldAZsLen = len(oldValues)
}
if len(desiredSpec.PreferredAvailabilityZones) <= oldAZsLen {
return errors.New("newly specified AZs in spec.preferredAvailabilityZones must match the number of cache nodes being added")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. It's a terminal error. Any error returned from this function is treated as a terminal error.

if nodesDelta > 0 {
for i := numNodes; i > numNodes-nodesDelta; i-- {
nodeID := fmt.Sprintf("%04d", i)
input.CacheNodeIdsToRemove = append(input.CacheNodeIdsToRemove, &nodeID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very weird API...

This changelist adds support for the ElastiCache `CacheCluster` resource. The generated code did not account for many fields in the call to `ModifyCacheCluster`, and the `DescribeCacheClusters` API does not return all fields in the spec and values for some fields are reported in the `PendingModifiedValues` field instead. To handle this, the last requested configuration for `Spec.PreferredAvailabilityZones` is stored as annotations and used to compute `NewAvailabilityZones`. Moreover, `CacheNodeIdsToRemove` is computed using `Spec.NumCacheNodes` and `PendingModifiedValues.NumCacheNodes`. Support for `Spec.LogDeliveryConfigurations` is explicitly removed and parked for later because the Describe API does not return all fields for this struct. There were many changes to other ElastiCache resources introduced in the newer SDK, so they have been removed for now and not ignored. As a result, a subsequent `make build-controller` will result in new changes.

The logic for syncing tags and comparing engine versions has been refactored to promote reusability.

Closes aws-controllers-k8s/community#2079.

Signed-off-by: cPu1 <patwal.chetan@gmail.com>
Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @cPu1 ! 👍
/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jul 11, 2024
Copy link

ack-prow bot commented Jul 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a-hilaly, cPu1

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-prow ack-prow bot added the approved label Jul 11, 2024
@ack-prow ack-prow bot merged commit 6e60bb7 into aws-controllers-k8s:main Jul 11, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for elasticache CacheClusters
2 participants