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

Commit

Permalink
feat: renamed workload resource type into service
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Yarshevich <yarshevich@gmail.com>
  • Loading branch information
ghen committed Jan 27, 2023
1 parent a1fc89e commit 243ab3e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# ![Score](docs/images/logo.svg) Score overview

Score aims to improve developer producticity and experience by reducing the risk of configurtaion inconsistencies between local and remote environments. It provides developer-centric workload specification (`score.yaml`) which captures a workloads runtime requirements in a platform-agnostic manner.
Score aims to improve developer productivity and experience by reducing the risk of configuration inconsistencies between local and remote environments. It provides developer-centric workload specification (`score.yaml`) which captures a workloads runtime requirements in a platform-agnostic manner.

The `score.yaml` specification file can be executed against a _Score Implementation CLI_, a conversion tool for application developers to generate environment specific configuration. In combination with environment specific parameters, the CLI tool can run your workload in the target environment by generating a platform-specific configuration file such as `docker-compose.yaml` or a Helm `values.yaml`. Learn more [here](https://github.com/score-spec/spec#-what-is-score).

Expand Down
3 changes: 2 additions & 1 deletion examples/03-dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ resources:
properties:
domain:
backend:
type: workload
type: service
properties:
name:
port:
```
This example also uses an extensions file, called `humanitec.yaml`, that contains additional hints for `score-humanitec` CLI tool. This information would help the CLI tool to resolve the resources properly.
Expand Down
3 changes: 2 additions & 1 deletion examples/03-dependencies/score.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resources:
properties:
domain:
backend:
type: workload
type: service
properties:
name:
port:
2 changes: 1 addition & 1 deletion internal/humanitec/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func ConvertSpec(name, envID string, spec *score.WorkloadSpec, ext *extensions.H
var externals = map[string]interface{}{}
for name, res := range spec.Resources {
if meta, exists := ext.Resources[name]; !exists || meta.Scope == "" || meta.Scope == "external" {
if res.Type != "workload" && res.Type != "environment" {
if res.Type != "service" && res.Type != "environment" {
externals[name] = map[string]interface{}{
"type": res.Type,
}
Expand Down
8 changes: 4 additions & 4 deletions internal/humanitec/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestScoreConvert(t *testing.T) {
Variables: map[string]string{
"DEBUG": "${resources.env.DEBUG}",
"LOGS_LEVEL": "${pod.debug.level}",
"ORDERS_SERVICE": "http://${resources.orders.service.name}:${resources.orders.service.port}/api",
"ORDERS_SERVICE": "http://${resources.orders.name}:${resources.orders.port}/api",
"CONNECTION_STRING": "postgresql://${resources.db.host}:${resources.db.port}/${resources.db.name}",
"DOMAIN_NAME": "${resources.dns.domain}",
},
Expand Down Expand Up @@ -217,10 +217,10 @@ func TestScoreConvert(t *testing.T) {
},
},
"orders": {
Type: "workload",
Type: "service",
Properties: map[string]score.ResourcePropertySpec{
"service.name": {Required: false},
"service.port": {},
"name": {Required: false},
"port": {},
},
},
},
Expand Down
11 changes: 9 additions & 2 deletions internal/humanitec/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func buildContext(metadata score.WorkloadMeta, resources score.ResourcesSpecs, e
switch res.Type {
case "environment":
source = "values"
case "workload":
case "service":
source = fmt.Sprintf("modules.%s", resName)
default:
if resExt, exists := ext[resName]; exists && resExt.Scope == "shared" {
Expand All @@ -63,7 +63,14 @@ func buildContext(metadata score.WorkloadMeta, resources score.ResourcesSpecs, e
if _, exists := ctx[ref]; exists {
return nil, fmt.Errorf("ambiguous property reference '%s'", ref)
}
ctx[ref] = fmt.Sprintf("${%s.%s}", source, propName)
var sourceProp string
switch res.Type {
case "service":
sourceProp = fmt.Sprintf("service.%s", propName)
default:
sourceProp = propName
}
ctx[ref] = fmt.Sprintf("${%s.%s}", source, sourceProp)
}
}

Expand Down
39 changes: 24 additions & 15 deletions internal/humanitec/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func TestBuildContext(t *testing.T) {
},
},
"service-a": score.ResourceSpec{
Type: "workload",
Type: "service",
Properties: map[string]score.ResourcePropertySpec{
"service.name": {},
"name": {},
"port": {},
},
},
}
Expand All @@ -71,8 +72,9 @@ func TestBuildContext(t *testing.T) {
"resources.dns": "shared.dns",
"resources.dns.domain": "${shared.dns.domain}",

"resources.service-a": "modules.service-a",
"resources.service-a.service.name": "${modules.service-a.service.name}",
"resources.service-a": "modules.service-a",
"resources.service-a.name": "${modules.service-a.service.name}",
"resources.service-a.port": "${modules.service-a.service.port}",
}, context)
}

Expand All @@ -91,8 +93,9 @@ func TestMapVar(t *testing.T) {
"resources.dns": "shared.dns",
"resources.dns.domain": "${shared.dns.domain}",

"resources.service-a": "modules.service-a",
"resources.service-a.service.name": "${modules.service-a.service.name}",
"resources.service-a": "modules.service-a",
"resources.service-a.name": "${modules.service-a.service.name}",
"resources.service-a.port": "${modules.service-a.service.port}",
}

assert.Equal(t, "", context.mapVar(""))
Expand All @@ -110,6 +113,8 @@ func TestMapVar(t *testing.T) {
assert.Equal(t, "${externals.db.name}", context.mapVar("resources.db.name"))
assert.Equal(t, "${resources.db.name.nil}", context.mapVar("resources.db.name.nil"))
assert.Equal(t, "${resources.db.nil}", context.mapVar("resources.db.nil"))
assert.Equal(t, "${modules.service-a.service.name}", context.mapVar("resources.service-a.name"))
assert.Equal(t, "${modules.service-a.service.port}", context.mapVar("resources.service-a.port"))
assert.Equal(t, "${resources.nil}", context.mapVar("resources.nil"))
assert.Equal(t, "${nil.db.name}", context.mapVar("nil.db.name"))
}
Expand All @@ -129,8 +134,9 @@ func TestSubstitute(t *testing.T) {
"resources.dns": "shared.dns",
"resources.dns.domain": "${shared.dns.domain}",

"resources.service-a": "modules.service-a",
"resources.service-a.service.name": "${modules.service-a.service.name}",
"resources.service-a": "modules.service-a",
"resources.service-a.name": "${modules.service-a.service.name}",
"resources.service-a.port": "${modules.service-a.service.port}",
}

assert.Equal(t, "", context.Substitute(""))
Expand Down Expand Up @@ -164,15 +170,17 @@ func TestSubstituteAll(t *testing.T) {
"resources.dns": "shared.dns",
"resources.dns.domain": "${shared.dns.domain}",

"resources.service-a": "modules.service-a",
"resources.service-a.service.name": "${modules.service-a.service.name}",
"resources.service-a": "modules.service-a",
"resources.service-a.name": "${modules.service-a.service.name}",
"resources.service-a.port": "${modules.service-a.service.port}",
}

var source = map[string]interface{}{
"api": map[string]interface{}{
"${resources.service-a.service.name}": map[string]interface{}{
"url": "http://${resources.dns.domain}",
"port": 80,
"${resources.service-a.name}": map[string]interface{}{
"url": "http://${resources.dns.domain}",
"port": "${resources.service-a.port}",
"retry": 10,
},
},
"DEBUG": "${resources.env.DEBUG}",
Expand All @@ -181,8 +189,9 @@ func TestSubstituteAll(t *testing.T) {
var expected = map[string]interface{}{
"api": map[string]interface{}{
"${modules.service-a.service.name}": map[string]interface{}{
"url": "http://${shared.dns.domain}",
"port": 80,
"url": "http://${shared.dns.domain}",
"port": "${modules.service-a.service.port}",
"retry": 10,
},
},
"DEBUG": "${values.DEBUG}",
Expand Down

0 comments on commit 243ab3e

Please sign in to comment.