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

Commit

Permalink
Merge pull request #2388 from ibuildthecloud/main
Browse files Browse the repository at this point in the history
Add assistants and functions
  • Loading branch information
ibuildthecloud authored Dec 21, 2023
2 parents 17a4108 + 7052f38 commit 707f2e8
Show file tree
Hide file tree
Showing 39 changed files with 1,169 additions and 49 deletions.
2 changes: 1 addition & 1 deletion generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//go:generate go run github.com/acorn-io/baaah/cmd/deepcopy ./pkg/apis/api.acorn.io/v1/
//go:generate go run github.com/acorn-io/baaah/cmd/deepcopy ./pkg/apis/internal.admin.acorn.io/v1/
//go:generate go run github.com/acorn-io/baaah/cmd/deepcopy ./pkg/apis/admin.acorn.io/v1/
//go:generate go run k8s.io/kube-openapi/cmd/openapi-gen -i github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1,github.com/acorn-io/runtime/pkg/apis/api.acorn.io/v1,github.com/acorn-io/runtime/pkg/apis/internal.admin.acorn.io/v1,github.com/acorn-io/runtime/pkg/apis/admin.acorn.io/v1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/version,k8s.io/apimachinery/pkg/api/resource,k8s.io/api/core/v1,k8s.io/api/rbac/v1,k8s.io/apimachinery/pkg/util/intstr -p ./pkg/openapi/generated -h tools/header.txt
//go:generate go run k8s.io/kube-openapi/cmd/openapi-gen -i github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1,github.com/acorn-io/runtime/pkg/apis/api.acorn.io/v1,github.com/acorn-io/runtime/pkg/apis/internal.admin.acorn.io/v1,github.com/acorn-io/runtime/pkg/apis/admin.acorn.io/v1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/version,k8s.io/apimachinery/pkg/api/resource,k8s.io/api/core/v1,k8s.io/api/rbac/v1,k8s.io/apimachinery/pkg/util/intstr,github.com/acorn-io/aml/pkg/jsonschema -p ./pkg/openapi/generated -h tools/header.txt
//go:generate go run github.com/golang/mock/mockgen --build_flags=--mod=mod -destination=./pkg/mocks/mock_client.go -package=mocks github.com/acorn-io/runtime/pkg/client Client,ProjectClientFactory
//go:generate go run github.com/golang/mock/mockgen --build_flags=--mod=mod -destination=./pkg/mocks/dns/mock.go -package=mocks github.com/acorn-io/runtime/pkg/dns Client
//go:generate go run github.com/golang/mock/mockgen --build_flags=--mod=mod -destination=./pkg/mocks/k8s/mock.go -package=mocks sigs.k8s.io/controller-runtime/pkg/client Reader
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ replace (
require (
cuelang.org/go v0.6.0
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/acorn-io/aml v0.0.0-20231122062516-f2ffb1e58cbd
github.com/acorn-io/aml v0.0.0-20231221034445-53c14e08c5ab
github.com/acorn-io/aml/cli v0.0.0-20231113171943-4844e2f3e1a2
github.com/acorn-io/aml/legacy v0.0.0-20230929081514-1e9f3394432e
github.com/acorn-io/baaah v0.0.0-20231009165317-af2b68361b8a
github.com/acorn-io/baaah v0.0.0-20231221034928-dfcf962a9d5b
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 Down Expand Up @@ -142,7 +142,7 @@ require (
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fujiwara/shapeio v1.0.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpH
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/acorn-io/aml v0.0.0-20231122062516-f2ffb1e58cbd h1:VfEyBeMeEXaz0R7KPZxkU9QKIfFuBWempchm4OAUXTU=
github.com/acorn-io/aml v0.0.0-20231122062516-f2ffb1e58cbd/go.mod h1:jImvyZGYOReKDJEEjS2SLjvVAEFcXFMA7OPQ96l1JYA=
github.com/acorn-io/aml v0.0.0-20231221034445-53c14e08c5ab h1:Xd/y9RIZ6XZTg4968sTR1XxNxxgne+3UVjXF7y6wdus=
github.com/acorn-io/aml v0.0.0-20231221034445-53c14e08c5ab/go.mod h1:z/Tz4f5dWHj/F5THru0+IQBIq31Xq06S5b7YpPkV7K0=
github.com/acorn-io/aml/cli v0.0.0-20231113171943-4844e2f3e1a2 h1:CtflOEPAvtpALuC3SM1WApsfTuECXcDuq25E3fZaPdg=
github.com/acorn-io/aml/cli v0.0.0-20231113171943-4844e2f3e1a2/go.mod h1:D4tWmJlLdsmMbQ/MI4T+Tj4j2PjgTAdde2QDGkeWH20=
github.com/acorn-io/aml/legacy v0.0.0-20230929081514-1e9f3394432e h1:W67DG9AcoNvBwIOR9OFUCZlSJBaHuvM2kXQ2+C6EnLk=
github.com/acorn-io/aml/legacy v0.0.0-20230929081514-1e9f3394432e/go.mod h1:XnJZSZq/tG/jWPE/tmm2zy90gOZrJRIaOyKpoMulxfE=
github.com/acorn-io/baaah v0.0.0-20231009165317-af2b68361b8a h1:0bHfiYUw4ojXCUfGHUPmRewrgJ/EpLQ4BaR4yEy8BC4=
github.com/acorn-io/baaah v0.0.0-20231009165317-af2b68361b8a/go.mod h1:1KSGxZt0E2MDedJESKUUYtxCwsJ3A+xZiw2QD8cVbjU=
github.com/acorn-io/baaah v0.0.0-20231221034928-dfcf962a9d5b h1:2k0eAzaBBmvEcC0Adqvl0rg/GpUgQxlJLvIPQFztgCI=
github.com/acorn-io/baaah v0.0.0-20231221034928-dfcf962a9d5b/go.mod h1:1KSGxZt0E2MDedJESKUUYtxCwsJ3A+xZiw2QD8cVbjU=
github.com/acorn-io/cmd v0.0.0-20230929053520-ebe1b9879b38 h1:oJMGvI702ZW5L0JjJfGV9ekzU2IqqTGjmAQl4gkO6Ro=
github.com/acorn-io/cmd v0.0.0-20230929053520-ebe1b9879b38/go.mod h1:bo9ONX4kagbQmXcG4bnfoK53MBFFtbUZ5fR7s9NfS+M=
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c h1:3equCG9oMf2I5iDZxllb41jmNNSTiIpU3IegCHBtVyk=
Expand Down Expand Up @@ -347,8 +347,8 @@ github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fujiwara/shapeio v1.0.0 h1:xG5D9oNqCSUUbryZ/jQV3cqe1v2suEjwPIcEg1gKM8M=
github.com/fujiwara/shapeio v1.0.0/go.mod h1:LmEmu6L/8jetyj1oewewFb7bZCNRwE7wLCUNzDLaLVA=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
Expand Down Expand Up @@ -1349,7 +1349,6 @@ golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/api.acorn.io/v1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions pkg/apis/internal.acorn.io/v1/appinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
AppInstanceConditionSecrets = "secrets"
AppInstanceConditionServices = "services"
AppInstanceConditionContainers = "containers"
AppInstanceConditionFunctions = "functions"
AppInstanceConditionJobs = "jobs"
AppInstanceConditionAcorns = "acorns"
AppInstanceConditionRouters = "routers"
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/internal.acorn.io/v1/appspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"strings"

"github.com/acorn-io/aml/pkg/jsonschema"
"golang.org/x/exp/slices"
rbacv1 "k8s.io/api/rbac/v1"
)
Expand Down Expand Up @@ -665,6 +666,9 @@ type Container struct {

// Sidecars are not available on sidecars
Sidecars map[string]Container `json:"sidecars,omitempty"`

// InputSchema is only available on function
InputSchema *jsonschema.Schema `json:"inputSchema,omitempty"`
}

type Image struct {
Expand All @@ -682,15 +686,29 @@ type AppSpec struct {
Info string `json:"info,omitempty"`
Icon string `json:"icon,omitempty"`
Containers map[string]Container `json:"containers,omitempty"`
Functions map[string]Container `json:"functions,omitempty"`
Jobs map[string]Container `json:"jobs,omitempty"`
Images map[string]Image `json:"images,omitempty"`
Volumes map[string]VolumeRequest `json:"volumes,omitempty"`
Secrets map[string]Secret `json:"secrets,omitempty"`
Acorns map[string]Acorn `json:"acorns,omitempty"`
Routers map[string]Router `json:"routers,omitempty"`
Services map[string]Service `json:"services,omitempty"`
Assistants map[string]Assistant `json:"assistants,omitempty"`
}

type Assistant struct {
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Prompts Prompts `json:"prompts,omitempty"`
Dependencies Dependencies `json:"tools,omitempty"`
InputSchema *jsonschema.Schema `json:"inputSchema,omitempty"`
}

type Prompts []string

type Route struct {
Path string `json:"path,omitempty"`
TargetServiceName string `json:"targetServiceName,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/internal.acorn.io/v1/appstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type AppStatus struct {
Permissions []Permissions `json:"permissions,omitempty"`

Containers map[string]ContainerStatus `json:"containers,omitempty"`
Functions map[string]ContainerStatus `json:"functions,omitempty"`
Jobs map[string]JobStatus `json:"jobs,omitempty"`
Volumes map[string]VolumeStatus `json:"volumes,omitempty"`
Secrets map[string]SecretStatus `json:"secrets,omitempty"`
Expand Down Expand Up @@ -183,6 +184,7 @@ const (
DependencyService = DependencyType("service")
DependencyJob = DependencyType("job")
DependencyContainer = DependencyType("container")
DependencyFunction = DependencyType("function")
)

func (in JobStatus) GetCommonStatus() CommonStatus {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/internal.acorn.io/v1/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type BuilderSpec struct {
Readme string `json:"readme,omitempty"`
Services map[string]AcornBuilderSpec `json:"services,omitempty"`
Containers map[string]ContainerImageBuilderSpec `json:"containers,omitempty"`
Functions map[string]ContainerImageBuilderSpec `json:"functions,omitempty"`
Jobs map[string]ContainerImageBuilderSpec `json:"jobs,omitempty"`
Images map[string]ImageBuilderSpec `json:"images,omitempty"`
Acorns map[string]AcornBuilderSpec `json:"acorns,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/internal.acorn.io/v1/imageinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ImageData struct {

type ImagesData struct {
Containers map[string]ContainerData `json:"containers,omitempty"`
Functions map[string]ContainerData `json:"functions,omitempty"`
Jobs map[string]ContainerData `json:"jobs,omitempty"`
Images map[string]ImageData `json:"images,omitempty"`
Acorns map[string]ImageData `json:"acorns,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/internal.acorn.io/v1/labelsannotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
const (
LabelTypeRouter = "router"
LabelTypeContainer = "container"
LabelTypeFunction = "function"
LabelTypeJob = "job"
LabelTypeVolume = "volume"
LabelTypeSecret = "secret"
Expand All @@ -21,6 +22,8 @@ var canonicalTypes = map[string]string{
"routers": LabelTypeRouter,
"container": LabelTypeContainer,
"containers": LabelTypeContainer,
"function": LabelTypeFunction,
"functions": LabelTypeFunction,
"job": LabelTypeJob,
"jobs": LabelTypeJob,
"volume": LabelTypeVolume,
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/internal.acorn.io/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type ServiceInstanceSpec struct {
Address string `json:"address,omitempty"`
Ports Ports `json:"ports,omitempty"`
Container string `json:"container,omitempty"`
Function string `json:"function,omitempty"`
Job string `json:"job,omitempty"`
ContainerLabels map[string]string `json:"containerLabels,omitempty"`
Secrets []string `json:"secrets,omitempty"`
Expand Down
45 changes: 42 additions & 3 deletions pkg/apis/internal.acorn.io/v1/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ func checkForDuplicateNames(in *AppSpec) error {
return err
}
}
for name := range in.Functions {
if err := addName(names, name, "function"); err != nil {
return err
}
}
for name := range in.Jobs {
if err := addName(names, name, "job"); err != nil {
return err
Expand All @@ -455,6 +460,11 @@ func checkForDuplicateNames(in *AppSpec) error {
return err
}
}
for name := range in.Assistants {
if err := addName(names, name, "assistant"); err != nil {
return err
}
}

return nil
}
Expand Down Expand Up @@ -504,6 +514,19 @@ func addImpliedResources(in *AppSpec) error {
}
}

for functionName, c := range in.Functions {
impliedSecretsForContainer(in, c)
if err := impliedVolumesForContainer(in, functionName, "", c); err != nil {
return err
}
for sidecarName, s := range c.Sidecars {
impliedSecretsForContainer(in, s)
if err := impliedVolumesForContainer(in, functionName, sidecarName, s); err != nil {
return err
}
}
}

for containerName, j := range in.Jobs {
impliedSecretsForContainer(in, j)
if err := impliedVolumesForContainer(in, containerName, "", j); err != nil {
Expand Down Expand Up @@ -681,13 +704,13 @@ func (c containerAliases) SetContainer(dst Container) Container {
dst.Dirs = c.Directories
}
if len(c.DependsOn) > 0 {
dst.Dependencies = c.DependsOn
dst.Dependencies = append(dst.Dependencies, c.DependsOn...)
}
if len(c.DependsOnUnderscore) > 0 {
dst.Dependencies = c.DependsOnUnderscore
dst.Dependencies = append(dst.Dependencies, c.DependsOnUnderscore...)
}
if len(c.Consumes) > 0 {
dst.Dependencies = c.Consumes
dst.Dependencies = append(dst.Dependencies, c.Consumes...)
}
if c.Memory != nil {
dst.Memory = c.Memory
Expand Down Expand Up @@ -736,6 +759,22 @@ func (in *Acorn) UnmarshalJSON(data []byte) error {
return nil
}

func (in *Prompts) UnmarshalJSON(data []byte) error {
*in = Prompts{}

if isString(data) {
s, err := parseString(data)
if err != nil {
return err
}
*in = append(*in, s)
return nil
}

type prompts Prompts
return json.Unmarshal(data, (*prompts)(in))
}

func (in *Container) UnmarshalJSON(data []byte) error {
var c Container
type container Container
Expand Down
Loading

0 comments on commit 707f2e8

Please sign in to comment.