Skip to content

Commit

Permalink
manifest annotate: connect IndexAnnotations
Browse files Browse the repository at this point in the history
Add the connective logic so that annotating the manifest as a whole will
succeed as intended.

Signed-off-by: Nalin Dahyabhai <[email protected]>
  • Loading branch information
nalind committed Dec 6, 2024
1 parent a28d167 commit a44a559
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
15 changes: 8 additions & 7 deletions pkg/bindings/manifests/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ type ModifyOptions struct {
Operation *string
All *bool // All when true, operate on all images in a manifest list that may be included in Images

Annotations map[string]string // Annotations to add to the entries for Images in the manifest list
Arch *string // Arch overrides the architecture for the image
Features []string // Feature list for the image
OS *string // OS overrides the operating system for the image
OSFeatures []string `json:"os_features" schema:"os_features"` // OSFeatures overrides the OS features for the image
OSVersion *string `json:"os_version" schema:"os_version"` // OSVersion overrides the operating system version for the image
Variant *string // Variant overrides the architecture variant for the image
Annotations map[string]string // Annotations to add to the entries for Images in the manifest list
IndexAnnotations map[string]string // Annotations to add to the manifest list as a whole
Arch *string // Arch overrides the architecture for the image
Features []string // Feature list for the image
OS *string // OS overrides the operating system for the image
OSFeatures []string `json:"os_features" schema:"os_features"` // OSFeatures overrides the OS features for the image
OSVersion *string `json:"os_version" schema:"os_version"` // OSVersion overrides the operating system version for the image
Variant *string // Variant overrides the architecture variant for the image

Images []string // Images is an optional list of images to add/remove to/from manifest list depending on operation
Authfile *string
Expand Down
15 changes: 15 additions & 0 deletions pkg/bindings/manifests/types_modify_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions pkg/domain/infra/abi/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ func (ir *ImageEngine) ManifestCreate(ctx context.Context, name string, images [
}
}

annotateOptions := &libimage.ManifestListAnnotateOptions{}
if len(opts.Annotations) != 0 {
annotateOptions.IndexAnnotations = opts.Annotations
annotateOptions := &libimage.ManifestListAnnotateOptions{
IndexAnnotations: opts.Annotations,
}
if err := manifestList.AnnotateInstance("", annotateOptions); err != nil {
return "", err
}
Expand Down Expand Up @@ -230,18 +231,14 @@ func (ir *ImageEngine) ManifestAdd(ctx context.Context, name string, images []st
Variant: opts.Variant,
Subject: opts.IndexSubject,
}
if len(opts.Annotation) != 0 {
annotations := make(map[string]string)
for _, annotationSpec := range opts.Annotation {
key, val, hasVal := strings.Cut(annotationSpec, "=")
if !hasVal {
return "", fmt.Errorf("no value given for annotation %q", key)
}
annotations[key] = val
}
opts.Annotations = envLib.Join(opts.Annotations, annotations)

if annotateOptions.Annotations, err = mergeAnnotations(opts.Annotations, opts.Annotation); err != nil {
return "", err
}

if annotateOptions.IndexAnnotations, err = mergeAnnotations(opts.IndexAnnotations, opts.IndexAnnotation); err != nil {
return "", err
}
annotateOptions.Annotations = opts.Annotations

if err := manifestList.AnnotateInstance(instanceDigest, annotateOptions); err != nil {
return "", err
Expand Down Expand Up @@ -380,10 +377,12 @@ func (ir *ImageEngine) ManifestAddArtifact(ctx context.Context, name string, fil
Variant: opts.Variant,
Subject: opts.IndexSubject,
}
if annotateOptions.Annotations, err = mergeAnnotations(opts.Annotations, opts.Annotation); err != nil {

if annotateOptions.Annotations, err = mergeAnnotations(opts.ManifestAnnotateOptions.Annotations, opts.ManifestAnnotateOptions.Annotation); err != nil {
return "", err
}
if annotateOptions.IndexAnnotations, err = mergeAnnotations(opts.IndexAnnotations, opts.IndexAnnotation); err != nil {

if annotateOptions.IndexAnnotations, err = mergeAnnotations(opts.ManifestAnnotateOptions.IndexAnnotations, opts.ManifestAnnotateOptions.IndexAnnotation); err != nil {
return "", err
}

Expand Down
39 changes: 28 additions & 11 deletions pkg/domain/infra/tunnel/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,17 @@ func (ir *ImageEngine) ManifestAnnotate(ctx context.Context, name, images string
options := new(manifests.ModifyOptions).WithArch(opts.Arch).WithVariant(opts.Variant)
options.WithFeatures(opts.Features).WithOS(opts.OS).WithOSVersion(opts.OSVersion)

if len(opts.Annotation) != 0 {
annotations := make(map[string]string)
for _, annotationSpec := range opts.Annotation {
key, val, hasVal := strings.Cut(annotationSpec, "=")
if !hasVal {
return "", fmt.Errorf("no value given for annotation %q", key)
}
annotations[key] = val
}
opts.Annotations = envLib.Join(opts.Annotations, annotations)
annotations, err := mergeAnnotations(opts.Annotations, opts.Annotation)
if err != nil {
return "", err
}
options.WithAnnotations(opts.Annotations)
options.WithAnnotations(annotations)

indexAnnotations, err := mergeAnnotations(opts.IndexAnnotations, opts.IndexAnnotation)
if err != nil {
return "", err
}
options.WithIndexAnnotations(indexAnnotations)

id, err := manifests.Annotate(ir.ClientCtx, name, []string{images}, options)
if err != nil {
Expand All @@ -151,6 +150,24 @@ func (ir *ImageEngine) ManifestAnnotate(ctx context.Context, name, images string
return id, nil
}

func mergeAnnotations(preferred map[string]string, aux []string) (map[string]string, error) {
if len(aux) != 0 {
auxAnnotations := make(map[string]string)
for _, annotationSpec := range aux {
key, val, hasVal := strings.Cut(annotationSpec, "=")
if !hasVal {
return nil, fmt.Errorf("no value given for annotation %q", key)
}
auxAnnotations[key] = val
}
if preferred == nil {
preferred = make(map[string]string)
}
preferred = envLib.Join(auxAnnotations, preferred)
}
return preferred, nil
}

// ManifestRemoveDigest removes the digest from manifest list
func (ir *ImageEngine) ManifestRemoveDigest(ctx context.Context, name string, image string) (string, error) {
updatedListID, err := manifests.Remove(ir.ClientCtx, name, image, nil)
Expand Down

0 comments on commit a44a559

Please sign in to comment.