Skip to content

Commit

Permalink
fix: Add logging regardless on every call back (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
aDisplayName authored Aug 26, 2024
1 parent 6076cac commit 1ce48d3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/controller/kuik/cachedimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
69 changes: 69 additions & 0 deletions internal/registry/test_test.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}
*/

0 comments on commit 1ce48d3

Please sign in to comment.