-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support just-in-time cache image pulls * add logging * remove unused * ch * fix artifact locaiton
- Loading branch information
Showing
5 changed files
with
127 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
changelog: | ||
- type: NON_USER_FACING | ||
description: Expand the Wasm Cache to allow just-in-time pulling of images based on ref. Also adds additional logging to the cache. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cache | ||
|
||
import ( | ||
"github.com/opencontainers/go-digest" | ||
"github.com/sirupsen/logrus" | ||
"github.com/solo-io/wasm/tools/wasme/pkg/pull" | ||
"sync" | ||
) | ||
|
||
type cacheState struct { | ||
images map[string]pull.Image | ||
imagesLock sync.RWMutex | ||
} | ||
|
||
func (c *cacheState) add(image pull.Image) { | ||
desc, err := image.Descriptor() | ||
if err != nil { | ||
// image is missing descriptor, should never happen | ||
// TODO: better logging impl | ||
logrus.Errorf("error: image %v missing code descriptor", image.Ref()) | ||
return | ||
} | ||
if c.find(desc.Digest) != nil { | ||
// check existence for idempotence | ||
// technically metadata can be different, but it's fine for now. | ||
return | ||
} | ||
c.imagesLock.Lock() | ||
if c.images == nil { | ||
c.images = make(map[string]pull.Image) | ||
} | ||
c.images[image.Ref()] = image | ||
logrus.Debugf("added image " + desc.Digest.String()) | ||
c.imagesLock.Unlock() | ||
} | ||
|
||
func (c *cacheState) find(digest digest.Digest) pull.Image { | ||
c.imagesLock.RLock() | ||
defer c.imagesLock.RUnlock() | ||
if c.images == nil { | ||
return nil | ||
} | ||
logrus.Debugf("searching for image " + digest.String()) | ||
for _, image := range c.images { | ||
desc, err := image.Descriptor() | ||
if err != nil { | ||
logrus.Errorf("error: image %v missing code descriptor", image.Ref()) | ||
return nil | ||
} | ||
|
||
if desc.Digest == digest { | ||
return image | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *cacheState) findImage(image string) pull.Image { | ||
c.imagesLock.RLock() | ||
defer c.imagesLock.RUnlock() | ||
return c.images[image] | ||
} | ||
|
||
func (c *cacheState) remove(image string) { | ||
c.imagesLock.Lock() | ||
defer c.imagesLock.Unlock() | ||
delete(c.images, image) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"github.com/solo-io/wasm/tools/wasme/pkg/cache" | ||
"github.com/solo-io/wasm/tools/wasme/pkg/pull" | ||
"github.com/solo-io/wasm/tools/wasme/pkg/resolver" | ||
) | ||
|
||
func NewDefaultCache() cache.Cache { | ||
return cache.NewCache(NewDefaultPuller()) | ||
} | ||
|
||
func NewDefaultCacheWithContext(ctx context.Context) cache.Cache { | ||
return cache.NewCacheWithConext(ctx, NewDefaultPuller()) | ||
} | ||
|
||
func NewDefaultPuller() pull.ImagePuller { | ||
// Can pull from non-private registries | ||
res, _ := resolver.NewResolver("", "", true, false) | ||
puller := pull.NewPuller(res) | ||
|
||
return cache.NewCache(puller) | ||
return pull.NewPuller(res) | ||
} |