Skip to content

Commit

Permalink
skip resource refs that don't exist
Browse files Browse the repository at this point in the history
Signed-off-by: Bulat Shakirzyanov <83289+avalanche123@users.noreply.github.com>
  • Loading branch information
avalanche123 committed Dec 12, 2023
1 parent b9d3a24 commit 95361ad
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 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 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

0 comments on commit 95361ad

Please sign in to comment.