Skip to content

Commit

Permalink
feat(kubepkg): support packe image only
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Jul 30, 2024
1 parent 51514f9 commit 2bb8d26
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions pkg/kubepkg/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Packer struct {
Registry Registry
Renamer Renamer
WithAnnotations []string
ImageOnly bool

CreatePuller func(ref name.Reference, options ...remote.Option) (*remote.Puller, error)

Expand Down Expand Up @@ -178,23 +179,46 @@ func (p *Packer) PackAsIndex(ctx context.Context, kpkg *kubepkgv1alpha1.KubePkg)
return nil, errors.Errorf("invalid image name %s", nameAndTag)
}

finalIndex, err = p.appendManifests(finalIndex, index, nil, &kubepkgv1alpha1.Image{
Name: nameAndTag[0],
Tag: nameAndTag[1],
if p.ImageOnly && len(imageIndexes) == 1 {
ann, err := p.pickAnnotations(kpkg.Annotations)
if err != nil {
return nil, err
}
d, err := partial.Descriptor(index)
if err != nil {
return nil, err
}
d.Annotations = ann

finalIndex, err = p.appendManifests(finalIndex, index, d, &kubepkgv1alpha1.Image{
Name: nameAndTag[0],
Tag: nameAndTag[1],
})
if err != nil {
return nil, err
}
} else {
finalIndex, err = p.appendManifests(finalIndex, index, nil, &kubepkgv1alpha1.Image{
Name: nameAndTag[0],
Tag: nameAndTag[1],
})
if err != nil {
return nil, err
}
}

}

if !p.ImageOnly {
finalIndex, err = p.appendManifests(finalIndex, kubePkgImage, nil, &kubepkgv1alpha1.Image{
Name: p.ImageName(r),
Tag: kpkg.Spec.Version,
})
if err != nil {
return nil, err
}
}

finalIndex, err = p.appendManifests(finalIndex, kubePkgImage, nil, &kubepkgv1alpha1.Image{
Name: p.ImageName(r),
Tag: kpkg.Spec.Version,
})
if err != nil {
return nil, err
}

return finalIndex, nil
}

Expand Down

0 comments on commit 2bb8d26

Please sign in to comment.