Skip to content

Commit

Permalink
feat(ui): add package detail page #172
Browse files Browse the repository at this point in the history
  • Loading branch information
christophenne committed Feb 14, 2024
1 parent 3e7236a commit 926a58b
Show file tree
Hide file tree
Showing 24 changed files with 640 additions and 254 deletions.
13 changes: 10 additions & 3 deletions api/v1alpha1/package_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ type PlainManifest struct {
Url string `json:"url" jsonschema:"required"`
}

type PackageReference struct {
Label string `json:"label" jsonschema:"required"`
Url string `json:"url" jsonschema:"required"`
}

type PackageManifest struct {
Name string `json:"name" jsonschema:"required"`
ShortDescription string `json:"shortDescription,omitempty"`
IconUrl string `json:"iconUrl,omitempty" jsonschema:"format=uri"`
Name string `json:"name" jsonschema:"required"`
ShortDescription string `json:"shortDescription,omitempty"`
LongDescription string `json:"longDescription,omitempty"`
References []PackageReference `json:"references,omitempty"`
IconUrl string `json:"iconUrl,omitempty" jsonschema:"format=uri"`
// Helm instructs the controller to create a helm release when installing this package.
Helm *HelmManifest `json:"helm,omitempty"`
// Kustomize instructs the controller to apply a kustomization when installing this package [PLACEHOLDER].
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

5 changes: 2 additions & 3 deletions cmd/glasskube/cmd/serve.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"os"

Expand Down Expand Up @@ -46,9 +45,9 @@ var serveCmd = &cobra.Command{
}
}

var ctx context.Context
var ctx = cmd.Context()
if cfg != nil {
ctx, err = client.SetupContext(cmd.Context(), cfg)
ctx, err = client.SetupContext(ctx, cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "An error occurred starting the webserver:\n\n%v\n", err)
os.Exit(1)
Expand Down
14 changes: 14 additions & 0 deletions config/crd/bases/packages.glasskube.dev_packageinfos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ spec:
description: Kustomize instructs the controller to apply a kustomization
when installing this package [PLACEHOLDER].
type: object
longDescription:
type: string
manifests:
items:
properties:
Expand All @@ -191,6 +193,18 @@ spec:
type: array
name:
type: string
references:
items:
properties:
label:
type: string
url:
type: string
required:
- label
- url
type: object
type: array
shortDescription:
type: string
required:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/fatih/color v1.16.0
github.com/fluxcd/helm-controller/api v0.37.4
github.com/fluxcd/source-controller/api v1.2.4
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.1
github.com/invopop/jsonschema v0.12.0
github.com/onsi/ginkgo/v2 v2.15.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 h1:dHLYa5D8/Ta0aLR2Xc
github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
Expand Down Expand Up @@ -246,8 +246,6 @@ k8s.io/kube-openapi v0.0.0-20240105020646-a37d4de58910 h1:1Rp/XEKP5uxPs6QrsngEHA
k8s.io/kube-openapi v0.0.0-20240105020646-a37d4de58910/go.mod h1:Pa1PvrP7ACSkuX6I7KYomY6cmMA0Tx86waBhDUgoKPw=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.17.0 h1:fjJQf8Ukya+VjogLO6/bNX9HE6Y2xpsO5+fyS26ur/s=
sigs.k8s.io/controller-runtime v0.17.0/go.mod h1:+MngTvIQQQhfXtwfdGw/UOQ/aIaqsYywfCINOtwMO/s=
sigs.k8s.io/controller-runtime v0.17.1 h1:V1dQELMGVk46YVXXQUbTFujU7u4DQj6YUj9Rb6cuzz8=
sigs.k8s.io/controller-runtime v0.17.1/go.mod h1:+MngTvIQQQhfXtwfdGw/UOQ/aIaqsYywfCINOtwMO/s=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/packageinfo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (r *PackageInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

if shouldSyncFromRepo(packageInfo) {
if err := repo.FetchPackageManifest(ctx, &packageInfo); err != nil {
if err := repo.LoadPackageManifest(ctx, &packageInfo); err != nil {
err1 := conditions.SetFailedAndUpdate(ctx, r.Client, r.EventRecorder, &packageInfo, &packageInfo.Status.Conditions, condition.SyncFailed, err.Error())
return requeue.Always(ctx, multierr.Append(err, err1))
} else {
Expand Down
21 changes: 20 additions & 1 deletion internal/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@ type PackageTeaser struct {
IconUrl string `json:"iconUrl,omitempty"`
}

func FetchPackageManifest(ctx context.Context, pi *packagesv1alpha1.PackageInfo) error {
func GetPackageManifest(repoUrl string, pkgName string) (*packagesv1alpha1.PackageManifest, error) {
if len(repoUrl) == 0 {
repoUrl = defaultRepositoryUrl
}
url, err := url.JoinPath(repoUrl, pkgName, "package.yaml")
if err != nil {
return nil, err
}
body, err := doFetch(url)
if err != nil {
return nil, err
}
var manifest packagesv1alpha1.PackageManifest
if err = yaml.Unmarshal(body, &manifest); err != nil {
return nil, err
}
return &manifest, nil
}

func LoadPackageManifest(ctx context.Context, pi *packagesv1alpha1.PackageInfo) error {
log := log.FromContext(ctx)
url, err := getPackageManifestUrl(*pi)
if err != nil {
Expand Down
46 changes: 0 additions & 46 deletions internal/web/components/installbutton.go

This file was deleted.

55 changes: 55 additions & 0 deletions internal/web/components/pkg_detail_btns/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package pkg_detail_btns

import (
"fmt"
"html/template"
"io"
"os"

"github.com/glasskube/glasskube/api/v1alpha1"
"github.com/glasskube/glasskube/pkg/client"
)

const TemplateId = "pkg-detail-btns"

type pkgDetailBtnsInput struct {
ContainerId string
Swap string
PackageName string
Status *client.PackageStatus
Manifest *v1alpha1.PackageManifest
}

func getId(pkgName string) string {
return fmt.Sprintf("%v-%v", TemplateId, pkgName)
}

func getSwap(id string) string {
return fmt.Sprintf("outerHTML:#%s", id)
}

func Render(w io.Writer, tmpl *template.Template, pkgName string, status *client.PackageStatus, manifest *v1alpha1.PackageManifest) {
id := getId(pkgName)
err := tmpl.ExecuteTemplate(w, TemplateId, &pkgDetailBtnsInput{
ContainerId: id,
Swap: getSwap(id),
PackageName: pkgName,
Status: status,
Manifest: manifest,
})
if err != nil {
fmt.Fprintf(os.Stderr, "An error occurred rendering %v for %v: \n%v\n"+
"This is most likely a BUG!", TemplateId, pkgName, err)
}
}

func ForPkgDetailBtns(pkgName string, status *client.PackageStatus, manifest *v1alpha1.PackageManifest) *pkgDetailBtnsInput {
id := getId(pkgName)
return &pkgDetailBtnsInput{
ContainerId: id,
Swap: "",
PackageName: pkgName,
Status: status,
Manifest: manifest,
}
}
52 changes: 52 additions & 0 deletions internal/web/components/pkg_overview_btn/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package pkg_overview_btn

import (
"fmt"
"html/template"
"io"
"os"

"github.com/glasskube/glasskube/api/v1alpha1"
"github.com/glasskube/glasskube/pkg/client"
"github.com/glasskube/glasskube/pkg/list"
)

const TemplateId = "pkg-overview-btn"

type pkgOverviewBtnInput struct {
ButtonId string
Swap string
PackageName string
Status *client.PackageStatus
Manifest *v1alpha1.PackageManifest
}

func getButtonId(pkgName string) string {
return fmt.Sprintf("%v-%v", TemplateId, pkgName)
}

func Render(w io.Writer, tmpl *template.Template, pkgName string, status *client.PackageStatus, manifest *v1alpha1.PackageManifest) {
buttonId := getButtonId(pkgName)
err := tmpl.ExecuteTemplate(w, TemplateId, &pkgOverviewBtnInput{
ButtonId: buttonId,
Swap: fmt.Sprintf("outerHTML:#%s", buttonId),
PackageName: pkgName,
Status: status,
Manifest: manifest,
})
if err != nil {
fmt.Fprintf(os.Stderr, "An error occurred rendering %v for %v: \n%v\n"+
"This is most likely a BUG!", TemplateId, pkgName, err)
}
}

func ForPkgOverviewBtn(pkgTeaser *list.PackageTeaserWithStatus) *pkgOverviewBtnInput {
buttonId := getButtonId(pkgTeaser.PackageName)
return &pkgOverviewBtnInput{
ButtonId: buttonId,
Swap: "",
PackageName: pkgTeaser.PackageName,
Status: pkgTeaser.Status,
Manifest: pkgTeaser.InstalledManifest,
}
}
Loading

0 comments on commit 926a58b

Please sign in to comment.