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

Commit

Permalink
Add more stuff to imagedetails
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Jun 24, 2022
1 parent 5f02681 commit 58c4f7f
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 20 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ replace (
github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220121014307-40bb9831756f+incompatible
github.com/rancher/apiserver => github.com/acorn-io/apiserver-1 v0.0.0-20220608053213-0ffc3be57697
github.com/rancher/lasso => github.com/acorn-io/lasso v0.0.0-20220519152917-47b14aceb5cf
github.com/rancher/steve => github.com/acorn-io/steve v0.0.0-20220525234928-3ccc837e8406
go.etcd.io/etcd/server/v3 v3.5.1 => github.com/acorn-io/etcd/server/v3 v3.5.1-ot-1
k8s.io/apiserver => github.com/acorn-io/apiserver v0.24.1-ot-1
k8s.io/client-go => k8s.io/client-go v0.24.1
Expand Down Expand Up @@ -35,7 +34,7 @@ require (
github.com/rancher/apiserver v0.0.0-20220513144301-4808910b5d4d
github.com/rancher/kubernetes-provider-detector v0.1.5
github.com/rancher/lasso v0.0.0-20220412224715-5f3517291ad4
github.com/rancher/steve v0.0.0-20220503004032-53511a06ff37
github.com/rancher/steve v0.0.0-20220624231620-3d379c3dd867
github.com/rancher/wrangler v1.0.1-0.20220520195731-8eeded9bae2a
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ github.com/acorn-io/etcd/server/v3 v3.5.1-ot-1 h1:MlyJCGYCmK9g7y3qjRQChBjDRLcjuH
github.com/acorn-io/etcd/server/v3 v3.5.1-ot-1/go.mod h1:3f9zpU8GP1dDA34jCqy3kIvaolyrUJmIiQ6AV/LvZsM=
github.com/acorn-io/lasso v0.0.0-20220519152917-47b14aceb5cf h1:y2vkS4R2O+iRDUP8QLvS10i7RoVaMP4spSPGdM93jXo=
github.com/acorn-io/lasso v0.0.0-20220519152917-47b14aceb5cf/go.mod h1:T6WoUopOHBWTGjnphruTJAgoZ+dpm6llvn6GDYaa7Kw=
github.com/acorn-io/steve v0.0.0-20220525234928-3ccc837e8406 h1:UHTQsw9T7IxPWno5sN0dbEBFlzuxmRYr/Yx232lRr1o=
github.com/acorn-io/steve v0.0.0-20220525234928-3ccc837e8406/go.mod h1:n1dJWcWsVKYElmmKlNt8w6KcpaK61M7PDiXrnAqeNSw=
github.com/adrg/xdg v0.3.1 h1:uIyL9BYfXaFgDyVRKE8wjtm6ETQULweQqTofphEFJYY=
github.com/adrg/xdg v0.3.1/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
Expand Down Expand Up @@ -1388,6 +1386,8 @@ github.com/rancher/norman v0.0.0-20210423002317-8e6ffc77a819 h1:K3pICsdBbzOHoOyW
github.com/rancher/norman v0.0.0-20210423002317-8e6ffc77a819/go.mod h1:hhnf77V2lmZD7cvUqi4vTBpIs3KpHNL/AmuN0MqEClI=
github.com/rancher/remotedialer v0.2.6-0.20220104192242-f3837f8d649a h1:Go8MpBEeZCR0yV1ylu2/KjJBvpYomIezU58pejYCtgk=
github.com/rancher/remotedialer v0.2.6-0.20220104192242-f3837f8d649a/go.mod h1:vq3LvyOFnLcwMiCE1KdW3foPd6g5kAjZOtOb7JqGHck=
github.com/rancher/steve v0.0.0-20220624231620-3d379c3dd867 h1:X30nwX8PAz1xqyUexAW2WfeiooTJ0lV+WDAmTgE8cuM=
github.com/rancher/steve v0.0.0-20220624231620-3d379c3dd867/go.mod h1:n1dJWcWsVKYElmmKlNt8w6KcpaK61M7PDiXrnAqeNSw=
github.com/rancher/wrangler v0.6.1/go.mod h1:L4HtjPeX8iqLgsxfJgz+JjKMcX2q3qbRXSeTlC/CSd4=
github.com/rancher/wrangler v0.6.2-0.20200714200521-c61fae623942/go.mod h1:8LdIqAQPHysxNlHqmKbUiDIx9ULt9IHUauh9aOnr67k=
github.com/rancher/wrangler v0.6.2-0.20200820173016-2068de651106/go.mod h1:iKqQcYs4YSDjsme52OZtQU4jHPmLlIiM93aj2c8c/W8=
Expand Down
8 changes: 7 additions & 1 deletion pkg/apis/api.acorn.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ type ImageDetails struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

AppImage v1.AppImage `json:"appImage,omitempty"`
DeployArgs v1.GenericMap `json:"deployArgs,omitempty"`
Profiles []string `json:"profiles,omitempty"`

AppImage v1.AppImage `json:"appImage,omitempty"`
AppSpec *v1.AppSpec `json:"appSpec,omitempty"`
Params *v1.ParamSpec `json:"params,omitempty"`
ParseError string `json:"parseError,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
16 changes: 16 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.

8 changes: 7 additions & 1 deletion pkg/apis/internal.acorn.io/v1/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ type BuilderSpec struct {
}

type ParamSpec struct {
Params []Param `json:"params,omitempty"`
Params []Param `json:"params,omitempty"`
Profiles []Profile `json:"profiles,omitempty"`
}

type Profile struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}

type Param struct {
Expand Down
20 changes: 20 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.

3 changes: 2 additions & 1 deletion pkg/apis/ui.acorn.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type Cluster struct {
}

type ClusterSpec struct {
Address string
Default bool `json:"default,omitempty"`
Address string `json:"address,omitempty"`
}

type ClusterStatus struct {
Expand Down
24 changes: 22 additions & 2 deletions pkg/appdefinition/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ import (
)

func (a *AppDefinition) BuildParams() (*v1.ParamSpec, error) {
return a.args("args.build")
return a.addProfiles(a.args("args.build"))
}

func (a *AppDefinition) DeployParams() (*v1.ParamSpec, error) {
return a.args("args.deploy")
return a.addProfiles(a.args("args.deploy"))
}

func (a *AppDefinition) addProfiles(paramSpec *v1.ParamSpec, err error) (*v1.ParamSpec, error) {
if err != nil {
return nil, err
}

profiles, err := a.args("profiles")
if err != nil {
return nil, err
}

for _, profile := range profiles.Params {
paramSpec.Profiles = append(paramSpec.Profiles, v1.Profile{
Name: profile.Name,
Description: profile.Description,
})
}

return paramSpec, nil
}

func (a *AppDefinition) args(section string) (*v1.ParamSpec, error) {
Expand Down
86 changes: 84 additions & 2 deletions pkg/openapi/generated/openapi_generated.go

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

58 changes: 56 additions & 2 deletions pkg/server/registry/images/detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"strings"

apiv1 "github.com/acorn-io/acorn/pkg/apis/api.acorn.io/v1"
"github.com/acorn-io/acorn/pkg/appdefinition"
"github.com/acorn-io/acorn/pkg/pull"
"github.com/acorn-io/acorn/pkg/tags"
apierror "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -34,9 +36,29 @@ func (s *ImageDetails) New() runtime.Object {
return &apiv1.ImageDetails{}
}

func (s *ImageDetails) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
if createValidation != nil {
if err := createValidation(ctx, obj); err != nil {
return nil, err
}
}

details := obj.(*apiv1.ImageDetails)
if details.Name == "" {
ri, ok := request.RequestInfoFrom(ctx)
if ok {
details.Name = ri.Name
}
}
return s.get(ctx, details.Name, details.Profiles, details.DeployArgs)
}

func (s *ImageDetails) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
name = strings.ReplaceAll(name, "+", "/")
return s.get(ctx, name, nil, nil)
}

func (s *ImageDetails) get(ctx context.Context, name string, profiles []string, deployArgs map[string]interface{}) (runtime.Object, error) {
ns, _ := request.NamespaceFrom(ctx)
imageName := name

Expand All @@ -55,11 +77,43 @@ func (s *ImageDetails) Get(ctx context.Context, name string, options *metav1.Get
return nil, err
}

return &apiv1.ImageDetails{
result := &apiv1.ImageDetails{
ObjectMeta: metav1.ObjectMeta{
Name: imageName,
Namespace: ns,
},
AppImage: *appImage,
}, nil
}

appDef, err := appdefinition.NewAppDefinition([]byte(appImage.Acornfile))
if err != nil {
result.ParseError = err.Error()
return result, nil
}

if len(deployArgs) > 0 || len(profiles) > 0 {
appDef, deployArgs, err = appDef.WithDeployArgs(deployArgs, profiles)
if err != nil {
result.ParseError = err.Error()
return result, nil
}
result.DeployArgs = deployArgs
}

appSpec, err := appDef.AppSpec()
if err != nil {
result.ParseError = err.Error()
return result, nil
}

result.AppSpec = appSpec

paramSpec, err := appDef.DeployParams()
if err != nil {
result.ParseError = err.Error()
return result, nil
}

result.Params = paramSpec
return result, nil
}

0 comments on commit 58c4f7f

Please sign in to comment.