You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "oscerd (via GitHub)" <gi...@apache.org> on 2023/05/10 18:06:26 UTC

[GitHub] [camel-k] oscerd commented on a diff in pull request #4350: feat: use contaier image as kamelet repository

oscerd commented on code in PR #4350:
URL: https://github.com/apache/camel-k/pull/4350#discussion_r1190245362


##########
pkg/kamelet/repository/oci_repository.go:
##########
@@ -0,0 +1,170 @@
+package repository
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"github.com/containers/image/docker/reference"
+	"io/ioutil"
+	"path"
+	"path/filepath"
+	"sync"
+
+	camelv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+	"k8s.io/apimachinery/pkg/util/yaml"
+
+	"os"
+	"strings"
+
+	"oras.land/oras-go/v2"
+	"oras.land/oras-go/v2/content/file"
+	"oras.land/oras-go/v2/registry/remote"
+	"oras.land/oras-go/v2/registry/remote/auth"
+	"oras.land/oras-go/v2/registry/remote/retry"
+)
+
+type ociKameletRepository struct {
+	once     sync.Once
+	image    string
+	relative string
+
+	kamelets map[string]string
+	pollRoot string
+	pollErr  error
+}
+
+func newOCIKameletRepository(image string) KameletRepository {
+	imageName := image
+	relativePath := ""
+
+	items := strings.Split(image, "?")
+	if len(items) == 2 {
+		imageName = items[0]
+		relativePath = items[1]
+	}
+
+	repo := ociKameletRepository{
+		image:    imageName,
+		relative: relativePath,
+		kamelets: make(map[string]string, 0),
+	}
+
+	return &repo
+}
+
+// Enforce type
+var _ KameletRepository = &ociKameletRepository{}
+
+func (r *ociKameletRepository) List(ctx context.Context) ([]string, error) {
+
+	r.pullAll(ctx)
+
+	if r.pollErr != nil {
+		return nil, r.pollErr
+	}
+
+	kamelets := make([]string, 0, len(r.kamelets))
+	for k := range r.kamelets {
+		kamelets = append(kamelets, k)
+	}
+
+	return kamelets, r.pollErr
+}
+
+func (r *ociKameletRepository) Get(ctx context.Context, name string) (*camelv1.Kamelet, error) {
+	r.pullAll(ctx)

Review Comment:
   I would go with 3 for the moment. To avoid other complexities



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org