Skip to content

Commit

Permalink
fix: allow overiding user passed resource & limits (#84)
Browse files Browse the repository at this point in the history
* fix: allow overiding user passed resource & limits

* test: add resource limit update test
  • Loading branch information
ishanarya0 authored Oct 20, 2023
1 parent 76eba64 commit 4d0e906
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/firehose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func readConfig(r resource.Resource, confJSON json.RawMessage, dc driverConf) (*
rl.Limits = rl.Limits.merge(overrides.Limits)
rl.Requests = rl.Requests.merge(overrides.Requests)
}
cfg.Limits = rl.Limits
cfg.Requests = rl.Requests
cfg.Limits = rl.Limits.merge(cfg.Limits)
cfg.Requests = rl.Requests.merge(cfg.Requests)

return &cfg, nil
}
93 changes: 93 additions & 0 deletions modules/firehose/driver_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,99 @@ func TestFirehoseDriver_Plan(t *testing.T) {
wantErr: nil,
},

{
title: "Update_Resource_&_Limits",
exr: module.ExpandedResource{
Resource: resource.Resource{
URN: "urn:goto:entropy:foo:fh1",
Kind: "firehose",
Name: "fh1",
Project: "foo",
Spec: resource.Spec{
Configs: modules.MustJSON(map[string]any{
"replicas": 1,
"deployment_id": "firehose-deployment-x",
"env_variables": map[string]string{
"SINK_TYPE": "LOG",
"INPUT_SCHEMA_PROTO_CLASS": "com.foo.Bar",
"SOURCE_KAFKA_BROKERS": "localhost:9092",
"SOURCE_KAFKA_TOPIC": "foo-log",
},
}),
},
State: resource.State{
Status: resource.StatusCompleted,
Output: modules.MustJSON(Output{
Namespace: "foo",
ReleaseName: "bar",
}),
},
},
},
act: module.ActionRequest{
Name: module.UpdateAction,
Params: modules.MustJSON(map[string]any{
"replicas": 10,
"env_variables": map[string]string{
"SINK_TYPE": "HTTP", // the change being applied
"INPUT_SCHEMA_PROTO_CLASS": "com.foo.Bar",
"SOURCE_KAFKA_CONSUMER_GROUP_ID": "foo-bar-baz",
"SOURCE_KAFKA_BROKERS": "localhost:9092",
"SOURCE_KAFKA_TOPIC": "foo-log",
},
"limits": map[string]any{
"cpu": "500m",
"memory": "2048Mi",
},
"requests": map[string]any{
"cpu": "400m",
"memory": "1024Mi",
},
}),
},
want: &resource.Resource{
URN: "urn:goto:entropy:foo:fh1",
Kind: "firehose",
Name: "fh1",
Project: "foo",
Spec: resource.Spec{
Configs: modules.MustJSON(map[string]any{
"stopped": false,
"replicas": 10,
"deployment_id": "firehose-deployment-x",
"env_variables": map[string]string{
"SINK_TYPE": "HTTP",
"INPUT_SCHEMA_PROTO_CLASS": "com.foo.Bar",
"SOURCE_KAFKA_CONSUMER_GROUP_ID": "foo-bar-baz",
"SOURCE_KAFKA_BROKERS": "localhost:9092",
"SOURCE_KAFKA_TOPIC": "foo-log",
},
"limits": map[string]any{
"cpu": "500m",
"memory": "2048Mi",
},
"requests": map[string]any{
"cpu": "400m",
"memory": "1024Mi",
},
"init_container": map[string]interface{}{"args": interface{}(nil), "command": interface{}(nil), "enabled": false, "image_tag": "", "pull_policy": "", "repository": ""},
}),
},
State: resource.State{
Status: resource.StatusPending,
Output: modules.MustJSON(Output{
Namespace: "foo",
ReleaseName: "bar",
}),
ModuleData: modules.MustJSON(transientData{
PendingSteps: []string{stepReleaseUpdate},
}),
NextSyncAt: &frozenTime,
},
},
wantErr: nil,
},

// reset action tests
{
title: "Reset_InValid",
Expand Down

0 comments on commit 4d0e906

Please sign in to comment.