Skip to content

Commit

Permalink
Load resource editor from cluster if overridden
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 7, 2024
1 parent 021ad18 commit c17e98a
Show file tree
Hide file tree
Showing 24 changed files with 129 additions and 84 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ require (
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/monitoring-agent-api v0.30.2-0.20241001043315-b98120efea48
kmodules.xyz/offshoot-api v0.30.1
kmodules.xyz/resource-metadata v0.18.16-0.20240929130110-f5f4e27aae5b
kmodules.xyz/resource-metadata v0.18.16
kmodules.xyz/resource-metrics v0.30.4
kmodules.xyz/resource-metrics/utils v0.30.4
kmodules.xyz/sets v0.29.0
kubeops.dev/falco-ui-server v0.0.4
kubeops.dev/scanner v0.0.18
kubepack.dev/lib-helm v0.29.10
kubepack.dev/lib-helm v0.29.11
sigs.k8s.io/cli-utils v0.37.2
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/yaml v1.4.0
Expand All @@ -80,7 +80,7 @@ require (
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/PuerkitoBio/purell v1.2.1 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go v1.47.9 // indirect
Expand All @@ -94,7 +94,7 @@ require (
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/dapr/go-sdk v1.8.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/cli v25.0.1+incompatible // indirect
github.com/docker/cli v26.1.3+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v26.1.5+incompatible // indirect
github.com/docker/docker-credential-helpers v0.8.0 // indirect
Expand Down Expand Up @@ -236,7 +236,7 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
helm.sh/helm/v3 v3.14.3 // indirect
helm.sh/helm/v3 v3.15.0 // indirect
k8s.io/cli-runtime v0.30.1 // indirect
k8s.io/component-helpers v0.29.0 // indirect
k8s.io/kms v0.30.3 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRB
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/alecthomas/kingpin/v2 v2.3.2/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0=
github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
Expand Down Expand Up @@ -118,8 +118,8 @@ github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkz
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/docker/cli v25.0.1+incompatible h1:mFpqnrS6Hsm3v1k7Wa/BO23oz0k121MTbTO1lpcGSkU=
github.com/docker/cli v25.0.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v26.1.3+incompatible h1:bUpXT/N0kDE3VUHI2r5VMsYQgi38kYuoC0oL9yt3lqc=
github.com/docker/cli v26.1.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v26.1.5+incompatible h1:NEAxTwEjxV6VbBMBoGG3zPqbiJosIApZjxlbrG9q3/g=
Expand Down Expand Up @@ -885,8 +885,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
helm.sh/helm/v3 v3.14.3 h1:HmvRJlwyyt9HjgmAuxHbHv3PhMz9ir/XNWHyXfmnOP4=
helm.sh/helm/v3 v3.14.3/go.mod h1:v6myVbyseSBJTzhmeE39UcPLNv6cQK6qss3dvgAySaE=
helm.sh/helm/v3 v3.15.0 h1:gcLxHeFp0Hfo7lYi6KIZ84ZyvlAnfFRSJ8lTL3zvG5U=
helm.sh/helm/v3 v3.15.0/go.mod h1:fvfoRcB8UKRUV5jrIfOTaN/pG1TPhuqSb56fjYdTKXg=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down Expand Up @@ -934,8 +934,8 @@ kmodules.xyz/monitoring-agent-api v0.30.2-0.20241001043315-b98120efea48 h1:kJdO7
kmodules.xyz/monitoring-agent-api v0.30.2-0.20241001043315-b98120efea48/go.mod h1:oR3tk5O4koYar4cD9N3AjbBFr9XTwBU3sw9qD2NdNQc=
kmodules.xyz/offshoot-api v0.30.1 h1:TrulAYO+oBsXe9sZZGTmNWIuI8qD2izMpgcTSPvgAmI=
kmodules.xyz/offshoot-api v0.30.1/go.mod h1:T3mpjR6fui0QzOcmQvIuANytW48fe9ytmy/1cgx6D4g=
kmodules.xyz/resource-metadata v0.18.16-0.20240929130110-f5f4e27aae5b h1:lnjpyQOfirCPMq5lgLJMUPnPqMRgHQLqHaZCkBk+dm8=
kmodules.xyz/resource-metadata v0.18.16-0.20240929130110-f5f4e27aae5b/go.mod h1:Q02Xh75qc9MB2rdeo1wbpBn4WCXwoDBxLtonxz57Dng=
kmodules.xyz/resource-metadata v0.18.16 h1:wQG8VgO/ySZcwp2eLe9xe5pI+IC1JJH7eDJnMZIC48Y=
kmodules.xyz/resource-metadata v0.18.16/go.mod h1:+oaGJj871hYXqUWDFgqf4Tc8Lz5F8rBco+Bq34DqLus=
kmodules.xyz/resource-metrics v0.30.4 h1:8HBPtYmo9ETY91gsc55JE8Z986+3ZuRq57M0wZ9npqI=
kmodules.xyz/resource-metrics v0.30.4/go.mod h1:w9+rz7/s/kGP1GWzYSuRdCn+l7EwpesmESSEHkLBnIQ=
kmodules.xyz/resource-metrics/utils v0.30.4 h1:bJS/x0Qr7N1FFdxugFbzZ/Es6HVs4ptsFlhkmgj3jac=
Expand All @@ -946,8 +946,8 @@ kubeops.dev/falco-ui-server v0.0.4 h1:47kA+B4pJTgru3P60ng9eC+c3TP8Gcq61c91FB3ZoB
kubeops.dev/falco-ui-server v0.0.4/go.mod h1:ApHVuTyGAqbuDK1dBiuP+5iuLv5vUZe10+5JOYRI0TU=
kubeops.dev/scanner v0.0.18 h1:j00BXav9dFH3ucqoROjfbXTdpKWpy7tL3RynWxkLXU4=
kubeops.dev/scanner v0.0.18/go.mod h1:uyhpFCDysphXUMIWytSyyv0LjY+49z2jfuC3rK0HFTA=
kubepack.dev/lib-helm v0.29.10 h1:DxqVpid7Ez+lp/jRHO6b1kqBEdAb+AdkYCGcsZVJd6A=
kubepack.dev/lib-helm v0.29.10/go.mod h1:vrVvhzbL/SNRuS5FTn53bnpLAWoNta31ETCeaOczAcM=
kubepack.dev/lib-helm v0.29.11 h1:5/vReFNh1fN1XP862Hc6rXEq6opJrtr6mNLEzxIiFqQ=
kubepack.dev/lib-helm v0.29.11/go.mod h1:XZnORjUeidNX08ws9FnLy1VyGYq4hhdGqE553QzKLIo=
kubevault.dev/apimachinery v0.18.3 h1:Bq180AGBYnRXXNWbJ6Zg82+8/3M1Y8WYPez32uTry8I=
kubevault.dev/apimachinery v0.18.3/go.mod h1:b9uUVFx3a3ThDziL2J2O4xQL+muY1/pGavAhDdJC99E=
moul.io/http2curl/v2 v2.3.1-0.20221024080105-10c404f653f7 h1:NykkTlRB+X40z86cLHdEmuoTxhNKhQebLT379b1EumA=
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (c completedConfig) New(ctx context.Context) (*UIServer, error) {
v1alpha1storage[rsapi.ResourceResourceLayouts] = resourcelayout.NewStorage(ctrlClient)
v1alpha1storage[rsapi.ResourceResourceOutlines] = resourceoutline.NewStorage()
v1alpha1storage[rsapi.ResourceClusterProfiles] = clusterprofilestorage.NewStorage()
v1alpha1storage[uiapi.ResourceResourceEditors] = resourceeditor.NewStorage()
v1alpha1storage[uiapi.ResourceResourceEditors] = resourceeditor.NewStorage(ctrlClient)
v1alpha1storage[rsapi.ResourceResourceQueries] = resourcequery.NewStorage(ctrlClient, rbacAuthorizer)
v1alpha1storage[rsapi.ResourceResourceTableDefinitions] = resourcetabledefinition.NewStorage()

Expand Down
12 changes: 3 additions & 9 deletions pkg/menu/gallery_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,10 @@ func RenderGalleryMenu(kc client.Client, disco discovery.DiscoveryInterface, in
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 {
ed, err := resourceeditors.LoadByResourceID(kc, mi.Resource)
if err != nil || ed.Spec.UI == nil || ed.Spec.UI.Options == nil || len(ed.Spec.Variants) == 0 {
items = append(items, mi)
} else if mi.Resource != nil {
gvr := mi.Resource.GroupVersionResource()
ed, ok := resourceeditors.LoadByGVR(kc, gvr)
if !ok {
return nil, fmt.Errorf("ResourceEditor not defined for %+v", gvr)
}

} else {
chartRef := ed.Spec.UI.Options
if chartRef.SourceRef.Namespace == "" {
chartRef.SourceRef.Namespace = mu.PodNamespace()
Expand Down
2 changes: 1 addition & 1 deletion pkg/menu/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func GenerateMenuItems(kc client.Client, disco discovery.DiscoveryInterface) (ma
// Icons: rd.Spec.Icons,
// Installer: rd.Spec.Installer,
}
if ed, ok := resourceeditors.LoadByGVR(kc, gvr); ok {
if ed, err := resourceeditors.LoadByGVR(kc, gvr); err == nil {
me.Icons = ed.Spec.Icons
me.Installer = ed.Spec.Installer

Expand Down
2 changes: 1 addition & 1 deletion pkg/menu/usermenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func updateMenuItemVariantsInfo(kc client.Client, in []rsapi.MenuItem) []rsapi.M
for _, item := range in {
if item.Resource != nil {
gvr := item.Resource.GroupVersionResource()
if ed, ok := resourceeditors.LoadByGVR(kc, gvr); ok {
if ed, err := resourceeditors.LoadByGVR(kc, gvr); err == nil {
item.AvailableVariants = len(ed.Spec.Variants)
if item.AvailableVariants == 1 {
item.Variant = ed.Spec.Variants[0].Name
Expand Down
7 changes: 5 additions & 2 deletions pkg/registry/meta/resourceeditor/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ import (
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1"
"kmodules.xyz/resource-metadata/hub/resourceeditors"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type Storage struct {
kc client.Client
convertor rest.TableConvertor
}

Expand All @@ -49,8 +51,9 @@ var (
_ rest.SingularNameProvider = &Storage{}
)

func NewStorage() *Storage {
func NewStorage(kc client.Client) *Storage {
return &Storage{
kc: kc,
convertor: rest.NewDefaultTableConvertor(schema.GroupResource{
Group: rsapi.SchemeGroupVersion.Group,
Resource: uiapi.ResourceResourceEditors,
Expand Down Expand Up @@ -78,7 +81,7 @@ func (r *Storage) New() runtime.Object {
func (r *Storage) Destroy() {}

func (r *Storage) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
obj, err := resourceeditors.LoadByName(name)
obj, err := resourceeditors.LoadByName(r.kc, name)
if err != nil {
return nil, kerr.NewNotFound(schema.GroupResource{Group: meta.GroupName, Resource: uiapi.ResourceKindResourceEditor}, name)
}
Expand Down
9 changes: 2 additions & 7 deletions vendor/github.com/alessio/shellescape/.golangci.yml

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

35 changes: 28 additions & 7 deletions vendor/github.com/alessio/shellescape/.goreleaser.yml

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

1 change: 1 addition & 0 deletions vendor/github.com/docker/cli/cli/config/configfile/file.go

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

2 changes: 1 addition & 1 deletion vendor/helm.sh/helm/v3/internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
//
// Increment major number for new feature additions and behavioral changes.
// Increment minor number for bug fixes and performance enhancements.
version = "v3.14"
version = "v3.15"

// metadata is extra build time data
metadata = ""
Expand Down
2 changes: 1 addition & 1 deletion vendor/helm.sh/helm/v3/pkg/chartutil/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ const defaultNotes = `1. Get the application URL by running these commands:
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "<CHARTNAME>.fullname" . }}'
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "<CHARTNAME>.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "<CHARTNAME>.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
Expand Down
6 changes: 3 additions & 3 deletions vendor/helm.sh/helm/v3/pkg/ignore/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *Rules) parseRule(rule string) error {

if strings.HasPrefix(rule, "/") {
// Require path matches the root path.
p.match = func(n string, fi os.FileInfo) bool {
p.match = func(n string, _ os.FileInfo) bool {
rule = strings.TrimPrefix(rule, "/")
ok, err := filepath.Match(rule, n)
if err != nil {
Expand All @@ -184,7 +184,7 @@ func (r *Rules) parseRule(rule string) error {
}
} else if strings.Contains(rule, "/") {
// require structural match.
p.match = func(n string, fi os.FileInfo) bool {
p.match = func(n string, _ os.FileInfo) bool {
ok, err := filepath.Match(rule, n)
if err != nil {
log.Printf("Failed to compile %q: %s", rule, err)
Expand All @@ -193,7 +193,7 @@ func (r *Rules) parseRule(rule string) error {
return ok
}
} else {
p.match = func(n string, fi os.FileInfo) bool {
p.match = func(n string, _ os.FileInfo) bool {
// When there is no slash in the pattern, we evaluate ONLY the
// filename.
n = filepath.Base(n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ spec:
name: appscode-charts-oci
version: v0.6.0
enforceQuota: false
options:
name: corekubestashcom-backupconfiguration-editor-options
sourceRef:
apiGroup: source.toolkit.fluxcd.io
kind: HelmRepository
name: appscode-charts-oci
version: v0.6.0
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ spec:
name: appscode-charts-oci
version: v0.6.0
enforceQuota: false
options:
name: corekubestashcom-backupsession-editor-options
sourceRef:
apiGroup: source.toolkit.fluxcd.io
kind: HelmRepository
name: appscode-charts-oci
version: v0.6.0
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ spec:
name: Operations
- items:
- disabledTemplate: |
{{ not (gt .spec.replicas 1) }}
{{ not (or (hasKey .spec "topology") (gt .spec.replicas 1) )}}
editor:
name: opskubedbcom-elasticsearchopsrequest-editor
sourceRef:
Expand Down
Loading

0 comments on commit c17e98a

Please sign in to comment.