Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom cluster profile #341

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ require (
k8s.io/kube-state-metrics/v2 v2.12.0
kmodules.xyz/apiversion v0.2.0
kmodules.xyz/authorizer v0.29.1
kmodules.xyz/client-go v0.30.26
kmodules.xyz/client-go v0.30.27
kmodules.xyz/custom-resources v0.30.0
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.19.1-0.20241009104424-86c39a298ab6
kmodules.xyz/resource-metadata v0.19.1-0.20241016073336-1307639922b4
kmodules.xyz/resource-metrics v0.30.4
kmodules.xyz/resource-metrics/utils v0.30.4
kmodules.xyz/sets v0.29.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,8 @@ kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/authorizer v0.29.1 h1:uByGGoryKbZcfiEAhjcK/Y345I9mygNQP7DVpkMbNQQ=
kmodules.xyz/authorizer v0.29.1/go.mod h1:kZRhclL8twzyt2bQuJQJbpYww2sc+qFr8I5PPoq/sWY=
kmodules.xyz/client-go v0.30.26 h1:cPoNid/Eq38EwznsZ27gu2AEXOjqcshn+/7kjlaaQNQ=
kmodules.xyz/client-go v0.30.26/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/client-go v0.30.27 h1:pmM11k/XNVGTFp22qRsXBnGRnFeLNGX2lB9I0Gu+JWY=
kmodules.xyz/client-go v0.30.27/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkYpcs=
kmodules.xyz/crd-schema-fuzz v0.29.1/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE=
kmodules.xyz/custom-resources v0.30.0 h1:vR3CbseHMLwR4GvtcJJuRuwIV8voKqFqNii27rMcm1o=
Expand All @@ -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.19.1-0.20241009104424-86c39a298ab6 h1:Q9agV+WnOrF6SVBHLEq8EKvZzSE86yqLv3GQM6Mmw+c=
kmodules.xyz/resource-metadata v0.19.1-0.20241009104424-86c39a298ab6/go.mod h1:tDBwzcPFSiJpVFjOndSbCxliSI0kkg+5ingh5lLAxOU=
kmodules.xyz/resource-metadata v0.19.1-0.20241016073336-1307639922b4 h1:k8JQX4XDUU/ULvscjx5ENBb4qNJdWFMcf2V79c+LIcI=
kmodules.xyz/resource-metadata v0.19.1-0.20241016073336-1307639922b4/go.mod h1:ZVjgAj622Fp+8bdmAgHv6PNQHkXXqhR6aQpJg3lO8Bo=
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 Down
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (c completedConfig) New(ctx context.Context) (*UIServer, error) {
v1alpha1storage[rsapi.ResourceResourceGraphs] = resourcegraph.NewStorage(ctrlClient)
v1alpha1storage[rsapi.ResourceResourceLayouts] = resourcelayout.NewStorage(ctrlClient)
v1alpha1storage[rsapi.ResourceResourceOutlines] = resourceoutline.NewStorage()
v1alpha1storage[rsapi.ResourceClusterProfiles] = clusterprofilestorage.NewStorage()
v1alpha1storage[uiapi.ResourceClusterProfiles] = clusterprofilestorage.NewStorage(ctrlClient)
v1alpha1storage[uiapi.ResourceResourceEditors] = resourceeditor.NewStorage(ctrlClient)
v1alpha1storage[rsapi.ResourceResourceQueries] = resourcequery.NewStorage(ctrlClient, rbacAuthorizer)
v1alpha1storage[rsapi.ResourceResourceTableDefinitions] = resourcetabledefinition.NewStorage()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmds/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (o *UIServerOptions) Config() (*apiserver.Config, error) {

fmt.Sprintf("/apis/%s/%s", rsapi.SchemeGroupVersion, "usermenus"),
fmt.Sprintf("/apis/%s/%s", rsapi.SchemeGroupVersion, rsapi.ResourceChartPresetQueries),
fmt.Sprintf("/apis/%s/%s", rsapi.SchemeGroupVersion, rsapi.ResourceClusterProfiles),
fmt.Sprintf("/apis/%s/%s", rsapi.SchemeGroupVersion, uiapi.ResourceClusterProfiles),
fmt.Sprintf("/apis/%s/%s", rsapi.SchemeGroupVersion, rsapi.ResourceClusterStatuses),
fmt.Sprintf("/apis/%s/%s", rsapi.SchemeGroupVersion, rsapi.ResourceMenus),
fmt.Sprintf("/apis/%s/%s", rsapi.SchemeGroupVersion, rsapi.ResourceRenderDashboards),
Expand Down
33 changes: 19 additions & 14 deletions pkg/registry/meta/clusterprofile/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/registry/rest"
"kmodules.xyz/resource-metadata/apis/meta"
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1"
"kmodules.xyz/resource-metadata/hub/clusterprofiles"
"sigs.k8s.io/controller-runtime/pkg/client"
)

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

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

func NewStorage() *Storage {
func NewStorage(kc client.Reader) *Storage {
return &Storage{
kc: kc,
convertor: rest.NewDefaultTableConvertor(schema.GroupResource{
Group: rsapi.SchemeGroupVersion.Group,
Resource: rsapi.ResourceClusterProfiles,
Group: uiapi.SchemeGroupVersion.Group,
Resource: uiapi.ResourceClusterProfiles,
}),
}
}

func (r *Storage) GroupVersionKind(_ schema.GroupVersion) schema.GroupVersionKind {
return rsapi.SchemeGroupVersion.WithKind(rsapi.ResourceKindClusterProfile)
return uiapi.SchemeGroupVersion.WithKind(uiapi.ResourceKindClusterProfile)
}

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

func (r *Storage) GetSingularName() string {
return strings.ToLower(rsapi.ResourceKindClusterProfile)
return strings.ToLower(uiapi.ResourceKindClusterProfile)
}

// Getter
func (r *Storage) New() runtime.Object {
return &rsapi.ClusterProfile{}
return &uiapi.ClusterProfile{}
}

func (r *Storage) Destroy() {}

func (r *Storage) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
obj, err := clusterprofiles.LoadByName(name)
obj, err := clusterprofiles.LoadByName(r.kc, name)
if err != nil {
return nil, kerr.NewNotFound(schema.GroupResource{Group: meta.GroupName, Resource: rsapi.ResourceKindClusterProfile}, name)
return nil, kerr.NewNotFound(schema.GroupResource{Group: meta.GroupName, Resource: uiapi.ResourceKindClusterProfile}, name)
}
return obj, err
}

// Lister
func (r *Storage) NewList() runtime.Object {
return &rsapi.ClusterProfileList{}
return &uiapi.ClusterProfileList{}
}

func (r *Storage) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) {
if options.FieldSelector != nil && !options.FieldSelector.Empty() {
return nil, kerr.NewBadRequest("fieldSelector is not a supported")
}

objs := clusterprofiles.List()

objs, err := clusterprofiles.List(r.kc)
if err != nil {
return nil, err
}
if options.Continue != "" {
start, err := strconv.Atoi(options.Continue)
if err != nil {
Expand All @@ -109,15 +114,15 @@ func (r *Storage) List(ctx context.Context, options *metainternalversion.ListOpt
objs = objs[:options.Limit]
}

items := make([]rsapi.ClusterProfile, 0, len(objs))
items := make([]uiapi.ClusterProfile, 0, len(objs))
for _, obj := range objs {
if options.LabelSelector != nil && !options.LabelSelector.Matches(labels.Set(obj.GetLabels())) {
continue
}
items = append(items, obj)
}

return &rsapi.ClusterProfileList{Items: items}, nil
return &uiapi.ClusterProfileList{Items: items}, nil
}

func (r *Storage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/kmodules.xyz/client-go/cluster/ace.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func IsACEManaged(kc client.Client) bool {
func IsACEManaged(kc client.Reader) bool {
var list unstructured.UnstructuredList
list.SetAPIVersion("apps/v1")
list.SetKind("Deployment")
Expand Down
2 changes: 1 addition & 1 deletion vendor/kmodules.xyz/client-go/cluster/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func UpsertClusterMetadata(kc client.Client, md *kmapi.ClusterMetadata) error {
return err
}

func DetectCAPICluster(kc client.Client) (*kmapi.CAPIClusterInfo, error) {
func DetectCAPICluster(kc client.Reader) (*kmapi.CAPIClusterInfo, error) {
var list unstructured.UnstructuredList
list.SetGroupVersionKind(schema.GroupVersionKind{
Group: "cluster.x-k8s.io",
Expand Down
2 changes: 1 addition & 1 deletion vendor/kmodules.xyz/client-go/cluster/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func IsOpenClusterHub(mapper meta.RESTMapper) bool {
return false
}

func IsOpenClusterSpoke(kc client.Client) bool {
func IsOpenClusterSpoke(kc client.Reader) bool {
var list unstructured.UnstructuredList
list.SetAPIVersion("operator.open-cluster-management.io/v1")
list.SetKind("Klusterlet")
Expand Down
6 changes: 3 additions & 3 deletions vendor/kmodules.xyz/client-go/cluster/rancher.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ func isInProject(kc client.Client, nsName, seedNS string) (bool, error) {
return projectId == seedProjectId, nil
}

func GetDefaultProjectId(kc client.Client) (string, bool, error) {
func GetDefaultProjectId(kc client.Reader) (string, bool, error) {
return GetProjectId(kc, metav1.NamespaceDefault)
}

func GetSystemProjectId(kc client.Client) (string, bool, error) {
func GetSystemProjectId(kc client.Reader) (string, bool, error) {
return GetProjectId(kc, metav1.NamespaceSystem)
}

func GetProjectId(kc client.Client, nsName string) (string, bool, error) {
func GetProjectId(kc client.Reader, nsName string) (string, bool, error) {
var ns core.Namespace
err := kc.Get(context.TODO(), client.ObjectKey{Name: nsName}, &ns)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions vendor/kmodules.xyz/client-go/cluster/vcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func IsVirtualCluster(kc client.Client) (bool, error) {
func IsVirtualCluster(kc client.Reader) (bool, error) {
var list core.NodeList
err := kc.List(context.TODO(), &list)
if err != nil {
Expand All @@ -44,7 +44,7 @@ func IsVirtualCluster(kc client.Client) (bool, error) {
return false, nil
}

func MustIsVirtualCluster(kc client.Client) bool {
func MustIsVirtualCluster(kc client.Reader) bool {
ok, _ := IsVirtualCluster(kc)
return ok
}

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

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

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

Loading
Loading