Skip to content

Commit

Permalink
feat: add collectioniterators to collection cr (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasepe authored Sep 10, 2024
1 parent 233cad7 commit fc4fcf2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions internal/resolvers/templates/refs/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func Resolve(ctx context.Context, opts ResolveOptions) *runtime.RawExtension {
}
}

if tools.IsCollectionIterator(gvr.GroupResource()) {
obj, err = cli.Templates().CollectionIterators(opts.WidgetRef.Namespace).
Get(ctx, opts.WidgetRef.Name, metav1.GetOptions{})
if err != nil {
klog.Errorf("unable to get collectioniterator '%s' %s/%s",
gvr.String(), opts.WidgetRef.Namespace, opts.WidgetRef.Name)
return nil
}
}

if tools.IsCollection(gvr.GroupResource()) {
obj, err = cli.Templates().Collections(opts.WidgetRef.Namespace).
Get(ctx, opts.WidgetRef.Name, metav1.GetOptions{})
Expand Down
6 changes: 6 additions & 0 deletions internal/resolvers/templates/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func IsWidget(gr schema.GroupResource) bool {
return ok
}

func IsCollectionIterator(gr schema.GroupResource) bool {
ok := (gr.Group == templates.SchemeGroupVersion.Group)
ok = ok && (gr.Resource == "collectioniterators")
return ok
}

func IsCollection(gr schema.GroupResource) bool {
ok := (gr.Group == templates.SchemeGroupVersion.Group)
ok = ok && (gr.Resource == "collections")
Expand Down
6 changes: 3 additions & 3 deletions testdata/collectioniterator.sample.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: templates-row-column-1
name: collit
namespace: demo-system
data:
width: "24"
---
apiVersion: templates.krateo.io/v1alpha1
kind: CollectionIterator
metadata:
name: templates-row-column-1
name: collit
namespace: demo-system
spec:
type: column
propsRef:
name: templates-row-column-1
name: collit
namespace: demo-system
widgetsRefs:
- iterator: .allPods.items[:3]
Expand Down
4 changes: 4 additions & 0 deletions testdata/widgets.collections.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ spec:
resource: widgets
name: external-api
namespace: demo-system
- apiVersion: templates.krateo.io/v1alpha1
resource: collectioniterators
name: collit
namespace: demo-system
---
kind: ConfigMap
apiVersion: v1
Expand Down

0 comments on commit fc4fcf2

Please sign in to comment.