diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index 56132c1b..dd61b4a0 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,5 +1,5 @@ ack_generate_info: - build_date: "2021-10-14T18:44:40Z" + build_date: "2021-10-18T18:57:57Z" build_hash: 385779a205bea50e8762b76bc75cab957cf723b9 go_version: go1.15.2 version: v0.15.1 diff --git a/pkg/resource/replication_group/manager_test.go b/pkg/resource/replication_group/manager_test.go deleted file mode 100644 index fa58909b..00000000 --- a/pkg/resource/replication_group/manager_test.go +++ /dev/null @@ -1,70 +0,0 @@ -// 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 ( - "context" - mocksvcsdkapi "github.com/aws-controllers-k8s/elasticache-controller/mocks/aws-sdk-go/elasticache" - "github.com/aws-controllers-k8s/elasticache-controller/pkg/testutil" - svcsdk "github.com/aws/aws-sdk-go/service/elasticache" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "path/filepath" - "testing" -) - -// TestReadOne_Exists runs resource manager ReadOne test scenario -// Declarative tests make this test redundant, but it remains to demonstrate the difference between a declarative -// test (as specified in test_suite.yaml) and a regular imperative test. -func TestReadOne_Exists(t *testing.T) { - assert := assert.New(t) - - mocksdkapi := &mocksvcsdkapi.ElastiCacheAPI{} - rm := provideResourceManagerWithMockSDKAPI(mocksdkapi) - - // Setup mock current ko state. - var rd = resourceDescriptor{} - ro := rd.EmptyRuntimeObject() - testutil.LoadFromFixture(filepath.Join("testdata", "replication_group", "cr", "rg_cmd_create_completed.yaml"), ro) - desired := rd.ResourceFromRuntimeObject(ro) - - // Setup mock API response - // Describe RG - var mockDescribeOutput svcsdk.DescribeReplicationGroupsOutput - testutil.LoadFromFixture(filepath.Join("testdata", "replication_group", "read_one", "rg_cmd_create_completed.json"), &mockDescribeOutput) - mocksdkapi.On("DescribeReplicationGroupsWithContext", mock.Anything, mock.Anything).Return(&mockDescribeOutput, nil) - // ListAllowedNodeTypeModifications - var mockAllowedNodeTypeOutput svcsdk.ListAllowedNodeTypeModificationsOutput - testutil.LoadFromFixture(filepath.Join("testdata", "allowed_node_types", "read_many", "rg_cmd_allowed_node_types.json"), &mockAllowedNodeTypeOutput) - mocksdkapi.On("ListAllowedNodeTypeModifications", mock.Anything, mock.Anything).Return(&mockAllowedNodeTypeOutput, nil) - // DescribeEvents - var mockDescribeEventsOutput svcsdk.DescribeEventsOutput - testutil.LoadFromFixture(filepath.Join("testdata", "events", "read_many", "rg_cmd_events.json"), &mockDescribeEventsOutput) - mocksdkapi.On("DescribeEventsWithContext", mock.Anything, mock.Anything).Return(&mockDescribeEventsOutput, nil) - // DescribeCacheClusters - var mockDescribeCacheClusterOutput svcsdk.DescribeCacheClustersOutput - testutil.LoadFromFixture(filepath.Join("testdata", "cache_clusters", "read_many", "rg_cmd_primary_cache_node.json"), &mockDescribeCacheClusterOutput) - mocksdkapi.On("DescribeCacheClustersWithContext", mock.Anything, mock.Anything).Return(&mockDescribeCacheClusterOutput, nil) - - var delegate = testRunnerDelegate{t: t} - - // Tests - t.Run("ReadOne=NoDiff", func(t *testing.T) { - // Given: describe RG response has no diff compared to latest ko state. - // Expect: no change in ko.status - latest, err := rm.ReadOne(context.Background(), desired) - assert.Nil(err) - assert.True(delegate.Equal(rm.concreteResource(desired), rm.concreteResource(latest))) - }) -} diff --git a/pkg/resource/replication_group/post_set_output.go b/pkg/resource/replication_group/post_set_output.go index 4e3fd9c5..c87d525b 100644 --- a/pkg/resource/replication_group/post_set_output.go +++ b/pkg/resource/replication_group/post_set_output.go @@ -43,6 +43,7 @@ func (rm *resourceManager) updateSpecFields( if err == nil && latestCacheCluster != nil { setEngineVersion(latestCacheCluster, resource) setMaintenanceWindow(latestCacheCluster, resource) + setCacheParameterGroup(latestCacheCluster, resource) } } @@ -66,7 +67,7 @@ func setReplicasPerNodeGroup( } } -// if EngineVersion was specified in desired.Spec, update ko.Sepc with the latest observed value (if non-nil) +// if EngineVersion was specified in desired.Spec, update ko.Spec with the latest observed value (if non-nil) func setEngineVersion( latestCacheCluster *svcsdk.CacheCluster, resource *resource, @@ -88,3 +89,16 @@ func setMaintenanceWindow( ko.Spec.PreferredMaintenanceWindow = &pmw } } + +// setCacheParameterGroup updates the cache parameter group associated with the replication group +// (if non-nil in API response) regardless of whether it was specified in desired +func setCacheParameterGroup( + latestCacheCluster *svcsdk.CacheCluster, + resource *resource, +) { + ko := resource.ko + if latestCacheCluster.CacheParameterGroup != nil && latestCacheCluster.CacheParameterGroup.CacheParameterGroupName != nil { + cpgName := *latestCacheCluster.CacheParameterGroup.CacheParameterGroupName + ko.Spec.CacheParameterGroupName = &cpgName + } +} diff --git a/pkg/resource/replication_group/testdata/replication_group/cr/rg_cmd_create_completed_latest.yaml b/pkg/resource/replication_group/testdata/replication_group/cr/rg_cmd_create_completed_latest.yaml new file mode 100644 index 00000000..e797ed47 --- /dev/null +++ b/pkg/resource/replication_group/testdata/replication_group/cr/rg_cmd_create_completed_latest.yaml @@ -0,0 +1,105 @@ +apiVersion: elasticache.services.k8s.aws/v1alpha1 +kind: ReplicationGroup +# omitted metadata +spec: + atRestEncryptionEnabled: false + cacheNodeType: cache.t3.micro + cacheParameterGroupName: "default.redis5.0" + engine: redis + numNodeGroups: 1 + preferredMaintenanceWindow: "wed:08:00-wed:09:00" + replicasPerNodeGroup: 1 + replicationGroupDescription: cluster-mode disabled RG + replicationGroupID: rg-cmd + snapshotRetentionLimit: 0 + snapshotWindow: "10:00-11:00" + transitEncryptionEnabled: false +status: + ackResourceMetadata: + arn: arn:aws:elasticache:us-east-1:012345678910:replicationgroup:rg-cmd + ownerAccountID: "" + allowedScaleUpModifications: + - cache.m3.2xlarge + - cache.m3.large + - cache.m3.medium + - cache.m3.xlarge + - cache.m4.10xlarge + - cache.m4.2xlarge + - cache.m4.4xlarge + - cache.m4.large + - cache.m4.xlarge + - cache.m5.12xlarge + - cache.m5.24xlarge + - cache.m5.2xlarge + - cache.m5.4xlarge + - cache.m5.large + - cache.m5.xlarge + - cache.m6g.large + - cache.r3.2xlarge + - cache.r3.4xlarge + - cache.r3.8xlarge + - cache.r3.large + - cache.r3.xlarge + - cache.r4.16xlarge + - cache.r4.2xlarge + - cache.r4.4xlarge + - cache.r4.8xlarge + - cache.r4.large + - cache.r4.xlarge + - cache.r5.12xlarge + - cache.r5.24xlarge + - cache.r5.2xlarge + - cache.r5.4xlarge + - cache.r5.large + - cache.r5.xlarge + - cache.r6g.2xlarge + - cache.r6g.4xlarge + - cache.r6g.8xlarge + - cache.r6g.large + - cache.r6g.xlarge + - cache.t2.medium + - cache.t2.micro + - cache.t2.small + - cache.t3.medium + - cache.t3.small + authTokenEnabled: false + automaticFailover: disabled + clusterEnabled: false + conditions: + - status: "True" + type: ACK.ResourceSynced + description: cluster-mode disabled RG + events: + - date: "2021-03-30T20:12:00Z" + message: Replication group rg-cmd created + globalReplicationGroupInfo: {} + memberClusters: + - rg-cmd-001 + - rg-cmd-002 + multiAZ: disabled + nodeGroups: + - nodeGroupID: "0001" + nodeGroupMembers: + - cacheClusterID: rg-cmd-001 + cacheNodeID: "0001" + currentRole: primary + preferredAvailabilityZone: us-east-1b + readEndpoint: + address: rg-cmd-001.xxxxxx.0001.use1.cache.amazonaws.com + port: 6379 + - cacheClusterID: rg-cmd-002 + cacheNodeID: "0001" + currentRole: replica + preferredAvailabilityZone: us-east-1d + readEndpoint: + address: rg-cmd-002.xxxxxx.0001.use1.cache.amazonaws.com + port: 6379 + primaryEndpoint: + address: rg-cmd.xxxxxx.ng.0001.use1.cache.amazonaws.com + port: 6379 + readerEndpoint: + address: rg-cmd-ro.xxxxxx.ng.0001.use1.cache.amazonaws.com + port: 6379 + status: available + pendingModifiedValues: {} + status: available \ No newline at end of file diff --git a/pkg/resource/replication_group/testdata/test_suite.yaml b/pkg/resource/replication_group/testdata/test_suite.yaml index 2489a413..d723b45d 100644 --- a/pkg/resource/replication_group/testdata/test_suite.yaml +++ b/pkg/resource/replication_group/testdata/test_suite.yaml @@ -53,7 +53,7 @@ tests: output_fixture: "cache_clusters/read_many/rg_cmd_primary_cache_node.json" invoke: ReadOne expect: - latest_state: "replication_group/cr/rg_cmd_create_completed.yaml" + latest_state: "replication_group/cr/rg_cmd_create_completed_latest.yaml" error: nil - name: "ReadOne=NoDiff" description: "Given desired state matches with server side resource data, ko.Status remain unchanged (resource is stable)" @@ -70,7 +70,7 @@ tests: output_fixture: "cache_clusters/read_many/rg_cmd_primary_cache_node.json" invoke: ReadOne expect: - latest_state: "replication_group/cr/rg_cmd_create_completed.yaml" #unchanged + latest_state: "replication_group/cr/rg_cmd_create_completed_latest.yaml" error: nil - name: "Update=IncreaseReplicaCount" description: "Ensure a replica is added once a new config is provided" diff --git a/test/e2e/tests/test_replicationgroup.py b/test/e2e/tests/test_replicationgroup.py index e7a3076a..4832ae57 100644 --- a/test/e2e/tests/test_replicationgroup.py +++ b/test/e2e/tests/test_replicationgroup.py @@ -640,7 +640,6 @@ def test_rg_associate_resources(self, rg_associate_resources_input, rg_associate # assert new state assert_associated_resources(rg_associate_resources_input['RG_ID'], sg_list, sns_topic, ug_list) - @pytest.mark.blocked # TODO: remove when passing def test_rg_update_cpg(self, rg_update_cpg_input, rg_update_cpg, bootstrap_resources): # wait for resource to sync and retrieve initial state (reference, _) = rg_update_cpg