Skip to content

Commit

Permalink
Rename "meta" to "origin"
Browse files Browse the repository at this point in the history
All of the information being stored in the "metas" section are
information about the sourcing of each image. The term "source" however,
is already used in this domain to mean a configuration from which an
image is produced from sources.

Origin is a softer claim than provenance; the latter of which is
generally taken to mean provable.
  • Loading branch information
jtigger authored and Dmitriy Kalinin committed Sep 21, 2021
1 parent 5fb9b46 commit 250bc59
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 116 deletions.
24 changes: 12 additions & 12 deletions pkg/kbld/cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
type Images []Image

type Image struct {
URL string
Metas []ctlconf.Meta // empty when deserialized
metasRaw []interface{} // populated when deserialized
URL string
Origins []ctlconf.Origin // empty when deserialized
originsRaw []interface{} // populated when deserialized
}

func (imgs Images) ForImage(url string) (Image, bool) {
Expand All @@ -30,7 +30,7 @@ func (imgs Images) ForImage(url string) (Image, bool) {

// TODO only works after deserialization
func (i Image) Description() string {
yamlBytes, err := yaml.Marshal(i.metasRaw)
yamlBytes, err := yaml.Marshal(i.originsRaw)
if err != nil {
return "[]" // TODO deal better?
}
Expand All @@ -39,12 +39,12 @@ func (i Image) Description() string {
}

type imageStruct struct {
URL string `json:"url"`
Metas []interface{} `json:"metas,omitempty"`
URL string `json:"url"`
Origins []interface{} `json:"origins,omitempty"`
}

func (st imageStruct) equal(other imageStruct) bool {
return st.URL == other.URL && reflect.DeepEqual(st.Metas, other.Metas)
return st.URL == other.URL && reflect.DeepEqual(st.Origins, other.Origins)
}

func contains(structs []imageStruct, st imageStruct) bool {
Expand All @@ -60,9 +60,9 @@ func newImageStructs(images []Image) []imageStruct {
var result []imageStruct
for _, img := range images {
st := newImageStruct(img)
// if Metas is empty then the image was already in digest form and we didn't need to resolve
// if Origins is empty then the image was already in digest form and we didn't need to resolve
// it, so the annotation isn't very useful
if len(st.Metas) > 0 {
if len(st.Origins) > 0 {
// also check for duplicates before adding
if !contains(result, st) {
result = append(result, st)
Expand All @@ -74,16 +74,16 @@ func newImageStructs(images []Image) []imageStruct {

func newImageStruct(image Image) imageStruct {
result := imageStruct{URL: image.URL}
for _, meta := range image.Metas {
result.Metas = append(result.Metas, meta)
for _, origin := range image.Origins {
result.Origins = append(result.Origins, origin)
}
return result
}

func newImages(structs []imageStruct) []Image {
var result []Image
for _, st := range structs {
result = append(result, Image{URL: st.URL, metasRaw: st.Metas})
result = append(result, Image{URL: st.URL, originsRaw: st.Origins})
}
return result
}
4 changes: 2 additions & 2 deletions pkg/kbld/cmd/image_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (b *ImageQueue) worker(workWg *sync.WaitGroup, queueCh <-chan UnprocessedIm
func (b *ImageQueue) work(workWg *sync.WaitGroup, unprocessedImageURL UnprocessedImageURL) {
defer workWg.Done()

imgURL, metas, err := b.imgFactory.New(unprocessedImageURL.URL).URL()
imgURL, origins, err := b.imgFactory.New(unprocessedImageURL.URL).URL()
if err != nil {
b.outputErrsLock.Lock()
b.outputErrs = append(b.outputErrs, fmt.Errorf("Resolving image '%s': %s", unprocessedImageURL.URL, err))
Expand All @@ -64,6 +64,6 @@ func (b *ImageQueue) work(workWg *sync.WaitGroup, unprocessedImageURL Unprocesse
}

b.outputImagesLock.Lock()
b.outputImages.Add(unprocessedImageURL, Image{URL: imgURL, Metas: metas})
b.outputImages.Add(unprocessedImageURL, Image{URL: imgURL, Origins: origins})
b.outputImagesLock.Unlock()
}
6 changes: 3 additions & 3 deletions pkg/kbld/cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ func (o *InspectOptions) Run() error {
}

for _, resWithImg := range foundImages {
metasDesc, err := resWithImg.MetasDescription()
originsDesc, err := resWithImg.OriginsDescription()
if err != nil {
return err
}

table.Rows = append(table.Rows, []uitable.Value{
uitable.NewValueString(resWithImg.URL),
uitable.NewValueString(metasDesc),
uitable.NewValueString(originsDesc),
uitable.NewValueString(resWithImg.Resource.Description()),
})
}
Expand Down Expand Up @@ -106,7 +106,7 @@ type foundResourceWithImage struct {
Resource ctlres.Resource
}

func (s foundResourceWithImage) MetasDescription() (string, error) {
func (s foundResourceWithImage) OriginsDescription() (string, error) {
images, err := NewResourceWithImages(s.Resource.DeepCopyRaw(), nil).Images()
if err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions pkg/kbld/cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ func (o *ResolveOptions) imgpkgLockAnnotations(i ProcessedImageItem) map[string]
anns := map[string]string{
ctlconf.ImagesLockKbldID: i.UnprocessedImageURL.URL,
}
if len(i.Metas) > 0 {
bs, err := yaml.Marshal(i.Metas)
if len(i.Origins) > 0 {
bs, err := yaml.Marshal(i.Origins)
if err != nil {
return anns
}
anns[ctlconf.ImagesLockKbldMetas] = string(bs)
anns[ctlconf.ImagesLockKbldOrigins] = string(bs)
}

return anns
Expand Down
12 changes: 6 additions & 6 deletions pkg/kbld/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ImageOverride struct {
NewImage string `json:"newImage"`
Preresolved bool `json:"preresolved,omitempty"`
TagSelection *versions.VersionSelection `json:"tagSelection,omitempty"`
ImageMetas []Meta `json:"metas,omitempty"`
ImageOrigins []Origin `json:"origins,omitempty"`
}

type ImageDestination struct {
Expand Down Expand Up @@ -169,17 +169,17 @@ func NewConfigFromImagesLock(res ctlres.Resource) (Config, error) {
overridesConfig := NewConfig()

for _, image := range imagesLock.Images {
imgMeta, err := NewMetasFromString(image.Annotations[ImagesLockKbldMetas])
imgOrigins, err := NewOriginsFromString(image.Annotations[ImagesLockKbldOrigins])
if err != nil {
return Config{}, fmt.Errorf("Unmarshaling %s as %s annotation: %s", res.Description(), ImagesLockKbldMetas, err)
return Config{}, fmt.Errorf("Unmarshaling %s as %s annotation: %s", res.Description(), ImagesLockKbldOrigins, err)
}
iOverride := ImageOverride{
ImageRef: ImageRef{
Image: image.Annotations[ImagesLockKbldID],
},
NewImage: image.Image,
Preresolved: true,
ImageMetas: imgMeta,
NewImage: image.Image,
Preresolved: true,
ImageOrigins: imgOrigins,
}
overridesConfig.Overrides = append(overridesConfig.Overrides, iOverride)
}
Expand Down
36 changes: 18 additions & 18 deletions pkg/kbld/config/image_meta.go → pkg/kbld/config/image_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ import (
"sigs.k8s.io/yaml"
)

type Meta struct {
Git *MetaGit `json:"git,omitempty"`
Local *MetaLocal `json:"local,omitempty"`
Resolved *MetaResolved `json:"resolved,omitempty"`
Tagged *MetaTagged `json:"tagged,omitempty"`
Preresolved *MetaPreresolved `json:"preresolved,omitempty"`
type Origin struct {
Git *OriginGit `json:"git,omitempty"`
Local *OriginLocal `json:"local,omitempty"`
Resolved *OriginResolved `json:"resolved,omitempty"`
Tagged *OriginTagged `json:"tagged,omitempty"`
Preresolved *OriginPreresolved `json:"preresolved,omitempty"`
}

type MetaGit struct {
type OriginGit struct {
RemoteURL string `json:"remoteURL"`
SHA string `json:"sha"`
Dirty bool `json:"dirty"`
Tags []string `json:"tags,omitempty"`
}

type MetaLocal struct {
type OriginLocal struct {
Path string `json:"path"`
}

type MetaResolved struct {
type OriginResolved struct {
URL string `json:"url"`
Tag string `json:"tag,omitempty"`
}

type MetaTagged struct {
type OriginTagged struct {
Tags []string `json:"tags"`
}

type MetaPreresolved struct {
type OriginPreresolved struct {
URL string `json:"url"`
Tag string `json:"tag,omitempty"`
}

func NewMetasFromString(str string) ([]Meta, error) {
var metas []Meta
func NewOriginsFromString(str string) ([]Origin, error) {
var origins []Origin

// Ignores unknown types of meta. At this time...
// - "Meta" are provided as primarily optional diagnostic information
// Ignores unknown types of origin. At this time...
// - "Origin" are provided as primarily optional diagnostic information
// rather than operational data (read: less important). Losing
// this information does not change the correctness of kbld's
// primary purpose during deployment: to rewrite image references.
Expand All @@ -56,10 +56,10 @@ func NewMetasFromString(str string) ([]Meta, error) {
// of warnings. So, the feature would quickly need an enhancement
// to de-dup such warnings. (read: added complexity)
// see also https://github.com/vmware-tanzu/carvel-kbld/issues/160
err := yaml.Unmarshal([]byte(str), &metas)
err := yaml.Unmarshal([]byte(str), &origins)
if err != nil {
return []Meta{}, err
return []Origin{}, err
}

return metas, nil
return origins, nil
}
4 changes: 2 additions & 2 deletions pkg/kbld/config/images_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
package config

const (
ImagesLockKbldID = "kbld.carvel.dev/id"
ImagesLockKbldMetas = "kbld.carvel.dev/metas"
ImagesLockKbldID = "kbld.carvel.dev/id"
ImagesLockKbldOrigins = "kbld.carvel.dev/origins"
)
32 changes: 16 additions & 16 deletions pkg/kbld/image/built.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func NewBuiltImage(url string, buildSource ctlconf.Source, imgDst *ctlconf.Image
return BuiltImage{url, buildSource, imgDst, docker, pack, kubectlBuildkit, ko, bazel}
}

func (i BuiltImage) URL() (string, []ctlconf.Meta, error) {
metas, err := i.sources()
func (i BuiltImage) URL() (string, []ctlconf.Origin, error) {
origins, err := i.sources()
if err != nil {
return "", nil, err
}
Expand All @@ -54,28 +54,28 @@ func (i BuiltImage) URL() (string, []ctlconf.Meta, error) {
return "", nil, err
}

return i.optionalPushWithDocker(dockerTmpRef, metas)
return i.optionalPushWithDocker(dockerTmpRef, origins)

case i.buildSource.KubectlBuildkit != nil:
url, err := i.kubectlBuildkit.BuildAndPush(
urlRepo, i.buildSource.Path, i.imgDst, *i.buildSource.KubectlBuildkit)
return url, metas, err
return url, origins, err

case i.buildSource.Ko != nil:
dockerTmpRef, err := i.ko.Build(urlRepo, i.buildSource.Path, i.buildSource.Ko.Build)
if err != nil {
return "", nil, err
}

return i.optionalPushWithDocker(dockerTmpRef, metas)
return i.optionalPushWithDocker(dockerTmpRef, origins)

case i.buildSource.Bazel != nil:
dockerTmpRef, err := i.bazel.Run(urlRepo, i.buildSource.Path, i.buildSource.Bazel.Run)
if err != nil {
return "", nil, err
}

return i.optionalPushWithDocker(dockerTmpRef, metas)
return i.optionalPushWithDocker(dockerTmpRef, origins)

default:
if i.buildSource.Docker == nil {
Expand All @@ -96,37 +96,37 @@ func (i BuiltImage) URL() (string, []ctlconf.Meta, error) {
return "", nil, err
}

return i.optionalPushWithDocker(dockerTmpRef, metas)
return i.optionalPushWithDocker(dockerTmpRef, origins)
}
}

func (i BuiltImage) optionalPushWithDocker(dockerTmpRef ctlbdk.DockerTmpRef, metas []ctlconf.Meta) (string, []ctlconf.Meta, error) {
func (i BuiltImage) optionalPushWithDocker(dockerTmpRef ctlbdk.DockerTmpRef, origins []ctlconf.Origin) (string, []ctlconf.Origin, error) {
if i.imgDst != nil {
digest, err := i.docker.Push(dockerTmpRef, i.imgDst.NewImage)
if err != nil {
return "", nil, err
}

url, metas2, err := NewDigestedImageFromParts(i.imgDst.NewImage, digest.AsString()).URL()
url, moreOrigins, err := NewDigestedImageFromParts(i.imgDst.NewImage, digest.AsString()).URL()
if err != nil {
return "", nil, err
}

return url, append(metas, metas2...), nil
return url, append(origins, moreOrigins...), nil
}

return dockerTmpRef.AsString(), metas, nil
return dockerTmpRef.AsString(), origins, nil
}

func (i BuiltImage) sources() ([]ctlconf.Meta, error) {
var sources []ctlconf.Meta
func (i BuiltImage) sources() ([]ctlconf.Origin, error) {
var sources []ctlconf.Origin

absPath, err := filepath.Abs(i.buildSource.Path)
if err != nil {
return nil, err
}

sources = append(sources, ctlconf.Meta{Local: &ctlconf.MetaLocal{Path: absPath}})
sources = append(sources, ctlconf.Origin{Local: &ctlconf.OriginLocal{Path: absPath}})

gitRepo := NewGitRepo(absPath)

Expand All @@ -138,7 +138,7 @@ func (i BuiltImage) sources() ([]ctlconf.Meta, error) {
return nil, err
}

git := ctlconf.MetaGit{SHA: sha}
git := ctlconf.OriginGit{SHA: sha}

git.RemoteURL, err = gitRepo.RemoteURL()
if err != nil {
Expand All @@ -155,7 +155,7 @@ func (i BuiltImage) sources() ([]ctlconf.Meta, error) {
return nil, err
}

sources = append(sources, ctlconf.Meta{Git: &git})
sources = append(sources, ctlconf.Origin{Git: &git})
}

return sources, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/kbld/image/digested.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewDigestedImageFromParts(url, digest string) DigestedImage {
return DigestedImage{nameWithDigest, nil}
}

func (i DigestedImage) URL() (string, []ctlconf.Meta, error) {
func (i DigestedImage) URL() (string, []ctlconf.Origin, error) {
if i.parseErr != nil {
return "", nil, i.parseErr
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/kbld/image/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

package image

import ctlconf "github.com/k14s/kbld/pkg/kbld/config"
import (
ctlconf "github.com/k14s/kbld/pkg/kbld/config"
)

type ErrImage struct {
err error
Expand All @@ -13,4 +15,4 @@ var _ Image = ErrImage{}

func NewErrImage(err error) ErrImage { return ErrImage{err} }

func (i ErrImage) URL() (string, []ctlconf.Meta, error) { return "", nil, i.err }
func (i ErrImage) URL() (string, []ctlconf.Origin, error) { return "", nil, i.err }
4 changes: 2 additions & 2 deletions pkg/kbld/image/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

type Image interface {
URL() (string, []ctlconf.Meta, error)
URL() (string, []ctlconf.Origin, error)
}

type Factory struct {
Expand All @@ -39,7 +39,7 @@ func (f Factory) New(url string) Image {
if overrideConf, found := f.shouldOverride(url); found {
url = overrideConf.NewImage
if overrideConf.Preresolved {
return NewPreresolvedImage(url, overrideConf.ImageMetas)
return NewPreresolvedImage(url, overrideConf.ImageOrigins)
} else if overrideConf.TagSelection != nil {
return NewTagSelectedImage(url, overrideConf.TagSelection, f.registry)
}
Expand Down
Loading

0 comments on commit 250bc59

Please sign in to comment.