Skip to content

Commit

Permalink
fix: gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
panshuai111 committed Nov 17, 2023
1 parent 953657d commit 5d5166f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 74 deletions.
104 changes: 52 additions & 52 deletions pkg/registry/search/uniresource/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,87 +15,87 @@
package uniresource

import (
"context"
"fmt"

"github.com/KusionStack/karbour/pkg/apis/search"
"github.com/KusionStack/karbour/pkg/search/storage"
filtersutil "github.com/KusionStack/karbour/pkg/util/filters"
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
"context"
"fmt"

"github.com/KusionStack/karbour/pkg/apis/search"
"github.com/KusionStack/karbour/pkg/search/storage"
filtersutil "github.com/KusionStack/karbour/pkg/util/filters"
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
)

var (
_ rest.Storage = &REST{}
_ rest.Scoper = &REST{}
_ rest.Lister = &REST{}
_ rest.ShortNamesProvider = &REST{}
_ rest.Storage = &REST{}
_ rest.Scoper = &REST{}
_ rest.Lister = &REST{}
_ rest.ShortNamesProvider = &REST{}
)

type REST struct {
Storage storage.SearchStorage
Storage storage.SearchStorage
}

func NewREST(searchStorageGetter storage.SearchStorageGetter) (rest.Storage, error) {
searchStorage, err := searchStorageGetter.GetSearchStorage()
if err != nil {
return nil, err
}

return &REST{
Storage: searchStorage,
}, nil
searchStorage, err := searchStorageGetter.GetSearchStorage()
if err != nil {
return nil, err
}

return &REST{
Storage: searchStorage,
}, nil
}

func (r *REST) New() runtime.Object {
return &search.UniResource{}
return &search.UniResource{}
}

func (r *REST) Destroy() {
}

func (r *REST) NamespaceScoped() bool {
return false
return false
}

func (r *REST) NewList() runtime.Object {
return &search.UniResourceList{}
return &search.UniResourceList{}
}

func (r *REST) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) {
queryString, ok := filtersutil.SearchQueryFrom(ctx)
if !ok {
return nil, fmt.Errorf("query can't be empty")
}

patternType, ok := filtersutil.PatternTypeFrom(ctx)
if !ok {
return nil, fmt.Errorf("pattern type can't be empty")
}

res, err := r.Storage.Search(ctx, queryString, patternType)
if err != nil {
return nil, err
}

rt := &search.UniResourceList{}
for _, resource := range res.Resources {
unObj := &unstructured.Unstructured{}
unObj.SetUnstructuredContent(resource.Object)
rt.Items = append(rt.Items, unObj)
}
return rt, nil
queryString, ok := filtersutil.SearchQueryFrom(ctx)
if !ok {
return nil, fmt.Errorf("query can't be empty")
}

patternType, ok := filtersutil.PatternTypeFrom(ctx)
if !ok {
return nil, fmt.Errorf("pattern type can't be empty")
}

res, err := r.Storage.Search(ctx, queryString, patternType)
if err != nil {
return nil, err
}

rt := &search.UniResourceList{}
for _, resource := range res.Resources {
unObj := &unstructured.Unstructured{}
unObj.SetUnstructuredContent(resource.Object)
rt.Items = append(rt.Items, unObj)
}
return rt, nil
}

func (r *REST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: add real logic of convert to table when the storage layer is implemented
return rest.NewDefaultTableConvertor(search.Resource("uniresources")).ConvertToTable(ctx, object, tableOptions)
// TODO: add real logic of convert to table when the storage layer is implemented
return rest.NewDefaultTableConvertor(search.Resource("uniresources")).ConvertToTable(ctx, object, tableOptions)
}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
return []string{"ur"}
return []string{"ur"}
}
44 changes: 22 additions & 22 deletions pkg/search/storage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,48 @@
package storage

import (
"context"
"context"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
)

const (
Equals string = "="
DSLPatternType = "dsl"
SQLPatternType = "sql"
Equals string = "="

Check failure on line 24 in pkg/search/storage/types.go

View workflow job for this annotation

GitHub Actions / Golang Lint

SA9004: only the first constant in this group has an explicit type (staticcheck)
DSLPatternType = "dsl"
SQLPatternType = "sql"
)

type Storage interface {
Get(ctx context.Context, cluster string, obj runtime.Object) error
Create(ctx context.Context, cluster string, obj runtime.Object) error
Update(ctx context.Context, cluster string, obj runtime.Object) error
Delete(ctx context.Context, cluster string, obj runtime.Object) error
Get(ctx context.Context, cluster string, obj runtime.Object) error
Create(ctx context.Context, cluster string, obj runtime.Object) error
Update(ctx context.Context, cluster string, obj runtime.Object) error
Delete(ctx context.Context, cluster string, obj runtime.Object) error
}

type Query struct {
Key string
Values []string
Operator string
Key string
Values []string
Operator string
}

type SearchStorage interface {
Search(ctx context.Context, queryString, patternType string) (*SearchResult, error)
Search(ctx context.Context, queryString, patternType string) (*SearchResult, error)
}

type SearchStorageGetter interface {
GetSearchStorage() (SearchStorage, error)
GetSearchStorage() (SearchStorage, error)
}

type Resource struct {
Cluster string `json:"cluster"`
Namespace string `json:"namespace"`
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Name string `json:"name"`
Object map[string]interface{} `json:"object"`
Cluster string `json:"cluster"`
Namespace string `json:"namespace"`
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Name string `json:"name"`
Object map[string]interface{} `json:"object"`
}

type SearchResult struct {
Total int
Resources []*Resource
Total int
Resources []*Resource
}

0 comments on commit 5d5166f

Please sign in to comment.