Skip to content

Commit

Permalink
Pass featureMode in menu items (#295)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored May 8, 2024
1 parent 220e991 commit 9d9d35d
Show file tree
Hide file tree
Showing 19 changed files with 220 additions and 57 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require (
kmodules.xyz/custom-resources v0.29.1
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/monitoring-agent-api v0.29.0
kmodules.xyz/resource-metadata v0.18.4-0.20240507203038-74ed30e3192f
kmodules.xyz/resource-metadata v0.18.4-0.20240508091636-af957419033d
kmodules.xyz/resource-metrics v0.29.5
kmodules.xyz/sets v0.29.0
kubeops.dev/falco-ui-server v0.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3490,8 +3490,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9
kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI=
kmodules.xyz/offshoot-api v0.29.0 h1:GHLhxxT9jU1N8+FvOCCeJNyU5g0duYS46UGrs6AHNLY=
kmodules.xyz/offshoot-api v0.29.0/go.mod h1:5NxhBblXoDHWStx9HCDJR2KFTwYjEZ7i1Id3jelIunw=
kmodules.xyz/resource-metadata v0.18.4-0.20240507203038-74ed30e3192f h1:ANis2aCNRIL/SJJoS9IiV9T3oaYIbjbgFVv0TfEar8s=
kmodules.xyz/resource-metadata v0.18.4-0.20240507203038-74ed30e3192f/go.mod h1:HY6FmDDzQOEHfIEHRiqwNXVyof3uRIDtLSu0Yi1mIBw=
kmodules.xyz/resource-metadata v0.18.4-0.20240508091636-af957419033d h1:bx0zkG52i/zispkGB9gudcqVuoawzeeGs6p8P9Js5s4=
kmodules.xyz/resource-metadata v0.18.4-0.20240508091636-af957419033d/go.mod h1:HY6FmDDzQOEHfIEHRiqwNXVyof3uRIDtLSu0Yi1mIBw=
kmodules.xyz/resource-metrics v0.29.5 h1:ciuvRXuXsloLNW/JwkubqbYySsvHvHr6/nhkTL5Sf1o=
kmodules.xyz/resource-metrics v0.29.5/go.mod h1:OuG/QobZ7o8GFHl/u3lqaUR0fDZDegxtV8Vdh+MNBD4=
kmodules.xyz/sets v0.29.0 h1:ZX/qOECzUob95JhhRtngJElHSlJ1UNNdwK4hTEy+nl0=
Expand Down
19 changes: 10 additions & 9 deletions pkg/menu/accordion_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
helmshared "x-helm.dev/apimachinery/apis/shared"
)

func RenderAccordionMenu(kc client.Client, disco discovery.ServerResourcesInterface, menuName string) (*rsapi.Menu, error) {
func RenderAccordionMenu(kc client.Client, disco discovery.DiscoveryInterface, menuName string) (*rsapi.Menu, error) {
mo, err := menuoutlines.LoadByName(menuName)
if err != nil {
return nil, err
Expand Down Expand Up @@ -76,14 +76,15 @@ func RenderAccordionMenu(kc client.Client, disco discovery.ServerResourcesInterf
items := make([]rsapi.MenuItem, 0, len(so.Items))
for _, item := range so.Items {
mi := rsapi.MenuItem{
Name: item.Name,
Path: item.Path,
Resource: nil,
Missing: true,
Required: item.Required,
LayoutName: item.LayoutName,
Icons: item.Icons,
Installer: nil,
Name: item.Name,
Path: item.Path,
Resource: nil,
Missing: true,
Required: item.Required,
LayoutName: item.LayoutName,
Icons: item.Icons,
Installer: nil,
FeatureMode: item.FeatureMode,
}

if item.Type != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/menu/coomplete_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var defaultIcons = []helmshared.ImageSpec{
},
}

func GenerateCompleteMenu(kc client.Client, disco discovery.ServerResourcesInterface) (*rsapi.Menu, error) {
func GenerateCompleteMenu(kc client.Client, disco discovery.DiscoveryInterface) (*rsapi.Menu, error) {
sectionIcons := map[string][]helmshared.ImageSpec{}
for _, m := range menuoutlines.List() {
for _, sec := range m.Spec.Sections {
Expand Down
45 changes: 33 additions & 12 deletions pkg/menu/gallery_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ import (
"fmt"
"sort"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kmodules.xyz/client-go/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/discovery/cached/memory"
"k8s.io/client-go/restmapper"
mu "kmodules.xyz/client-go/meta"
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
"kmodules.xyz/resource-metadata/hub/resourceeditors"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -32,10 +37,12 @@ func GetGalleryMenu(driver *UserMenuDriver, opts *rsapi.RenderMenuRequest) (*rsa
if err != nil {
return nil, err
}
return RenderGalleryMenu(driver.GetClient(), menu, opts)
return RenderGalleryMenu(driver.GetClient(), driver.disco, menu, opts)
}

func RenderGalleryMenu(kc client.Client, in *rsapi.Menu, opts *rsapi.RenderMenuRequest) (*rsapi.Menu, error) {
func RenderGalleryMenu(kc client.Client, disco discovery.DiscoveryInterface, in *rsapi.Menu, opts *rsapi.RenderMenuRequest) (*rsapi.Menu, error) {
mapper := restmapper.NewDeferredDiscoveryRESTMapper(memory.NewMemCacheClient(disco))

out := rsapi.Menu{
TypeMeta: metav1.TypeMeta{
APIVersion: rsapi.SchemeGroupVersion.String(),
Expand All @@ -56,21 +63,25 @@ func RenderGalleryMenu(kc client.Client, in *rsapi.Menu, opts *rsapi.RenderMenuR
items := make([]rsapi.MenuItem, 0)
for _, item := range so.Items {
mi := rsapi.MenuItem{
Name: item.Name,
Path: item.Path,
Resource: item.Resource,
Missing: item.Missing,
Required: item.Required,
LayoutName: item.LayoutName,
Icons: item.Icons,
Installer: item.Installer,
Name: item.Name,
Path: item.Path,
Resource: item.Resource,
Missing: item.Missing,
Required: item.Required,
LayoutName: item.LayoutName,
Icons: item.Icons,
Installer: item.Installer,
FeatureMode: item.FeatureMode,
}

if mi.Resource != nil &&
opts.Type != nil &&
(opts.Type.Group != mi.Resource.Group || opts.Type.Kind != mi.Resource.Kind) {
continue
}
if mi.Resource.Kind != "" && !gkExists(mapper, item.Resource.GroupKind()) {
mi.Missing = true
}

ed, ok := resourceeditors.LoadByResourceID(kc, mi.Resource)
if !ok || ed.Spec.UI == nil || ed.Spec.UI.Options == nil || len(ed.Spec.Variants) == 0 {
Expand All @@ -84,7 +95,7 @@ func RenderGalleryMenu(kc client.Client, in *rsapi.Menu, opts *rsapi.RenderMenuR

chartRef := ed.Spec.UI.Options
if chartRef.SourceRef.Namespace == "" {
chartRef.SourceRef.Namespace = meta.PodNamespace()
chartRef.SourceRef.Namespace = mu.PodNamespace()
}

for _, ref := range ed.Spec.Variants {
Expand Down Expand Up @@ -118,3 +129,13 @@ func RenderGalleryMenu(kc client.Client, in *rsapi.Menu, opts *rsapi.RenderMenuR

return &out, nil
}

func gkExists(mapper meta.RESTMapper, gk schema.GroupKind) bool {
if _, err := mapper.RESTMappings(schema.GroupKind{
Group: gk.Group,
Kind: gk.Kind,
}); err == nil {
return true
}
return false
}
2 changes: 1 addition & 1 deletion pkg/menu/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func RenderMenu(driver *UserMenuDriver, req *rsapi.RenderMenuRequest) (*rsapi.Me
}
}

func GenerateMenuItems(kc client.Client, disco discovery.ServerResourcesInterface) (map[string]map[string]*rsapi.MenuItem, error) {
func GenerateMenuItems(kc client.Client, disco discovery.DiscoveryInterface) (map[string]map[string]*rsapi.MenuItem, error) {
rsLists, err := disco.ServerPreferredResources()
if err != nil && !discovery.IsGroupDiscoveryFailedError(err) {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/menu/usermenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ import (

type UserMenuDriver struct {
kc client.Client
disco discovery.ServerResourcesInterface
disco discovery.DiscoveryInterface
ns string
user string
}

func NewUserMenuDriver(kc client.Client, disco discovery.ServerResourcesInterface, ns, user string) *UserMenuDriver {
func NewUserMenuDriver(kc client.Client, disco discovery.DiscoveryInterface, ns, user string) *UserMenuDriver {
return &UserMenuDriver{
kc: kc,
disco: disco,
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/meta/rendermenu/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

type Storage struct {
kc client.Client
disco discovery.ServerResourcesInterface
disco discovery.DiscoveryInterface
ns string
}

Expand All @@ -47,7 +47,7 @@ var (
_ rest.SingularNameProvider = &Storage{}
)

func NewStorage(kc client.Client, disco discovery.ServerResourcesInterface, ns string) *Storage {
func NewStorage(kc client.Client, disco discovery.DiscoveryInterface, ns string) *Storage {
return &Storage{
kc: kc,
disco: disco,
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/meta/usermenu/available.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

type AvailableStorage struct {
kc client.Client
disco discovery.ServerResourcesInterface
disco discovery.DiscoveryInterface
ns string
}

Expand All @@ -44,7 +44,7 @@ var (
_ rest.Getter = &AvailableStorage{}
)

func NewAvailableStorage(kc client.Client, disco discovery.ServerResourcesInterface, ns string) *AvailableStorage {
func NewAvailableStorage(kc client.Client, disco discovery.DiscoveryInterface, ns string) *AvailableStorage {
return &AvailableStorage{
kc: kc,
disco: disco,
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/meta/usermenu/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

type Storage struct {
kc client.Client
disco discovery.ServerResourcesInterface
disco discovery.DiscoveryInterface
ns string
convertor rest.TableConvertor
}
Expand All @@ -52,7 +52,7 @@ var (
_ rest.SingularNameProvider = &Storage{}
)

func NewStorage(kc client.Client, disco discovery.ServerResourcesInterface, ns string) *Storage {
func NewStorage(kc client.Client, disco discovery.DiscoveryInterface, ns string) *Storage {
return &Storage{
kc: kc,
disco: disco,
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/meta/vendormenu/available.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

type AvailableStorage struct {
kc client.Client
disco discovery.ServerResourcesInterface
disco discovery.DiscoveryInterface
}

var (
Expand All @@ -41,7 +41,7 @@ var (
_ rest.Getter = &AvailableStorage{}
)

func NewAvailableStorage(kc client.Client, disco discovery.ServerResourcesInterface) *AvailableStorage {
func NewAvailableStorage(kc client.Client, disco discovery.DiscoveryInterface) *AvailableStorage {
return &AvailableStorage{
kc: kc,
disco: disco,
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/meta/vendormenu/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

type Storage struct {
kc client.Client
disco discovery.ServerResourcesInterface
disco discovery.DiscoveryInterface
convertor rest.TableConvertor
}

Expand All @@ -48,7 +48,7 @@ var (
_ rest.SingularNameProvider = &Storage{}
)

func NewStorage(kc client.Client, disco discovery.ServerResourcesInterface) *Storage {
func NewStorage(kc client.Client, disco discovery.DiscoveryInterface) *Storage {
return &Storage{
kc: kc,
disco: disco,
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ type MenuSection struct {
Items []MenuItem `json:"items"`
}

// +kubebuilder:validation:Enum=ALPHA;BETA;GA
type FeatureMode string

const (
FeatureModeAlpha FeatureMode = "ALPHA"
FeatureModeBeta FeatureMode = "BETA"
FeatureModeGA FeatureMode = "GA"
)

type MenuSectionInfo struct {
Name string `json:"name,omitempty"`

Expand Down Expand Up @@ -81,6 +90,8 @@ type MenuItem struct {
// +optional
LayoutName string `json:"layoutName,omitempty"`
// +optional
FeatureMode FeatureMode `json:"featureMode,omitempty"`
// +optional
Icons []helmshared.ImageSpec `json:"icons,omitempty"`
Installer *shared.DeploymentParameters `json:"installer,omitempty"`
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ type MenuEntry struct {
// +optional
Required bool `json:"required,omitempty"`
// +optional
FeatureMode FeatureMode `json:"featureMode,omitempty"`
// +optional
Icons []helmshared.ImageSpec `json:"icons,omitempty"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ spec:
items:
items:
properties:
featureMode:
enum:
- ALPHA
- BETA
- GA
type: string
icons:
items:
description: ImageSpec contains information about an
Expand Down
Loading

0 comments on commit 9d9d35d

Please sign in to comment.