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

Commit

Permalink
Fix app info for top level acorns
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Shepherd <darren@acorn.io>
  • Loading branch information
ibuildthecloud committed Aug 23, 2023
1 parent 1306d93 commit bb90c04
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 22 deletions.
37 changes: 37 additions & 0 deletions integration/services/services_test.go
Expand Up @@ -9,8 +9,45 @@ import (
"github.com/acorn-io/runtime/pkg/client"
"github.com/acorn-io/runtime/pkg/labels"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestServiceInfo(t *testing.T) {
helper.StartController(t)

ctx := helper.GetCTX(t)
c, _ := helper.ClientAndProject(t)

image, err := c.AcornImageBuild(ctx, "./testdata/info/Acornfile", &client.AcornImageBuildOptions{
Cwd: "./testdata/info",
})
if err != nil {
t.Fatal(err)
}

app, err := c.AppRun(ctx, image.ID, nil)
if err != nil {
t.Fatal(err)
}

k, err := c.GetClient()
if err != nil {
t.Fatal(err)
}

helper.WaitForObject(t, k.Watch, &apiv1.AppList{}, app, func(obj *apiv1.App) bool {
return obj.Status.Ready
})

i, err := c.AppInfo(ctx, app.Name)
require.NoError(t, err)
assert.Equal(t, "top message", i)

i, err = c.AppInfo(ctx, app.Name+".nested")
require.NoError(t, err)
assert.Equal(t, "nested message", i)
}

func TestServices(t *testing.T) {
helper.StartController(t)

Expand Down
6 changes: 6 additions & 0 deletions integration/services/testdata/info/Acornfile
@@ -0,0 +1,6 @@
info: "top message"
acorns: nested: {
build: {
acornfile: "./nested.acorn"
}
}
1 change: 1 addition & 0 deletions integration/services/testdata/info/nested.acorn
@@ -0,0 +1 @@
info: "nested message"
5 changes: 5 additions & 0 deletions pkg/cli/testdata/MockClient.go
Expand Up @@ -159,6 +159,11 @@ func (m *MockClient) DevSessionRelease(ctx context.Context, name string) error {
panic("implement me")
}

func (m *MockClient) AppInfo(ctx context.Context, name string) (string, error) {
//TODO implement me
panic("implement me")
}

func (m *MockClient) AppPullImage(ctx context.Context, name string) error {
return nil
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/client/app.go
Expand Up @@ -594,6 +594,26 @@ func (c *DefaultClient) AppConfirmUpgrade(ctx context.Context, name string) erro
Body(&apiv1.ConfirmUpgrade{}).Do(ctx).Error()
}

func (c *DefaultClient) AppInfo(ctx context.Context, name string) (string, error) {
app := &apiv1.App{}
err := c.Client.Get(ctx, kclient.ObjectKey{
Name: name,
Namespace: c.Namespace,
}, app)
if err != nil {
return "", err
}

info := &apiv1.AppInfo{}
err = c.RESTClient.Get().
Namespace(app.Namespace).
Resource("apps").
Name(app.Name).
SubResource("info").
Do(ctx).Into(info)
return info.Info, err
}

func (c *DefaultClient) AppPullImage(ctx context.Context, name string) error {
app := &apiv1.App{}
err := c.Client.Get(ctx, kclient.ObjectKey{
Expand Down
1 change: 1 addition & 0 deletions pkg/client/client.go
Expand Up @@ -214,6 +214,7 @@ type Client interface {
AppRun(ctx context.Context, image string, opts *AppRunOptions) (*apiv1.App, error)
AppUpdate(ctx context.Context, name string, opts *AppUpdateOptions) (*apiv1.App, error)
AppLog(ctx context.Context, name string, opts *LogOptions) (<-chan apiv1.LogMessage, error)
AppInfo(ctx context.Context, name string) (string, error)
AppConfirmUpgrade(ctx context.Context, name string) error
AppPullImage(ctx context.Context, name string) error
AppIgnoreDeleteCleanup(ctx context.Context, name string) error
Expand Down
7 changes: 7 additions & 0 deletions pkg/client/deferred.go
Expand Up @@ -73,6 +73,13 @@ func (d *DeferredClient) AppRun(ctx context.Context, image string, opts *AppRunO
return d.Client.AppRun(ctx, image, opts)
}

func (d *DeferredClient) AppInfo(ctx context.Context, name string) (string, error) {
if err := d.create(); err != nil {
return "", err
}
return d.Client.AppInfo(ctx, name)
}

func (d *DeferredClient) AppUpdate(ctx context.Context, name string, opts *AppUpdateOptions) (*apiv1.App, error) {
if err := d.create(); err != nil {
return nil, err
Expand Down
14 changes: 14 additions & 0 deletions pkg/client/multi.go
Expand Up @@ -149,6 +149,20 @@ func (m *MultiClient) AppStop(ctx context.Context, name string) error {
return err
}

func (m *MultiClient) AppInfo(ctx context.Context, name string) (string, error) {
var (
info = ""
err error
)

_, err = onOne(ctx, m.Factory, name, func(name string, c Client) (*apiv1.App, error) {
info, err = c.AppInfo(ctx, name)
return &apiv1.App{}, err
})

return info, err
}

func (m *MultiClient) AppStart(ctx context.Context, name string) error {
_, err := onOne(ctx, m.Factory, name, func(name string, c Client) (*apiv1.App, error) {
return &apiv1.App{}, c.AppStart(ctx, name)
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/appstatus/appstatus.go
Expand Up @@ -156,6 +156,12 @@ func setCondition[T commonStatusGetter](obj kclient.Object, conditionName string
errorMessages = append(errorMessages, formatMessage(name, status.ErrorMessages, ", "))
} else if len(status.TransitioningMessages) > 0 {
transitioningMessages = append(transitioningMessages, formatMessage(name, status.TransitioningMessages, ", "))
} else if !status.Defined {
transitioningMessages = append(transitioningMessages, formatMessage(name, []string{"pending"}, ", "))
} else if !status.UpToDate {
transitioningMessages = append(transitioningMessages, formatMessage(name, []string{"updating"}, ", "))
} else if !status.Ready {
transitioningMessages = append(transitioningMessages, formatMessage(name, []string{"not ready"}, ", "))
}
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/mocks/mock_client.go

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

57 changes: 35 additions & 22 deletions pkg/server/registry/apigroups/acorn/apps/info.go
Expand Up @@ -2,6 +2,7 @@ package apps

import (
"context"
"strings"

"github.com/acorn-io/mink/pkg/stores"
"github.com/acorn-io/mink/pkg/types"
Expand Down Expand Up @@ -34,31 +35,43 @@ type InfoStrategy struct {
func (s *InfoStrategy) Get(ctx context.Context, namespace, name string) (types.Object, error) {
ri, _ := request.RequestInfoFrom(ctx)

app := &apiv1.App{}
err := s.client.Get(ctx, kclient.ObjectKey{Namespace: ri.Namespace, Name: ri.Name}, app)
if err != nil {
return nil, err
}
var (
appInstance = &v1.AppInstance{}
err error
)

appInstances := &v1.AppInstanceList{}
err = s.client.List(ctx, appInstances, &kclient.ListOptions{
LabelSelector: klabels.SelectorFromSet(klabels.Set{
labels.AcornPublicName: name,
}),
Namespace: ri.Namespace,
})
if err != nil {
return nil, err
}
if strings.Contains(name, ".") {
app := &apiv1.App{}
err := s.client.Get(ctx, kclient.ObjectKey{Namespace: ri.Namespace, Name: ri.Name}, app)
if err != nil {
return nil, err
}

if len(appInstances.Items) != 1 {
return nil, apierrors.NewNotFound(schema.GroupResource{
Group: apiv1.SchemeGroupVersion.Group,
Resource: "apps",
}, name)
}
appInstances := &v1.AppInstanceList{}
err = s.client.List(ctx, appInstances, &kclient.ListOptions{
LabelSelector: klabels.SelectorFromSet(klabels.Set{
labels.AcornPublicName: name,
}),
Namespace: ri.Namespace,
})
if err != nil {
return nil, err
}

appInstance := &appInstances.Items[0]
if len(appInstances.Items) != 1 {
return nil, apierrors.NewNotFound(schema.GroupResource{
Group: apiv1.SchemeGroupVersion.Group,
Resource: "apps",
}, name)
}

appInstance = &appInstances.Items[0]
} else {
err := s.client.Get(ctx, kclient.ObjectKey{Namespace: ri.Namespace, Name: ri.Name}, appInstance)
if err != nil {
return nil, err
}
}

resp := &apiv1.AppInfo{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit bb90c04

Please sign in to comment.