Skip to content

Commit

Permalink
Merge pull request #116 from tnthornton/this-is-fine
Browse files Browse the repository at this point in the history
Move ProviderRevisionStatus Objects back to using CRDs
  • Loading branch information
tnthornton authored Apr 25, 2023
2 parents 5d572cd + 77563be commit 22a8306
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
1 change: 0 additions & 1 deletion cmd/xgql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ var noCache = []client.Object{
&appsv1.DaemonSet{},
&rbacv1.RoleBinding{},
&rbacv1.ClusterRoleBinding{},
&kextv1.CustomResourceDefinition{},

// We don't cache secrets because there's a high risk that the caller won't
// have access to list and watch secrets across all namespaces.
Expand Down
11 changes: 4 additions & 7 deletions internal/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ func Config() (*rest.Config, error) {
return nil, errors.Wrap(err, "cannot create in-cluster configuration")
}

// ctrl.GetConfig tunes QPS and burst for Kubernetes controllers. We're not
// a controller and we expect to be creating many clients, so we tune these
// back down to the client-go defaults.
cfg.QPS = 5
cfg.Burst = 20
cfg.QPS = 50
cfg.Burst = 300

cfg.UserAgent = "xgql/" + version.Version

Expand All @@ -84,8 +81,8 @@ func Config() (*rest.Config, error) {
// than once every 20 seconds.
func RESTMapper(cfg *rest.Config) (meta.RESTMapper, error) {
dcfg := rest.CopyConfig(cfg)
dcfg.QPS = 20
dcfg.Burst = 100
dcfg.QPS = 50
dcfg.Burst = 300

return apiutil.NewDynamicRESTMapper(dcfg, apiutil.WithLimiter(rate.NewLimiter(rate.Limit(0.05), 1)))
}
Expand Down
23 changes: 23 additions & 0 deletions internal/graph/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,29 @@ func GetCustomResourceDefinition(crd *unstructured.CustomResourceDefinition) Cus
}
}

// GetCustomResourceDefinitionFromCRD from the suppled Kubernetes CRD.
func GetCustomResourceDefinitionFromCRD(crd *kextv1.CustomResourceDefinition) CustomResourceDefinition {
return CustomResourceDefinition{
ID: ReferenceID{
APIVersion: crd.APIVersion,
Kind: crd.Kind,
Name: crd.GetName(),
},

APIVersion: crd.APIVersion,
Kind: crd.Kind,
Metadata: GetObjectMeta(crd),
Spec: &CustomResourceDefinitionSpec{
Group: crd.Spec.Group,
Names: GetCustomResourceDefinitionNames(crd.Spec.Names),
Scope: GetResourceScope(crd.Spec.Scope),
Versions: GetCustomResourceDefinitionVersions(crd.Spec.Versions),
},
Status: GetCustomResourceDefinitionStatus(crd.Status),
Unstructured: unstruct(crd),
}
}

// GetKubernetesResource from the supplied unstructured Kubernetes resource.
// GetKubernetesResource attempts to determine what type of resource the
// unstructured data contains (e.g. a managed resource, a provider, etc) and
Expand Down
5 changes: 2 additions & 3 deletions internal/graph/resolvers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

"github.com/upbound/xgql/internal/auth"
"github.com/upbound/xgql/internal/graph/model"
"github.com/upbound/xgql/internal/unstructured"
)

const (
Expand Down Expand Up @@ -174,13 +173,13 @@ func (r *providerRevisionStatus) Objects(ctx context.Context, obj *model.Provide
continue
}

crd := unstructured.NewCRD()
crd := &kextv1.CustomResourceDefinition{}
if err := c.Get(ctx, types.NamespacedName{Name: ref.Name}, crd); err != nil {
graphql.AddError(ctx, errors.Wrap(err, errGetCRD))
continue
}

out.Nodes = append(out.Nodes, model.GetCustomResourceDefinition(crd))
out.Nodes = append(out.Nodes, model.GetCustomResourceDefinitionFromCRD(crd))
out.TotalCount++
}

Expand Down
3 changes: 1 addition & 2 deletions internal/graph/resolvers/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/upbound/xgql/internal/clients"
"github.com/upbound/xgql/internal/graph/generated"
"github.com/upbound/xgql/internal/graph/model"
"github.com/upbound/xgql/internal/unstructured"
)

var (
Expand Down Expand Up @@ -317,7 +316,7 @@ func TestProviderActiveRevision(t *testing.T) {
func TestProviderRevisionStatusObjects(t *testing.T) {
errBoom := errors.New("boom")

gcrd := model.GetCustomResourceDefinition(&unstructured.CustomResourceDefinition{})
gcrd := model.GetCustomResourceDefinitionFromCRD(&kextv1.CustomResourceDefinition{})

type args struct {
ctx context.Context
Expand Down

0 comments on commit 22a8306

Please sign in to comment.