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

feat: use resource id aliases in deltas for non-default classes #68

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions internal/humanitec/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ func ConvertSpec(name, envID, baseDir, workloadSourceURL string, spec *score.Wor
if len(res.Params) > 0 {
sharedRes["params"] = ctx.SubstituteAll(res.Params)
}
if class != "default" {
sharedRes["id"] = resId
resName = resName + "-class-" + class
}
shared = append(shared, humanitec.UpdateAction{
Operation: "add",
Path: "/" + resName,
Expand Down
25 changes: 25 additions & 0 deletions internal/humanitec/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func TestScoreConvert(t *testing.T) {
"CONNECTION_STRING": "postgresql://${resources.db.host}:${resources.db.port}/${resources.db.name}",
"DOMAIN_NAME": "${resources.dns.domain}",
"EXTERNAL_RESOURCE": "${resources.external-resource.name}",
"SENSITIVE_BUCKET": "${resources.sensitive-bucket.name}",
},
Files: []score.FileMountSpec{
{
Expand Down Expand Up @@ -340,6 +341,15 @@ func TestScoreConvert(t *testing.T) {
"host": "${resources.dns.host}",
},
},
"sensitive-bucket": {
Metadata: score.ResourceMeta{
Annotations: map[string]string{
AnnotationLabelResourceId: "shared.sensitive-bucket",
},
},
Type: "bucket",
Class: "sensitive",
},
},
},
Extensions: &extensions.HumanitecExtensionsSpec{
Expand Down Expand Up @@ -392,6 +402,7 @@ func TestScoreConvert(t *testing.T) {
"CONNECTION_STRING": "postgresql://${externals.annotations-db-id.host}:${externals.annotations-db-id.port}/${externals.annotations-db-id.name}",
"DOMAIN_NAME": "${shared.dns.domain}",
"EXTERNAL_RESOURCE": "${modules.test-module.externals.test-resource.name}",
"SENSITIVE_BUCKET": "${shared.sensitive-bucket-class-sensitive.name}",
},
"files": map[string]interface{}{
"/etc/backend/config.yaml": map[string]interface{}{
Expand Down Expand Up @@ -461,6 +472,15 @@ func TestScoreConvert(t *testing.T) {
},
},
Shared: []humanitec.UpdateAction{
{
Operation: "add",
Path: "/sensitive-bucket-class-sensitive",
Value: map[string]interface{}{
"type": "bucket",
"class": "sensitive",
"id": "shared.sensitive-bucket",
},
},
{
Operation: "add",
Path: "/dns",
Expand Down Expand Up @@ -489,7 +509,12 @@ func TestScoreConvert(t *testing.T) {
// On Success
//
assert.NoError(t, err)
expectedShared := tt.Output.Shared
tt.Output.Shared = nil
actualShared := res.Shared
res.Shared = nil
assert.Equal(t, tt.Output, res)
assert.ElementsMatch(t, expectedShared, actualShared)
}
})
}
Expand Down
4 changes: 4 additions & 0 deletions internal/humanitec/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func (ctx *templatesContext) mapVar(ref string) string {
}
// END (DEPRECATED)

if hasAnnotation && strings.HasPrefix(resId, "shared.") && (res.Class != "" && res.Class != "default") {
resId = "shared." + resName + "-class-" + res.Class
}

if resId != "" {
source = resId
} else {
Expand Down