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

Cache discovery response for cluster status #289

Merged
merged 1 commit into from
Mar 7, 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
42 changes: 22 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module kubeops.dev/ui-server

go 1.21.5
go 1.22.0

toolchain go1.22.1

require (
github.com/Masterminds/sprig/v3 v3.2.3
Expand All @@ -9,7 +11,7 @@ require (
github.com/go-logr/logr v1.4.1
github.com/gobuffalo/flect v0.3.0
github.com/google/gofuzz v1.2.0
github.com/google/uuid v1.4.0
github.com/google/uuid v1.6.0
github.com/gorilla/schema v1.2.0
github.com/graphql-go/graphql v0.8.1
github.com/graphql-go/handler v0.2.3
Expand All @@ -19,7 +21,7 @@ require (
github.com/prometheus/client_golang v1.18.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/zeebo/xxh3 v1.0.2
go.bytebuilders.dev/license-verifier v0.14.0
go.openviz.dev/apimachinery v0.0.7
Expand All @@ -30,19 +32,19 @@ require (
gomodules.xyz/pointer v0.1.0
gomodules.xyz/sets v0.2.1
gomodules.xyz/sync v0.1.0
gomodules.xyz/x v0.0.15
k8s.io/api v0.29.0
k8s.io/apiextensions-apiserver v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/apiserver v0.29.0
k8s.io/client-go v0.29.0
k8s.io/component-base v0.29.0
k8s.io/klog/v2 v2.110.1
k8s.io/kube-openapi v0.0.0-20231129212854-f0671cc7e66a
gomodules.xyz/x v0.0.17
k8s.io/api v0.29.2
k8s.io/apiextensions-apiserver v0.29.2
k8s.io/apimachinery v0.29.2
k8s.io/apiserver v0.29.2
k8s.io/client-go v0.29.2
k8s.io/component-base v0.29.2
k8s.io/klog/v2 v2.120.1
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
k8s.io/kube-state-metrics/v2 v2.7.0
kmodules.xyz/apiversion v0.2.0
kmodules.xyz/authorizer v0.29.0
kmodules.xyz/client-go v0.29.12
kmodules.xyz/client-go v0.29.13
kmodules.xyz/custom-resources v0.29.1
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/monitoring-agent-api v0.29.0
Expand Down Expand Up @@ -120,7 +122,7 @@ require (
github.com/google/cel-go v0.17.7 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-containerregistry v0.17.0 // indirect
github.com/google/go-containerregistry v0.19.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
Expand Down Expand Up @@ -195,12 +197,12 @@ require (
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/atomic-writer v0.0.2 // indirect
Expand All @@ -222,9 +224,9 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
helm.sh/helm/v3 v3.14.2 // indirect
k8s.io/cli-runtime v0.29.0 // indirect
k8s.io/cli-runtime v0.29.2 // indirect
k8s.io/component-helpers v0.29.0 // indirect
k8s.io/kms v0.29.0 // indirect
k8s.io/kms v0.29.2 // indirect
k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect
kmodules.xyz/offshoot-api v0.29.0 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 // indirect
Expand Down
82 changes: 46 additions & 36 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (c completedConfig) New(ctx context.Context) (*UIServer, error) {

v1alpha1storage := map[string]rest.Storage{}
v1alpha1storage[rsapi.ResourceChartPresetQueries] = chartpresetquery.NewStorage(ctrlClient)
v1alpha1storage[rsapi.ResourceClusterStatuses] = clusterstatusstorage.NewStorage(ctrlClient)
v1alpha1storage[rsapi.ResourceClusterStatuses] = clusterstatusstorage.NewStorage(ctrlClient, disco)
v1alpha1storage[rsapi.ResourceRenderDashboards] = renderdashboard.NewStorage(ctrlClient, oc)
v1alpha1storage[rsapi.ResourceRenderRawGraphs] = renderrawgraph.NewStorage(ctrlClient)
v1alpha1storage[rsapi.ResourceRenders] = render.NewStorage(ctrlClient, oc, rbacAuthorizer)
Expand Down
5 changes: 3 additions & 2 deletions pkg/registry/meta/clusterstatus/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

"gomodules.xyz/pointer"
"k8s.io/apimachinery/pkg/api/meta"
clustermeta "kmodules.xyz/client-go/cluster"
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1"
Expand All @@ -31,11 +32,11 @@ const (
MessageRequiredComponentsMissing = "One or more core components are not ready. Please, reconnect to update the components."
)

func generateClusterStatusResponse(kc client.Client) *rsapi.ClusterStatusResponse {
func generateClusterStatusResponse(kc client.Client, mapper meta.RESTMapper) *rsapi.ClusterStatusResponse {
var csr rsapi.ClusterStatusResponse
var err error

clusterManager := clustermeta.DetectClusterManager(kc)
clusterManager := clustermeta.DetectClusterManager(kc, mapper)
csr.ClusterManagers = clusterManager.Strings()
if clusterManager.ManagedByOCMMulticlusterControlplane() {
csr.Phase = rsapi.ClusterPhaseActive
Expand Down
10 changes: 8 additions & 2 deletions pkg/registry/meta/clusterstatus/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/client-go/discovery"
"k8s.io/client-go/discovery/cached/memory"
"k8s.io/client-go/restmapper"
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

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

Expand All @@ -41,9 +45,10 @@ var (
_ rest.SingularNameProvider = &Storage{}
)

func NewStorage(kc client.Client) *Storage {
func NewStorage(kc client.Client, dc discovery.DiscoveryInterface) *Storage {
return &Storage{
kc: kc,
dc: dc,
convertor: rest.NewDefaultTableConvertor(schema.GroupResource{
Group: rsapi.SchemeGroupVersion.Group,
Resource: rsapi.ResourceClusterStatuses,
Expand Down Expand Up @@ -71,7 +76,8 @@ func (r *Storage) Destroy() {}

func (r *Storage) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
in := obj.(*rsapi.ClusterStatus)
in.Response = generateClusterStatusResponse(r.kc)
mapper := restmapper.NewDeferredDiscoveryRESTMapper(memory.NewMemCacheClient(r.dc))
in.Response = generateClusterStatusResponse(r.kc, mapper)

return in, nil
}
Expand Down
61 changes: 0 additions & 61 deletions vendor/github.com/go-logr/logr/slogr/slogr.go

This file was deleted.

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

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading