Skip to content

Commit

Permalink
Merge pull request #226 from austincunningham/add-applyImmediately
Browse files Browse the repository at this point in the history
add the applyImmediately flag
  • Loading branch information
openshift-merge-robot authored Jul 6, 2021
2 parents d3dba33 + dc6552d commit e60237c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
9 changes: 6 additions & 3 deletions pkg/providers/aws/provider_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (p *RedisProvider) createElasticacheCluster(ctx context.Context, r *v1alpha
}

// check if any modifications are required to bring the elasticache instance up to date with the strategy map.
modifyInput, err := buildElasticacheUpdateStrategy(ec2Svc, elasticacheConfig, foundCache, replicationGroupClusters, logger)
modifyInput, err := buildElasticacheUpdateStrategy(ec2Svc, elasticacheConfig, foundCache, replicationGroupClusters, logger, r.Spec.ApplyImmediately)
if err != nil {
errMsg := "failed to build elasticache modify strategy"
return nil, croType.StatusMessage(errMsg), errorUtil.Wrap(err, errMsg)
Expand Down Expand Up @@ -644,7 +644,7 @@ func (p *RedisProvider) isLastResource(ctx context.Context, namespace string) (b
// if modifications are required, a modify input struct will be returned with all proposed changes.
//
// if no modifications are required, nil will be returned.
func buildElasticacheUpdateStrategy(ec2Client ec2iface.EC2API, elasticacheConfig *elasticache.CreateReplicationGroupInput, foundConfig *elasticache.ReplicationGroup, replicationGroupClusters []elasticache.CacheCluster, logger *logrus.Entry) (*elasticache.ModifyReplicationGroupInput, error) {
func buildElasticacheUpdateStrategy(ec2Client ec2iface.EC2API, elasticacheConfig *elasticache.CreateReplicationGroupInput, foundConfig *elasticache.ReplicationGroup, replicationGroupClusters []elasticache.CacheCluster, logger *logrus.Entry, applyImmediately bool) (*elasticache.ModifyReplicationGroupInput, error) {
// setup logger.
actionLogger := resources.NewActionLogger(logger, "buildElasticacheUpdateStrategy")
actionLogger.Infof("verifying that %s configuration is as expected", *foundConfig.ReplicationGroupId)
Expand Down Expand Up @@ -741,6 +741,9 @@ func buildElasticacheUpdateStrategy(ec2Client ec2iface.EC2API, elasticacheConfig
modifyInput.SnapshotWindow = elasticacheConfig.SnapshotWindow
updateFound = true
}

// ApplyImmediately flag is controlled by the redis cr.Spec.applyImmediately flag
modifyInput.ApplyImmediately = aws.Bool(applyImmediately)
}

if updateFound {
Expand Down Expand Up @@ -1011,7 +1014,7 @@ func (p *RedisProvider) setRedisServiceMaintenanceMetric(ctx context.Context, ca
return
}

logrus.Infof("there are elasticache service update actions: %d available", len(output.UpdateActions))
logrus.Infof("there are elasticache service update actions %d available : %s", len(output.UpdateActions), output.UpdateActions)
for _, updateAction := range output.UpdateActions {
metricLabels := map[string]string{}
metricLabels["clusterID"] = clusterID
Expand Down
24 changes: 17 additions & 7 deletions pkg/providers/aws/provider_redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
foundConfig *elasticache.ReplicationGroup
replicationGroupClusters []elasticache.CacheCluster
logger *logrus.Entry
applyImmediately bool
}
tests := []struct {
name string
Expand Down Expand Up @@ -946,7 +947,8 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
SnapshotWindow: aws.String("test"),
},
},
logger: testLogger,
logger: testLogger,
applyImmediately: false,
},
want: nil,
},
Expand All @@ -973,7 +975,8 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
SnapshotWindow: aws.String("test"),
},
},
logger: testLogger,
logger: testLogger,
applyImmediately: false,
},
want: nil,
},
Expand All @@ -1000,7 +1003,8 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
SnapshotWindow: aws.String("test"),
},
},
logger: testLogger,
logger: testLogger,
applyImmediately: false,
},
want: nil,
wantErr: "invalid redis version: failed to parse desired version: Malformed version: some invalid value",
Expand Down Expand Up @@ -1028,7 +1032,8 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
SnapshotWindow: aws.String("test"),
},
},
logger: testLogger,
logger: testLogger,
applyImmediately: false,
},
want: nil,
wantErr: "invalid redis version: failed to parse current version: Malformed version: some invalid value",
Expand Down Expand Up @@ -1067,7 +1072,8 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
PreferredAvailabilityZone: aws.String("test"),
},
},
logger: testLogger,
logger: testLogger,
applyImmediately: true,
},
want: &elasticache.ModifyReplicationGroupInput{
CacheNodeType: aws.String("cache.newValue"),
Expand All @@ -1076,6 +1082,7 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
SnapshotWindow: aws.String("newValue"),
ReplicationGroupId: aws.String("test-id"),
EngineVersion: aws.String(defaultEngineVersion),
ApplyImmediately: aws.Bool(true),
},
},
{
Expand All @@ -1097,6 +1104,7 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
},
replicationGroupClusters: []elasticache.CacheCluster{},
logger: testLogger,
applyImmediately: false,
},
want: nil,
wantErr: "failed to get instance type offerings for type cache.test2: test",
Expand Down Expand Up @@ -1135,9 +1143,11 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
PreferredAvailabilityZone: aws.String("test2"),
},
},
logger: testLogger,
logger: testLogger,
applyImmediately: false,
},
want: &elasticache.ModifyReplicationGroupInput{
ApplyImmediately: aws.Bool(false),
SnapshotRetentionLimit: aws.Int64(50),
PreferredMaintenanceWindow: aws.String("newValue"),
SnapshotWindow: aws.String("newValue"),
Expand All @@ -1148,7 +1158,7 @@ func Test_buildElasticacheUpdateStrategy(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := buildElasticacheUpdateStrategy(tt.args.ec2Client, tt.args.elasticacheConfig, tt.args.foundConfig, tt.args.replicationGroupClusters, tt.args.logger)
got, err := buildElasticacheUpdateStrategy(tt.args.ec2Client, tt.args.elasticacheConfig, tt.args.foundConfig, tt.args.replicationGroupClusters, tt.args.logger, tt.args.applyImmediately)
if tt.wantErr != "" && err.Error() != tt.wantErr {
t.Errorf("createElasticacheCluster() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit e60237c

Please sign in to comment.