Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/module/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const (

// ActionRequest describes an invocation of action on module.
type ActionRequest struct {
Name string `json:"name"`
Params json.RawMessage `json:"params"`
Name string `json:"name"`
Params json.RawMessage `json:"params"`
Labels map[string]string `json:"labels"`
}

// ActionDesc is a descriptor for an action supported by a module.
Expand Down
5 changes: 5 additions & 0 deletions core/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ type Filter struct {
Labels map[string]string `json:"labels"`
}

type UpdateRequest struct {
Spec Spec `json:"spec"`
Labels map[string]string `json:"labels"`
}

type RevisionsSelector struct {
URN string `json:"urn"`
}
Expand Down
14 changes: 9 additions & 5 deletions core/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ func (s *Service) CreateResource(ctx context.Context, res resource.Resource) (*r
return s.execAction(ctx, res, act)
}

func (s *Service) UpdateResource(ctx context.Context, urn string, newSpec resource.Spec) (*resource.Resource, error) {
if len(newSpec.Dependencies) != 0 {
func (s *Service) UpdateResource(ctx context.Context, urn string, req resource.UpdateRequest) (*resource.Resource, error) {
if len(req.Spec.Dependencies) != 0 {
return nil, errors.ErrUnsupported.WithMsgf("updating dependencies is not supported")
} else if len(newSpec.Configs) == 0 {
} else if len(req.Spec.Configs) == 0 {
return nil, errors.ErrInvalid.WithMsgf("no config is being updated, nothing to do")
}

return s.ApplyAction(ctx, urn, module.ActionRequest{
Name: module.UpdateAction,
Params: newSpec.Configs,
Params: req.Spec.Configs,
Labels: req.Labels,
})
}

Expand Down Expand Up @@ -90,7 +91,10 @@ func (s *Service) planChange(ctx context.Context, res resource.Resource, act mod
return nil, err
}
return nil, errors.ErrInternal.WithMsgf("plan() failed").WithCausef(err.Error())
} else if err := planned.Resource.Validate(isCreate(act.Name)); err != nil {
}

planned.Resource.Labels = act.Labels
if err := planned.Resource.Validate(isCreate(act.Name)); err != nil {
return nil, err
}

Expand Down
33 changes: 23 additions & 10 deletions core/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestService_UpdateResource(t *testing.T) {
name string
setup func(t *testing.T) *core.Service
urn string
newSpec resource.Spec
update resource.UpdateRequest
want *resource.Resource
wantErr error
}{
Expand All @@ -325,8 +325,11 @@ func TestService_UpdateResource(t *testing.T) {

return core.New(resourceRepo, nil, &mocks.AsyncWorker{}, deadClock, nil)
},
urn: "orn:entropy:mock:project:child",
newSpec: resource.Spec{Configs: []byte(`{"foo": "bar"}`)},
urn: "orn:entropy:mock:project:child",
update: resource.UpdateRequest{
Spec: resource.Spec{Configs: []byte(`{"foo": "bar"}`)},
Labels: map[string]string{"created_by": "test_user", "group": "test_group"},
},
want: nil,
wantErr: errors.ErrNotFound,
},
Expand All @@ -347,8 +350,11 @@ func TestService_UpdateResource(t *testing.T) {

return core.New(resourceRepo, mod, &mocks.AsyncWorker{}, deadClock, nil)
},
urn: "orn:entropy:mock:project:child",
newSpec: resource.Spec{Configs: []byte(`{"foo": "bar"}`)},
urn: "orn:entropy:mock:project:child",
update: resource.UpdateRequest{
Spec: resource.Spec{Configs: []byte(`{"foo": "bar"}`)},
Labels: map[string]string{"created_by": "test_user", "group": "test_group"},
},
want: nil,
wantErr: errors.ErrInvalid,
},
Expand Down Expand Up @@ -388,8 +394,11 @@ func TestService_UpdateResource(t *testing.T) {

return core.New(resourceRepo, mod, mockWorker, deadClock, nil)
},
urn: "orn:entropy:mock:project:child",
newSpec: resource.Spec{Configs: []byte(`{"foo": "bar"}`)},
urn: "orn:entropy:mock:project:child",
update: resource.UpdateRequest{
Spec: resource.Spec{Configs: []byte(`{"foo": "bar"}`)},
Labels: map[string]string{"created_by": "test_user", "group": "test_group"},
},
want: nil,
wantErr: testErr,
},
Expand Down Expand Up @@ -441,8 +450,11 @@ func TestService_UpdateResource(t *testing.T) {

return core.New(resourceRepo, mod, mockWorker, deadClock, nil)
},
urn: "orn:entropy:mock:project:child",
newSpec: resource.Spec{Configs: []byte(`{"foo": "bar"}`)},
urn: "orn:entropy:mock:project:child",
update: resource.UpdateRequest{
Spec: resource.Spec{Configs: []byte(`{"foo": "bar"}`)},
Labels: map[string]string{"created_by": "test_user", "group": "test_group"},
},
want: &resource.Resource{
URN: "orn:entropy:mock:project:child",
Kind: "mock",
Expand All @@ -451,6 +463,7 @@ func TestService_UpdateResource(t *testing.T) {
CreatedAt: frozenTime,
UpdatedAt: frozenTime,
State: resource.State{Status: resource.StatusPending},
Labels: map[string]string{"created_by": "test_user", "group": "test_group"},
Spec: resource.Spec{
Configs: []byte(`{"foo": "bar"}`),
},
Expand All @@ -465,7 +478,7 @@ func TestService_UpdateResource(t *testing.T) {
t.Parallel()
svc := tt.setup(t)

got, err := svc.UpdateResource(context.Background(), tt.urn, tt.newSpec)
got, err := svc.UpdateResource(context.Background(), tt.urn, tt.update)
if tt.wantErr != nil {
assert.Error(t, err)
assert.True(t, errors.Is(err, tt.wantErr))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/stretchr/testify v1.7.1
github.com/xeipuuv/gojsonschema v1.2.0
go.buf.build/odpf/gw/odpf/proton v1.1.122
go.buf.build/odpf/gwv/odpf/proton v1.1.123
go.buf.build/odpf/gwv/odpf/proton v1.1.133
go.opencensus.io v0.23.0
go.uber.org/zap v1.21.0
google.golang.org/grpc v1.46.2
Expand Down
Loading