From db3f4ed54d92dec55b4bf9b9a454abada84c59f9 Mon Sep 17 00:00:00 2001 From: Bianca Del Carretto Date: Tue, 24 Oct 2023 13:14:34 +0200 Subject: [PATCH] feat: add support for resource classes Signed-off-by: Bianca Del Carretto --- examples/03-dependencies/score.yaml | 1 + go.mod | 2 +- go.sum | 4 ++++ internal/humanitec/convert.go | 11 ++++++++--- internal/humanitec/convert_test.go | 15 ++++++++++----- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/examples/03-dependencies/score.yaml b/examples/03-dependencies/score.yaml index 02ea32b..72969b8 100644 --- a/examples/03-dependencies/score.yaml +++ b/examples/03-dependencies/score.yaml @@ -15,6 +15,7 @@ containers: resources: db: type: postgres + class: sensitive dns: type: dns backend: diff --git a/go.mod b/go.mod index 8c96556..657e6ea 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 94a69ff..81cffba 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/humanitec/convert.go b/internal/humanitec/convert.go index 254c799..336606e 100644 --- a/internal/humanitec/convert.go +++ b/internal/humanitec/convert.go @@ -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) @@ -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) diff --git a/internal/humanitec/convert_test.go b/internal/humanitec/convert_test.go index 9980f36..a2ed323 100644 --- a/internal/humanitec/convert_test.go +++ b/internal/humanitec/convert_test.go @@ -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{}{ @@ -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{}{ @@ -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}", }, @@ -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", },