Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
feat: add support for resource classes
Browse files Browse the repository at this point in the history
Signed-off-by: Bianca Del Carretto <delca85@users.noreply.github.com>
  • Loading branch information
delca85 committed Oct 24, 2023
1 parent 7216417 commit db3f4ed
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/03-dependencies/score.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ containers:
resources:
db:
type: postgres
class: sensitive
dns:
type: dns
backend:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/golang/mock v1.6.0
github.com/imdario/mergo v0.3.13
github.com/mitchellh/mapstructure v1.5.0
github.com/score-spec/score-go v0.0.0-20230905115428-131acdd2f5cf
github.com/score-spec/score-go v0.0.0-20231024094556-308a07ae2536
github.com/sendgrid/rest v2.6.9+incompatible
github.com/spf13/cobra v1.6.0
github.com/stretchr/testify v1.8.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6Ng
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/score-spec/score-go v0.0.0-20230905115428-131acdd2f5cf h1:0Dt+qyYoGTXPPU5Xq/KxLDtQMMA8hX+oJ8EsjFWUajQ=
github.com/score-spec/score-go v0.0.0-20230905115428-131acdd2f5cf/go.mod h1:3l9mvrtYKzxXDQVcYkQBD3ABTPkTzWhUMYNfGlpctoo=
github.com/score-spec/score-go v0.0.0-20231024093959-ed5a5d548352 h1:yycML7iVHv/65wo4ao7uH5cvIYgQhB184iKAy7suNBk=
github.com/score-spec/score-go v0.0.0-20231024093959-ed5a5d548352/go.mod h1:3l9mvrtYKzxXDQVcYkQBD3ABTPkTzWhUMYNfGlpctoo=
github.com/score-spec/score-go v0.0.0-20231024094556-308a07ae2536 h1:WBWWWSbAR2oJapUZyCm4IZ5LJfkT5IUlHtmcJNBLFiY=
github.com/score-spec/score-go v0.0.0-20231024094556-308a07ae2536/go.mod h1:3l9mvrtYKzxXDQVcYkQBD3ABTPkTzWhUMYNfGlpctoo=
github.com/sendgrid/rest v2.6.9+incompatible h1:1EyIcsNdn9KIisLW50MKwmSRSK+ekueiEMJ7NEoxJo0=
github.com/sendgrid/rest v2.6.9+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
Expand Down
11 changes: 8 additions & 3 deletions internal/humanitec/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,17 @@ func ConvertSpec(name, envID, baseDir, workloadSourceURL string, spec *score.Wor
}
}
// END (DEPRECATED)

var class = "default"
if res.Class != "" {
class = res.Class
}
if mod, scope, resName, err := parseResourceId(resId); err != nil {
log.Printf("Warning: %v.\n", err)
} else if mod == "" || mod == spec.Metadata.Name {
if scope == "externals" {
var extRes = map[string]interface{}{
"type": res.Type,
"type": res.Type,
"class": class,
}
if len(res.Params) > 0 {
extRes["params"] = ctx.SubstituteAll(res.Params)
Expand All @@ -313,7 +317,8 @@ func ConvertSpec(name, envID, baseDir, workloadSourceURL string, spec *score.Wor
} else if scope == "shared" {
var resName = strings.Replace(resId, "shared.", "", 1)
var sharedRes = map[string]interface{}{
"type": res.Type,
"type": res.Type,
"class": class,
}
if len(res.Params) > 0 {
sharedRes["params"] = ctx.SubstituteAll(res.Params)
Expand Down
15 changes: 10 additions & 5 deletions internal/humanitec/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ func TestScoreConvert(t *testing.T) {
AnnotationLabelResourceId: "externals.annotations-db-id",
},
},
Type: "postgres",
Type: "postgres",
Class: "large",
Params: map[string]interface{}{
"extensions": map[string]interface{}{
"uuid-ossp": map[string]interface{}{
Expand Down Expand Up @@ -433,10 +434,12 @@ func TestScoreConvert(t *testing.T) {
},
"externals": map[string]interface{}{
"data": map[string]interface{}{
"type": "volume",
"type": "volume",
"class": "default",
},
"annotations-db-id": map[string]interface{}{
"type": "postgres",
"type": "postgres",
"class": "large",
"params": map[string]interface{}{
"extensions": map[string]interface{}{
"uuid-ossp": map[string]interface{}{
Expand All @@ -447,7 +450,8 @@ func TestScoreConvert(t *testing.T) {
},
},
"route": map[string]interface{}{
"type": "route",
"type": "route",
"class": "default",
"params": map[string]interface{}{
"host": "${shared.dns.host}",
},
Expand All @@ -461,7 +465,8 @@ func TestScoreConvert(t *testing.T) {
Operation: "add",
Path: "/dns",
Value: map[string]interface{}{
"type": "dns",
"type": "dns",
"class": "default",
"params": map[string]interface{}{
"test": "value",
},
Expand Down

0 comments on commit db3f4ed

Please sign in to comment.