Skip to content

Commit

Permalink
Configure namespace for resource editor (#279)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Jan 18, 2024
1 parent 4dcaf7b commit e9d0108
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/registry/meta/resourceeditor/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/registry/rest"
meta_util "kmodules.xyz/client-go/meta"
"kmodules.xyz/resource-metadata/apis/meta"
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1"
Expand Down Expand Up @@ -81,7 +82,7 @@ func (r *Storage) Get(ctx context.Context, name string, options *metav1.GetOptio
if err != nil {
return nil, kerr.NewNotFound(schema.GroupResource{Group: meta.GroupName, Resource: uiapi.ResourceKindResourceEditor}, name)
}
return obj, err
return complete(obj.DeepCopy()), err
}

// Lister
Expand Down Expand Up @@ -115,12 +116,31 @@ func (r *Storage) List(ctx context.Context, options *metainternalversion.ListOpt
if options.LabelSelector != nil && !options.LabelSelector.Matches(labels.Set(obj.GetLabels())) {
continue
}
items = append(items, obj)
items = append(items, *complete(obj.DeepCopy()))
}

return &uiapi.ResourceEditorList{Items: items}, nil
}

var podNamespace = meta_util.PodNamespace()

func complete(obj *uiapi.ResourceEditor) *uiapi.ResourceEditor {
if obj.Spec.UI == nil {
return obj
}
if obj.Spec.UI.Editor != nil {
if obj.Spec.UI.Editor.SourceRef.Namespace == "" {
obj.Spec.UI.Editor.SourceRef.Namespace = podNamespace
}
}
if obj.Spec.UI.Options != nil {
if obj.Spec.UI.Options.SourceRef.Namespace == "" {
obj.Spec.UI.Options.SourceRef.Namespace = podNamespace
}
}
return obj
}

func (r *Storage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
return r.convertor.ConvertToTable(ctx, object, tableOptions)
}

0 comments on commit e9d0108

Please sign in to comment.