Skip to content

Commit

Permalink
Merge pull request #683 from adam-cattermole/MGDAPI-5691
Browse files Browse the repository at this point in the history
MGDAPI-5691 - allow specifying redis size for GCP
  • Loading branch information
openshift-merge-robot authored May 3, 2023
2 parents c37f30a + 4c82525 commit 5b40016
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ cluster/seed/blobstorage:

.PHONY: cluster/seed/redis
cluster/seed/redis:
@cat config/samples/integreatly_v1alpha1_redis.yaml | sed "s/name: REPLACE_ME/name: $(REDIS_NAME)/g" | sed "s/type: REPLACE_ME/type: $(PROVIDER)/g" | sed "s/size: REPLACE_ME/size: $(REDIS_NODE_SIZE)/g" | oc apply -f - -n $(NAMESPACE)
@cat config/samples/integreatly_v1alpha1_redis.yaml | sed "s/name: REPLACE_ME/name: $(REDIS_NAME)/g" | sed "s/type: REPLACE_ME/type: $(PROVIDER)/g" | sed "s/size: REPLACE_ME/size: '$(REDIS_NODE_SIZE)'/g" | oc apply -f - -n $(NAMESPACE)

.PHONY: cluster/seed/redissnapshot
cluster/seed/redissnapshot:
Expand Down
10 changes: 10 additions & 0 deletions pkg/providers/gcp/provider_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -378,6 +379,14 @@ func (p *RedisProvider) buildCreateInstanceRequest(ctx context.Context, r *v1alp
RedisVersion: redisVersion,
Labels: tags,
}
// Override if node size is defined in the CR spec
if r.Spec.Size != "" {
size, err := strconv.ParseInt(r.Spec.Size, 10, 64)
if err != nil {
return nil, errorUtil.Wrap(err, "failed to parse redis spec size")
}
defaultInstance.MemorySizeGb = int32(size)
}
if createInstanceRequest.Instance == nil {
createInstanceRequest.Instance = defaultInstance
return createInstanceRequest, nil
Expand Down Expand Up @@ -412,6 +421,7 @@ func (p *RedisProvider) buildCreateInstanceRequest(ctx context.Context, r *v1alp
if createInstanceRequest.Instance.RedisVersion == "" {
createInstanceRequest.Instance.RedisVersion = defaultInstance.RedisVersion
}

return createInstanceRequest, nil
}

Expand Down
58 changes: 58 additions & 0 deletions pkg/providers/gcp/provider_redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,64 @@ func TestRedisProvider_buildCreateInstanceRequest(t *testing.T) {
},
wantErr: false,
},
{
name: "success building redis create instance request with custom size",
fields: fields{
Client: moqClient.NewSigsClientMoqWithScheme(scheme, buildTestGcpInfrastructure(nil)),
},
args: args{
r: &v1alpha1.Redis{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testNs,
},
Spec: types.ResourceTypeSpec{
Size: "7",
},
},
strategyConfig: &StrategyConfig{
Region: gcpTestRegion,
ProjectID: gcpTestProjectId,
CreateStrategy: json.RawMessage(`{}`),
},
address: buildTestComputeAddress(nil),
},
want: &redispb.CreateInstanceRequest{
Parent: parent,
InstanceId: instanceID,
Instance: func() *redispb.Instance {
inst := *redisInstance
inst.MemorySizeGb = 7
return &inst
}(),
},
wantErr: false,
},
{
name: "fail to parse redis spec size",
fields: fields{
Client: moqClient.NewSigsClientMoqWithScheme(scheme, buildTestGcpInfrastructure(nil)),
},
args: args{
r: &v1alpha1.Redis{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testNs,
},
Spec: types.ResourceTypeSpec{
Size: "invalid",
},
},
strategyConfig: &StrategyConfig{
Region: gcpTestRegion,
ProjectID: gcpTestProjectId,
CreateStrategy: json.RawMessage(`{}`),
},
address: buildTestComputeAddress(nil),
},
want: nil,
wantErr: true,
},
{
name: "fail to unmarshal gcp redis create strategy",
fields: fields{},
Expand Down

0 comments on commit 5b40016

Please sign in to comment.