diff --git a/internal/controller/kuik/cachedimage_controller.go b/internal/controller/kuik/cachedimage_controller.go index 9d8a873c..48240d02 100644 --- a/internal/controller/kuik/cachedimage_controller.go +++ b/internal/controller/kuik/cachedimage_controller.go @@ -241,7 +241,7 @@ func (r *CachedImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) } if putImageInCache { r.Recorder.Eventf(&cachedImage, "Normal", "Caching", "Start caching image %s", cachedImage.Spec.SourceImage) - err = r.cacheImage(&cachedImage) + err = r.cacheImage(&cachedImage, log) if err != nil { log.Error(err, "failed to cache image") r.Recorder.Eventf(&cachedImage, "Warning", "CacheFailed", "Failed to cache image %s, reason: %s", cachedImage.Spec.SourceImage, err) @@ -308,7 +308,7 @@ func getSanitizedName(cachedImage *kuikv1alpha1.CachedImage) (string, error) { return sanitizedName, nil } -func (r *CachedImageReconciler) cacheImage(cachedImage *kuikv1alpha1.CachedImage) error { +func (r *CachedImageReconciler) cacheImage(cachedImage *kuikv1alpha1.CachedImage, log logr.Logger) error { if err := r.patchPhase(cachedImage, cachedImagePhaseSynchronizing); err != nil { return err } @@ -347,6 +347,7 @@ func (r *CachedImageReconciler) cacheImage(cachedImage *kuikv1alpha1.CachedImage lastUpdateTime := time.Now() lastWriteComplete := int64(0) onUpdated := func(update v1.Update) { + log.Info("OnUpdate") needUpdate := false if lastWriteComplete != update.Complete && update.Complete == update.Total { // Update is needed whenever the writing complmetes. diff --git a/internal/registry/test_test.go b/internal/registry/test_test.go new file mode 100644 index 00000000..2f3f8d7e --- /dev/null +++ b/internal/registry/test_test.go @@ -0,0 +1,69 @@ +package registry + +/* +import ( + "fmt" + "os" + "testing" + + cranepkg "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/remote" + "github.com/google/go-containerregistry/pkg/v1/tarball" + "github.com/google/go-containerregistry/pkg/v1/types" + v1 "k8s.io/api/core/v1" +) + +// Write remote image to tarball file +func Test_parsing(t *testing.T) { + + sourceImangeName := "mcr.microsoft.com/powershell:lts" + desc, _ := GetDescriptor(sourceImangeName, []v1.Secret{}, []string{}, nil) + destRef, _ := parseLocalReference(sourceImangeName) + // architectures := []string{"amd64"} + switch desc.MediaType { + case types.OCIImageIndex, types.DockerManifestList: + // index, err := desc.ImageIndex() + // if err != nil { + // return + // } + // filteredIndex := mutate.RemoveManifests(index, func(desc cranepkg.Descriptor) bool { + // for _, arch := range architectures { + // if arch == desc.Platform.Architecture { + // return false + // } + // } + // return true + // }) + + // if err := remote.WriteIndex(destRef, filteredIndex); err != nil { + // return + // } + var k = 1 + k = k + 1 + + progressUpdate := make(chan cranepkg.Update, 100) + callback := func(u cranepkg.Update) { + fmt.Print(u.Complete) + } + go func() { + for update := range progressUpdate { + if callback != nil { + callback(update) + } + } + }() + image, err := desc.Image() + if err != nil { + return + } + file, err := os.Create("output.tar") + if err := tarball.Write(destRef, image, file, tarball.WithProgress(progressUpdate)); err != nil { + return + } + + if err := remote.Write(destRef, image, remote.WithProgress(progressUpdate)); err != nil { + return + } + } +} +*/