Skip to content

Commit

Permalink
Merge pull request #137 from upbound/fix-resource-refs
Browse files Browse the repository at this point in the history
fix resource refs
  • Loading branch information
avalanche123 authored Dec 12, 2023
2 parents bfe16eb + 5a9bf4c commit 0a1d4ae
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
env:
# Common versions
GO_VERSION: '1.21'
GOLANGCI_VERSION: 'v1.51'
GOLANGCI_VERSION: 'v1.54'
DOCKER_BUILDX_VERSION: 'v0.8.2'

# Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ S3_BUCKET ?= public-upbound.releases/$(PROJECT_NAME)
# Setup Go
NPROCS ?= 1
GO_REQUIRED_VERSION = 1.21
GOLANGCILINT_VERSION = 1.51.0
GOLANGCILINT_VERSION = 1.54.0
GO_TEST_PARALLEL := $(shell echo $$(( $(NPROCS) / 2 )))
GO_STATIC_PACKAGES = $(GO_PROJECT)/cmd/${PROJECT_NAME}
GO_LDFLAGS += -X $(GO_PROJECT)/internal/version.Version=$(VERSION)
Expand Down
152 changes: 152 additions & 0 deletions internal/graph/generated/generated.go

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

12 changes: 11 additions & 1 deletion internal/graph/resolvers/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func (r *compositeResourceSpec) Resources(ctx context.Context, obj *model.Compos
xrc.SetKind(ref.Kind)
nn := types.NamespacedName{Namespace: ref.Namespace, Name: ref.Name}
if err := c.Get(ctx, nn, xrc); err != nil {
graphql.AddError(ctx, errors.Wrap(err, errGetComposed))
if !apierrors.IsNotFound(err) {
graphql.AddError(ctx, errors.Wrap(err, errGetComposed))
}
return
}

Expand All @@ -237,6 +239,14 @@ func (r *compositeResourceSpec) Resources(ctx context.Context, obj *model.Compos
return *out, nil
}

func (r *compositeResourceSpec) ResourceRefs(ctx context.Context, obj *model.CompositeResourceSpec) ([]model.ObjectReference, error) {
resourceRefs := make([]model.ObjectReference, 0, len(obj.ResourceReferences))
for i := range obj.ResourceReferences {
resourceRefs = append(resourceRefs, *model.GetObjectReference(&obj.ResourceReferences[i]))
}
return resourceRefs, nil
}

func (r *compositeResourceSpec) ConnectionSecret(ctx context.Context, obj *model.CompositeResourceSpec) (*model.Secret, error) {
if obj.WriteConnectionSecretToReference == nil {
return nil, nil
Expand Down
29 changes: 29 additions & 0 deletions internal/graph/resolvers/composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,35 @@ func TestCompositeResourceSpecResources(t *testing.T) {
},
},
},
"IgnoreMissingResources": {
reason: "If the resource is not found, skip it.",
clients: ClientCacheFn(func(_ auth.Credentials, _ ...clients.GetOption) (client.Client, error) {
return &test.MockClient{
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
if key.Name == "not-existing" {
return apierrors.NewNotFound(schema.GroupResource{}, key.Name)
}
return nil
},
}, nil
}),
args: args{
ctx: graphql.WithResponseContext(context.Background(), graphql.DefaultErrorPresenter, graphql.DefaultRecover),
obj: &model.CompositeResourceSpec{
ResourceReferences: []corev1.ObjectReference{
{Kind: kra.GetKind(), Name: "an-a"},
{Kind: krc.GetKind(), Name: "not-existing"},
{Kind: krb.GetKind(), Name: "a-b"},
},
},
},
want: want{
krc: model.KubernetesResourceConnection{
TotalCount: 2,
Nodes: []model.KubernetesResource{gkra, gkrb},
},
},
},
"Success": {
reason: "If we can get and model composed resources we should return them.",
clients: ClientCacheFn(func(_ auth.Credentials, _ ...clients.GetOption) (client.Client, error) {
Expand Down
5 changes: 5 additions & 0 deletions schema/composite.gql
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ type CompositeResourceSpec {
"""
connectionSecret: Secret @goField(forceResolver: true)

"""
The `ObjectReference`s for the resources composed by this composite resources.
"""
resourceRefs: [ObjectReference!]!

"""
The resources of which this composite resource is composed.
"""
Expand Down

0 comments on commit 0a1d4ae

Please sign in to comment.