Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit 21f1918

Browse files
Merge pull request #2127 from ibuildthecloud/fix-info
Add class and mem to services and acorns
2 parents 15fc547 + 5b7fcf6 commit 21f1918

File tree

16 files changed

+483
-22
lines changed

16 files changed

+483
-22
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ replace (
1313
require (
1414
cuelang.org/go v0.5.0
1515
github.com/AlecAivazis/survey/v2 v2.3.6
16-
github.com/acorn-io/aml v0.0.0-20230814072513-12acbd5f883c
17-
github.com/acorn-io/baaah v0.0.0-20230818001243-36c10b8f8e7b
16+
github.com/acorn-io/aml v0.0.0-20230827061234-6707a74cdc97
17+
github.com/acorn-io/baaah v0.0.0-20230827055549-50fb849cd5d3
1818
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c
1919
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78
2020
github.com/acorn-io/z v0.0.0-20230714155009-a770ecbbdc45
@@ -37,6 +37,7 @@ require (
3737
github.com/google/uuid v1.3.0
3838
github.com/gorilla/websocket v1.5.0
3939
github.com/hexops/autogold/v2 v2.1.0
40+
github.com/hexops/valast v1.4.3
4041
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
4142
github.com/loft-sh/devspace v1.1.1-0.20221217093921-7604c5857f98
4243
github.com/moby/buildkit v0.11.6
@@ -171,7 +172,6 @@ require (
171172
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
172173
github.com/hashicorp/hcl v1.0.0 // indirect
173174
github.com/hexops/gotextdiff v1.0.3 // indirect
174-
github.com/hexops/valast v1.4.3 // indirect
175175
github.com/imdario/mergo v0.3.12 // indirect
176176
github.com/in-toto/in-toto-golang v0.9.0 // indirect
177177
github.com/inconshreveable/mousetrap v1.1.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ github.com/ThalesIgnite/crypto11 v1.2.5 h1:1IiIIEqYmBvUYFeMnHqRft4bwf/O36jryEUpY
9292
github.com/ThalesIgnite/crypto11 v1.2.5/go.mod h1:ILDKtnCKiQ7zRoNxcp36Y1ZR8LBPmR2E23+wTQe/MlE=
9393
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
9494
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
95-
github.com/acorn-io/aml v0.0.0-20230814072513-12acbd5f883c h1:S3TEHyI7VtPm54Nwrg4Su7fnWClD9/AwlIPujDqjFGs=
96-
github.com/acorn-io/aml v0.0.0-20230814072513-12acbd5f883c/go.mod h1:UEx5RRLFjryCEHN2pM59+d8A0mPJ3VAxggJOTzPymwg=
97-
github.com/acorn-io/baaah v0.0.0-20230818001243-36c10b8f8e7b h1:sqU9W1Oq3zuzIBlcqCnCbrwFuOrWb6zKz6s1rZrJRAg=
98-
github.com/acorn-io/baaah v0.0.0-20230818001243-36c10b8f8e7b/go.mod h1:1KSGxZt0E2MDedJESKUUYtxCwsJ3A+xZiw2QD8cVbjU=
95+
github.com/acorn-io/aml v0.0.0-20230827061234-6707a74cdc97 h1:ygErLRK5S+mu9EhV9hTfCIZL/WY5r+Z2Vp8KY6F9WF0=
96+
github.com/acorn-io/aml v0.0.0-20230827061234-6707a74cdc97/go.mod h1:UEx5RRLFjryCEHN2pM59+d8A0mPJ3VAxggJOTzPymwg=
97+
github.com/acorn-io/baaah v0.0.0-20230827055549-50fb849cd5d3 h1:NKK5Vs6dybjU2Wl7+9ecgl2mZ8oavT2mBPW2Se8Ce0A=
98+
github.com/acorn-io/baaah v0.0.0-20230827055549-50fb849cd5d3/go.mod h1:1KSGxZt0E2MDedJESKUUYtxCwsJ3A+xZiw2QD8cVbjU=
9999
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c h1:3equCG9oMf2I5iDZxllb41jmNNSTiIpU3IegCHBtVyk=
100100
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c/go.mod h1:Zn9T1kdnsXJbhRp6G4LZUPuq9URlzQAoYwHA1U1r7Bg=
101101
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78 h1:5zs9L/CXNkuTdJSbhFWczAorbmx67nqlqswx5CQi7XI=

pkg/apis/internal.acorn.io/v1/appspec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ type Acorn struct {
737737
NotifyUpgrade *bool `json:"notifyUpgrade,omitempty"`
738738
AutoUpgradeInterval string `json:"autoUpgradeInterval,omitempty"`
739739
Memory MemoryMap `json:"memory,omitempty"`
740-
ComputeClasses ComputeClassMap `json:"computeClasses,omitempty"`
740+
ComputeClasses ComputeClassMap `json:"class,omitempty"`
741741
Permissions map[string]Permissions `json:"permissions,omitempty"`
742742
}
743743

@@ -803,6 +803,7 @@ type Service struct {
803803
NotifyUpgrade *bool `json:"notifyUpgrade,omitempty"`
804804
AutoUpgradeInterval string `json:"autoUpgradeInterval,omitempty"`
805805
Memory MemoryMap `json:"memory,omitempty"`
806+
ComputeClasses ComputeClassMap `json:"class,omitempty"`
806807
Permissions map[string]Permissions `json:"permissions,omitempty"`
807808
Consumer *ServiceConsumer `json:"consumer,omitempty"`
808809
}

pkg/apis/internal.acorn.io/v1/unmarshal.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ func (in *Quantity) UnmarshalJSON(data []byte) error {
160160
return nil
161161
}
162162

163+
func (in *ComputeClassMap) UnmarshalJSON(data []byte) error {
164+
if isObject(data) {
165+
return json.Unmarshal(data, (*map[string]string)(in))
166+
}
167+
s, err := parseString(data)
168+
if err != nil {
169+
return err
170+
}
171+
*in = ComputeClassMap{
172+
"": s,
173+
}
174+
return nil
175+
}
176+
163177
func (in *MemoryMap) UnmarshalJSON(data []byte) error {
164178
if isObject(data) {
165179
return json.Unmarshal(data, (*map[string]*int64)(in))

pkg/apis/internal.acorn.io/v1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/appdefinition/appdefinition_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import (
1212
"github.com/acorn-io/baaah/pkg/typed"
1313
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
1414
"github.com/acorn-io/z"
15+
"github.com/hexops/autogold/v2"
16+
"github.com/hexops/valast"
1517
"github.com/stretchr/testify/assert"
18+
"github.com/stretchr/testify/require"
1619
)
1720

1821
func TestReadMeInfoIcon(t *testing.T) {
@@ -2966,6 +2969,109 @@ containers: default: image: "foo"
29662969
assert.Equal(t, v1.Probes(nil), spec.Containers["default"].Probes)
29672970
}
29682971

2972+
func TestComputeMemOnNested(t *testing.T) {
2973+
appImage, err := NewAppDefinition([]byte(`
2974+
services: sdef: {
2975+
class: "foo"
2976+
mem: 1G
2977+
}
2978+
services: snodef: {
2979+
class: {
2980+
"foo": "bar"
2981+
}
2982+
mem: {
2983+
"foo": 1G
2984+
}
2985+
}
2986+
acorns: def: {
2987+
class: "foo"
2988+
mem: 1G
2989+
}
2990+
acorns: nodef: {
2991+
class: {
2992+
"foo": "bar"
2993+
}
2994+
mem: {
2995+
"foo": 1G
2996+
}
2997+
}`))
2998+
if err != nil {
2999+
t.Fatal(err)
3000+
}
3001+
3002+
appSpec, err := appImage.AppSpec()
3003+
require.NoError(t, err)
3004+
3005+
autogold.Expect(&v1.AppSpec{
3006+
Labels: map[string]string{},
3007+
Annotations: map[string]string{},
3008+
Containers: map[string]v1.Container{},
3009+
Jobs: map[string]v1.Container{},
3010+
Images: map[string]v1.Image{},
3011+
Volumes: map[string]v1.VolumeRequest{},
3012+
Secrets: map[string]v1.Secret{},
3013+
Acorns: map[string]v1.Acorn{
3014+
"def": {
3015+
Labels: v1.ScopedLabels{},
3016+
Annotations: v1.ScopedLabels{},
3017+
Profiles: []string{},
3018+
DeployArgs: v1.GenericMap{},
3019+
Publish: v1.PortBindings{},
3020+
Secrets: v1.SecretBindings{},
3021+
Volumes: v1.VolumeBindings{},
3022+
Links: v1.ServiceBindings{},
3023+
AutoUpgrade: valast.Addr(false).(*bool),
3024+
NotifyUpgrade: valast.Addr(false).(*bool),
3025+
Memory: v1.MemoryMap{"": valast.Addr(int64(1000000000)).(*int64)},
3026+
ComputeClasses: v1.ComputeClassMap{"": "foo"},
3027+
Permissions: map[string]v1.Permissions{},
3028+
},
3029+
"nodef": {
3030+
Labels: v1.ScopedLabels{},
3031+
Annotations: v1.ScopedLabels{},
3032+
Profiles: []string{},
3033+
DeployArgs: v1.GenericMap{},
3034+
Publish: v1.PortBindings{},
3035+
Secrets: v1.SecretBindings{},
3036+
Volumes: v1.VolumeBindings{},
3037+
Links: v1.ServiceBindings{},
3038+
AutoUpgrade: valast.Addr(false).(*bool),
3039+
NotifyUpgrade: valast.Addr(false).(*bool),
3040+
Memory: v1.MemoryMap{"foo": valast.Addr(int64(1000000000)).(*int64)},
3041+
ComputeClasses: v1.ComputeClassMap{"foo": "bar"},
3042+
Permissions: map[string]v1.Permissions{},
3043+
},
3044+
},
3045+
Routers: map[string]v1.Router{},
3046+
Services: map[string]v1.Service{
3047+
"sdef": {
3048+
Labels: v1.ScopedLabels{},
3049+
Annotations: v1.ScopedLabels{},
3050+
ServiceArgs: v1.GenericMap{},
3051+
Secrets: v1.SecretBindings{},
3052+
Links: v1.ServiceBindings{},
3053+
AutoUpgrade: valast.Addr(false).(*bool),
3054+
NotifyUpgrade: valast.Addr(false).(*bool),
3055+
Memory: v1.MemoryMap{"": valast.Addr(int64(1000000000)).(*int64)},
3056+
ComputeClasses: v1.ComputeClassMap{"": "foo"},
3057+
Permissions: map[string]v1.Permissions{},
3058+
},
3059+
"snodef": {
3060+
Labels: v1.ScopedLabels{},
3061+
Annotations: v1.ScopedLabels{},
3062+
ServiceArgs: v1.GenericMap{},
3063+
Secrets: v1.SecretBindings{},
3064+
Links: v1.ServiceBindings{},
3065+
AutoUpgrade: valast.Addr(false).(*bool),
3066+
NotifyUpgrade: valast.Addr(false).(*bool),
3067+
Memory: v1.MemoryMap{"foo": valast.Addr(int64(1000000000)).(*int64)},
3068+
ComputeClasses: v1.ComputeClassMap{"foo": "bar"},
3069+
Permissions: map[string]v1.Permissions{},
3070+
},
3071+
},
3072+
}).Equal(t, appSpec)
3073+
}
3074+
29693075
func TestNestedScopedLabels(t *testing.T) {
29703076
// labels and annotations on a acorn are both unmarshalled into a ScopedLabels struct, which is just a slice
29713077
// Similar to ports, in the Acornfile you can define them using an object syntax or short-form string syntax.

pkg/cli/builder/table/funcs.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,20 @@ func Noop(obj any) string {
6262
}
6363

6464
func Trunc(s string) string {
65-
if tags.SHAPattern.MatchString(s) && len(s) > 12 {
66-
return s[:12]
65+
t := s
66+
suffix := ""
67+
if strings.HasSuffix(t, "*") {
68+
t = t[:len(t)-1]
69+
suffix = "*"
70+
}
71+
if tags.SHAPattern.MatchString(t) && len(s) > 12 {
72+
return s[:12] + suffix
6773
}
68-
if tags.DigestPattern.MatchString(s) && len(s) > 12 {
69-
return s[7:19]
74+
if tags.DigestPattern.MatchString(t) && len(s) > 12 {
75+
return t[7:19] + suffix
7076
}
71-
if tags.CommitPattern.MatchString(s) && len(s) > 12 {
72-
return s[:12]
77+
if tags.CommitPattern.MatchString(t) && len(s) > 12 {
78+
return t[:12] + suffix
7379
}
7480
return s
7581
}

pkg/controller/appdefinition/acorn.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func toAcorns(appInstance *v1.AppInstance, tag name.Reference, pullSecrets *Pull
7171
NotifyUpgrade: service.NotifyUpgrade,
7272
AutoUpgradeInterval: service.AutoUpgradeInterval,
7373
Memory: service.Memory,
74+
ComputeClasses: service.ComputeClasses,
7475
}))
7576
}
7677
return result
@@ -84,6 +85,59 @@ func scopeSecrets(app *v1.AppInstance, bindings v1.SecretBindings) (result v1.Se
8485
return
8586
}
8687

88+
func trimPrefixComputeClass(app *v1.AppInstance, compute v1.ComputeClassMap, name string) (result v1.ComputeClassMap) {
89+
prefix := name + "."
90+
result = map[string]string{}
91+
for k, v := range compute {
92+
result[k] = v
93+
}
94+
95+
// add default first to maintain idempotency
96+
for id, class := range app.Spec.ComputeClasses {
97+
if id == "" {
98+
result[""] = class
99+
}
100+
}
101+
102+
for id, class := range app.Spec.ComputeClasses {
103+
if id == "" {
104+
continue
105+
}
106+
if strings.HasPrefix(id, prefix) {
107+
result[strings.TrimPrefix(id, prefix)] = class
108+
} else if id == name {
109+
result[""] = class
110+
}
111+
}
112+
113+
return
114+
}
115+
116+
func trimPrefixMemory(app *v1.AppInstance, memory v1.MemoryMap, name string) (result v1.MemoryMap) {
117+
prefix := name + "."
118+
result = map[string]*int64{}
119+
for k, v := range memory {
120+
result[k] = v
121+
}
122+
123+
// add default first to maintain idempotency
124+
for id, mem := range app.Spec.Memory {
125+
if id == "" {
126+
result[""] = mem
127+
}
128+
}
129+
130+
for id, mem := range app.Spec.Memory {
131+
if strings.HasPrefix(id, prefix) {
132+
result[strings.TrimPrefix(id, prefix)] = mem
133+
} else if id == name {
134+
result[""] = mem
135+
}
136+
}
137+
138+
return
139+
}
140+
87141
func scopeLinks(app *v1.AppInstance, bindings v1.ServiceBindings) (result v1.ServiceBindings) {
88142
for _, binding := range bindings {
89143
binding.Service = publicname.Get(app) + "." + binding.Service
@@ -147,6 +201,8 @@ func toAcorn(appInstance *v1.AppInstance, tag name.Reference, pullSecrets *PullS
147201
AutoUpgrade: acorn.AutoUpgrade,
148202
AutoUpgradeInterval: acorn.AutoUpgradeInterval,
149203
NotifyUpgrade: acorn.NotifyUpgrade,
204+
ComputeClasses: trimPrefixComputeClass(appInstance, acorn.ComputeClasses, acornName),
205+
Memory: trimPrefixMemory(appInstance, acorn.Memory, acornName),
150206
},
151207
}
152208

pkg/controller/appdefinition/acorn_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ package appdefinition
33
import (
44
"testing"
55

6+
"github.com/acorn-io/baaah/pkg/router"
67
"github.com/acorn-io/baaah/pkg/router/tester"
8+
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
79
"github.com/acorn-io/runtime/pkg/scheme"
10+
"github.com/acorn-io/z"
11+
"github.com/hexops/autogold/v2"
12+
"github.com/stretchr/testify/require"
13+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
814
)
915

1016
func TestAcornLabels(t *testing.T) {
@@ -14,3 +20,49 @@ func TestAcornLabels(t *testing.T) {
1420
func TestAcornBasic(t *testing.T) {
1521
tester.DefaultTest(t, scheme.Scheme, "testdata/acorn/basic", DeploySpec)
1622
}
23+
24+
func TestComputeMem(t *testing.T) {
25+
h := tester.Harness{
26+
Scheme: scheme.Scheme,
27+
}
28+
29+
resp, err := h.Invoke(t, &v1.AppInstance{
30+
TypeMeta: metav1.TypeMeta{},
31+
ObjectMeta: metav1.ObjectMeta{
32+
Name: "app",
33+
Namespace: "app-namespace",
34+
},
35+
Spec: v1.AppInstanceSpec{
36+
Memory: map[string]*int64{
37+
"": z.Pointer(int64(1)),
38+
"byname": z.Pointer(int64(2)),
39+
"byname.child": z.Pointer(int64(3)),
40+
},
41+
ComputeClasses: map[string]string{
42+
"": "defaultValue",
43+
"byname": "byNameValue",
44+
"byname.child": "byNameChildValue",
45+
},
46+
},
47+
Status: v1.AppInstanceStatus{
48+
Namespace: "app-created-namespace",
49+
AppImage: v1.AppImage{
50+
ID: "foo",
51+
},
52+
AppSpec: v1.AppSpec{
53+
Acorns: map[string]v1.Acorn{
54+
"byname": {
55+
Image: "foo",
56+
},
57+
"other": {
58+
Image: "foo",
59+
},
60+
},
61+
},
62+
},
63+
}, router.HandlerFunc(DeploySpec))
64+
65+
require.NoError(t, err)
66+
67+
autogold.ExpectFile(t, h.SanitizedYAML(t, resp.Collected))
68+
}

0 commit comments

Comments
 (0)