Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ replace (
require (
cuelang.org/go v0.5.0
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/acorn-io/aml v0.0.0-20230814072513-12acbd5f883c
github.com/acorn-io/baaah v0.0.0-20230818001243-36c10b8f8e7b
github.com/acorn-io/aml v0.0.0-20230827061234-6707a74cdc97
github.com/acorn-io/baaah v0.0.0-20230827055549-50fb849cd5d3
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78
github.com/acorn-io/z v0.0.0-20230714155009-a770ecbbdc45
Expand All @@ -37,6 +37,7 @@ require (
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.5.0
github.com/hexops/autogold/v2 v2.1.0
github.com/hexops/valast v1.4.3
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
github.com/loft-sh/devspace v1.1.1-0.20221217093921-7604c5857f98
github.com/moby/buildkit v0.11.6
Expand Down Expand Up @@ -171,7 +172,6 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/hexops/valast v1.4.3 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/in-toto/in-toto-golang v0.9.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ github.com/ThalesIgnite/crypto11 v1.2.5 h1:1IiIIEqYmBvUYFeMnHqRft4bwf/O36jryEUpY
github.com/ThalesIgnite/crypto11 v1.2.5/go.mod h1:ILDKtnCKiQ7zRoNxcp36Y1ZR8LBPmR2E23+wTQe/MlE=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/acorn-io/aml v0.0.0-20230814072513-12acbd5f883c h1:S3TEHyI7VtPm54Nwrg4Su7fnWClD9/AwlIPujDqjFGs=
github.com/acorn-io/aml v0.0.0-20230814072513-12acbd5f883c/go.mod h1:UEx5RRLFjryCEHN2pM59+d8A0mPJ3VAxggJOTzPymwg=
github.com/acorn-io/baaah v0.0.0-20230818001243-36c10b8f8e7b h1:sqU9W1Oq3zuzIBlcqCnCbrwFuOrWb6zKz6s1rZrJRAg=
github.com/acorn-io/baaah v0.0.0-20230818001243-36c10b8f8e7b/go.mod h1:1KSGxZt0E2MDedJESKUUYtxCwsJ3A+xZiw2QD8cVbjU=
github.com/acorn-io/aml v0.0.0-20230827061234-6707a74cdc97 h1:ygErLRK5S+mu9EhV9hTfCIZL/WY5r+Z2Vp8KY6F9WF0=
github.com/acorn-io/aml v0.0.0-20230827061234-6707a74cdc97/go.mod h1:UEx5RRLFjryCEHN2pM59+d8A0mPJ3VAxggJOTzPymwg=
github.com/acorn-io/baaah v0.0.0-20230827055549-50fb849cd5d3 h1:NKK5Vs6dybjU2Wl7+9ecgl2mZ8oavT2mBPW2Se8Ce0A=
github.com/acorn-io/baaah v0.0.0-20230827055549-50fb849cd5d3/go.mod h1:1KSGxZt0E2MDedJESKUUYtxCwsJ3A+xZiw2QD8cVbjU=
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c h1:3equCG9oMf2I5iDZxllb41jmNNSTiIpU3IegCHBtVyk=
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c/go.mod h1:Zn9T1kdnsXJbhRp6G4LZUPuq9URlzQAoYwHA1U1r7Bg=
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78 h1:5zs9L/CXNkuTdJSbhFWczAorbmx67nqlqswx5CQi7XI=
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/internal.acorn.io/v1/appspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ type Acorn struct {
NotifyUpgrade *bool `json:"notifyUpgrade,omitempty"`
AutoUpgradeInterval string `json:"autoUpgradeInterval,omitempty"`
Memory MemoryMap `json:"memory,omitempty"`
ComputeClasses ComputeClassMap `json:"computeClasses,omitempty"`
ComputeClasses ComputeClassMap `json:"class,omitempty"`
Permissions map[string]Permissions `json:"permissions,omitempty"`
}

Expand Down Expand Up @@ -803,6 +803,7 @@ type Service struct {
NotifyUpgrade *bool `json:"notifyUpgrade,omitempty"`
AutoUpgradeInterval string `json:"autoUpgradeInterval,omitempty"`
Memory MemoryMap `json:"memory,omitempty"`
ComputeClasses ComputeClassMap `json:"class,omitempty"`
Permissions map[string]Permissions `json:"permissions,omitempty"`
Consumer *ServiceConsumer `json:"consumer,omitempty"`
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/internal.acorn.io/v1/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ func (in *Quantity) UnmarshalJSON(data []byte) error {
return nil
}

func (in *ComputeClassMap) UnmarshalJSON(data []byte) error {
if isObject(data) {
return json.Unmarshal(data, (*map[string]string)(in))
}
s, err := parseString(data)
if err != nil {
return err
}
*in = ComputeClassMap{
"": s,
}
return nil
}

func (in *MemoryMap) UnmarshalJSON(data []byte) error {
if isObject(data) {
return json.Unmarshal(data, (*map[string]*int64)(in))
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/internal.acorn.io/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions pkg/appdefinition/appdefinition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
"github.com/acorn-io/baaah/pkg/typed"
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/z"
"github.com/hexops/autogold/v2"
"github.com/hexops/valast"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

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

func TestComputeMemOnNested(t *testing.T) {
appImage, err := NewAppDefinition([]byte(`
services: sdef: {
class: "foo"
mem: 1G
}
services: snodef: {
class: {
"foo": "bar"
}
mem: {
"foo": 1G
}
}
acorns: def: {
class: "foo"
mem: 1G
}
acorns: nodef: {
class: {
"foo": "bar"
}
mem: {
"foo": 1G
}
}`))
if err != nil {
t.Fatal(err)
}

appSpec, err := appImage.AppSpec()
require.NoError(t, err)

autogold.Expect(&v1.AppSpec{
Labels: map[string]string{},
Annotations: map[string]string{},
Containers: map[string]v1.Container{},
Jobs: map[string]v1.Container{},
Images: map[string]v1.Image{},
Volumes: map[string]v1.VolumeRequest{},
Secrets: map[string]v1.Secret{},
Acorns: map[string]v1.Acorn{
"def": {
Labels: v1.ScopedLabels{},
Annotations: v1.ScopedLabels{},
Profiles: []string{},
DeployArgs: v1.GenericMap{},
Publish: v1.PortBindings{},
Secrets: v1.SecretBindings{},
Volumes: v1.VolumeBindings{},
Links: v1.ServiceBindings{},
AutoUpgrade: valast.Addr(false).(*bool),
NotifyUpgrade: valast.Addr(false).(*bool),
Memory: v1.MemoryMap{"": valast.Addr(int64(1000000000)).(*int64)},
ComputeClasses: v1.ComputeClassMap{"": "foo"},
Permissions: map[string]v1.Permissions{},
},
"nodef": {
Labels: v1.ScopedLabels{},
Annotations: v1.ScopedLabels{},
Profiles: []string{},
DeployArgs: v1.GenericMap{},
Publish: v1.PortBindings{},
Secrets: v1.SecretBindings{},
Volumes: v1.VolumeBindings{},
Links: v1.ServiceBindings{},
AutoUpgrade: valast.Addr(false).(*bool),
NotifyUpgrade: valast.Addr(false).(*bool),
Memory: v1.MemoryMap{"foo": valast.Addr(int64(1000000000)).(*int64)},
ComputeClasses: v1.ComputeClassMap{"foo": "bar"},
Permissions: map[string]v1.Permissions{},
},
},
Routers: map[string]v1.Router{},
Services: map[string]v1.Service{
"sdef": {
Labels: v1.ScopedLabels{},
Annotations: v1.ScopedLabels{},
ServiceArgs: v1.GenericMap{},
Secrets: v1.SecretBindings{},
Links: v1.ServiceBindings{},
AutoUpgrade: valast.Addr(false).(*bool),
NotifyUpgrade: valast.Addr(false).(*bool),
Memory: v1.MemoryMap{"": valast.Addr(int64(1000000000)).(*int64)},
ComputeClasses: v1.ComputeClassMap{"": "foo"},
Permissions: map[string]v1.Permissions{},
},
"snodef": {
Labels: v1.ScopedLabels{},
Annotations: v1.ScopedLabels{},
ServiceArgs: v1.GenericMap{},
Secrets: v1.SecretBindings{},
Links: v1.ServiceBindings{},
AutoUpgrade: valast.Addr(false).(*bool),
NotifyUpgrade: valast.Addr(false).(*bool),
Memory: v1.MemoryMap{"foo": valast.Addr(int64(1000000000)).(*int64)},
ComputeClasses: v1.ComputeClassMap{"foo": "bar"},
Permissions: map[string]v1.Permissions{},
},
},
}).Equal(t, appSpec)
}

func TestNestedScopedLabels(t *testing.T) {
// labels and annotations on a acorn are both unmarshalled into a ScopedLabels struct, which is just a slice
// Similar to ports, in the Acornfile you can define them using an object syntax or short-form string syntax.
Expand Down
18 changes: 12 additions & 6 deletions pkg/cli/builder/table/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ func Noop(obj any) string {
}

func Trunc(s string) string {
if tags.SHAPattern.MatchString(s) && len(s) > 12 {
return s[:12]
t := s
suffix := ""
if strings.HasSuffix(t, "*") {
t = t[:len(t)-1]
suffix = "*"
}
if tags.SHAPattern.MatchString(t) && len(s) > 12 {
return s[:12] + suffix
}
if tags.DigestPattern.MatchString(s) && len(s) > 12 {
return s[7:19]
if tags.DigestPattern.MatchString(t) && len(s) > 12 {
return t[7:19] + suffix
}
if tags.CommitPattern.MatchString(s) && len(s) > 12 {
return s[:12]
if tags.CommitPattern.MatchString(t) && len(s) > 12 {
return t[:12] + suffix
}
return s
}
Expand Down
56 changes: 56 additions & 0 deletions pkg/controller/appdefinition/acorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func toAcorns(appInstance *v1.AppInstance, tag name.Reference, pullSecrets *Pull
NotifyUpgrade: service.NotifyUpgrade,
AutoUpgradeInterval: service.AutoUpgradeInterval,
Memory: service.Memory,
ComputeClasses: service.ComputeClasses,
}))
}
return result
Expand All @@ -84,6 +85,59 @@ func scopeSecrets(app *v1.AppInstance, bindings v1.SecretBindings) (result v1.Se
return
}

func trimPrefixComputeClass(app *v1.AppInstance, compute v1.ComputeClassMap, name string) (result v1.ComputeClassMap) {
prefix := name + "."
result = map[string]string{}
for k, v := range compute {
result[k] = v
}

// add default first to maintain idempotency
for id, class := range app.Spec.ComputeClasses {
if id == "" {
result[""] = class
}
}

for id, class := range app.Spec.ComputeClasses {
if id == "" {
continue
}
if strings.HasPrefix(id, prefix) {
result[strings.TrimPrefix(id, prefix)] = class
} else if id == name {
result[""] = class
}
}

return
}

func trimPrefixMemory(app *v1.AppInstance, memory v1.MemoryMap, name string) (result v1.MemoryMap) {
prefix := name + "."
result = map[string]*int64{}
for k, v := range memory {
result[k] = v
}

// add default first to maintain idempotency
for id, mem := range app.Spec.Memory {
if id == "" {
result[""] = mem
}
}

for id, mem := range app.Spec.Memory {
if strings.HasPrefix(id, prefix) {
result[strings.TrimPrefix(id, prefix)] = mem
} else if id == name {
result[""] = mem
}
}

return
}

func scopeLinks(app *v1.AppInstance, bindings v1.ServiceBindings) (result v1.ServiceBindings) {
for _, binding := range bindings {
binding.Service = publicname.Get(app) + "." + binding.Service
Expand Down Expand Up @@ -147,6 +201,8 @@ func toAcorn(appInstance *v1.AppInstance, tag name.Reference, pullSecrets *PullS
AutoUpgrade: acorn.AutoUpgrade,
AutoUpgradeInterval: acorn.AutoUpgradeInterval,
NotifyUpgrade: acorn.NotifyUpgrade,
ComputeClasses: trimPrefixComputeClass(appInstance, acorn.ComputeClasses, acornName),
Memory: trimPrefixMemory(appInstance, acorn.Memory, acornName),
},
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/controller/appdefinition/acorn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ package appdefinition
import (
"testing"

"github.com/acorn-io/baaah/pkg/router"
"github.com/acorn-io/baaah/pkg/router/tester"
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/scheme"
"github.com/acorn-io/z"
"github.com/hexops/autogold/v2"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestAcornLabels(t *testing.T) {
Expand All @@ -14,3 +20,49 @@ func TestAcornLabels(t *testing.T) {
func TestAcornBasic(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/acorn/basic", DeploySpec)
}

func TestComputeMem(t *testing.T) {
h := tester.Harness{
Scheme: scheme.Scheme,
}

resp, err := h.Invoke(t, &v1.AppInstance{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "app",
Namespace: "app-namespace",
},
Spec: v1.AppInstanceSpec{
Memory: map[string]*int64{
"": z.Pointer(int64(1)),
"byname": z.Pointer(int64(2)),
"byname.child": z.Pointer(int64(3)),
},
ComputeClasses: map[string]string{
"": "defaultValue",
"byname": "byNameValue",
"byname.child": "byNameChildValue",
},
},
Status: v1.AppInstanceStatus{
Namespace: "app-created-namespace",
AppImage: v1.AppImage{
ID: "foo",
},
AppSpec: v1.AppSpec{
Acorns: map[string]v1.Acorn{
"byname": {
Image: "foo",
},
"other": {
Image: "foo",
},
},
},
},
}, router.HandlerFunc(DeploySpec))

require.NoError(t, err)

autogold.ExpectFile(t, h.SanitizedYAML(t, resp.Collected))
}
Loading