pkg

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const ExtraIdentityKeyPrefix = "imagevector-gardener-cloud"

ExtraIdentityKeyPrefix is the prefix for all image vector related extra identities on component descriptor resources.

View Source
const GardenerCIOriginalRefLabel = "cloud.gardener.cnudie/migration/original_ref"

GardenerCIOriginalRefLabel describes the lable of the gardener ci that is used to identify the original ref of a resource.

View Source
const LabelPrefix = "imagevector.gardener.cloud"

LabelPrefix is the prefix for all image vector related labels on component descriptor resources.

Variables

View Source
var (
	ComponentReferenceAction = Label("component-reference")
	GenericDependencyAction  = Label("generic")
	IgnoreFlagsAction        = Label("ignore-flags")
)

describes all available actions expressed through labels

View Source
var (
	NameLabel             = Label("name")
	RepositoryLabel       = Label("repository")
	SourceRepositoryLabel = Label("source-repository")
	TargetVersionLabel    = Label("target-version")
	RuntimeVersionLabel   = Label("runtime-version")
	ImagesLabel           = Label("images")

	TagExtraIdentity        = ExtraIdentityKey("tag")
	RepositoryExtraIdentity = ExtraIdentityKey("repository")
)
View Source
var (
	// ReferencedResourceNotFoundError is an error that indicates that a image is referenced by a external component
	// but it cannot be found in the referenced component.
	ErrReferencedResourceNotFoundError = errors.New("ReferencedResourceNotFound")
)

Functions

func ExtraIdentityKey

func ExtraIdentityKey(name string) string

ExtraIdentityKey creates a new identity key for a name and append the image vector prefix.

func ImageEntryIsComponentReference

func ImageEntryIsComponentReference(image ImageEntry, opts *ParseImageOptions) bool

ImageEntryIsComponentReference checks if the image entry should be parsed as component reference

func ImageEntryIsGenericDependency

func ImageEntryIsGenericDependency(image ImageEntry, opts *ParseImageOptions) bool

ImageEntryIsGenericDependency checks if the image entry should be parsed as generic dependency

func Label

func Label(name string) string

Label creates a new label for a name and append the image vector prefix.

func ParseImageRef

func ParseImageRef(ref string) (repository, version string, err error)

ParseImageRef parses a valid image ref into its repository and version

func ParseImageVector

func ParseImageVector(ctx context.Context,
	compResolver ctf.ComponentResolver,
	cd *cdv2.ComponentDescriptor,
	reader io.Reader,
	opts *ParseImageOptions) error

ParseImageVector parses a image vector and generates the corresponding component descriptor resources. It is expected that the image vector yaml is passed as io.Reader.

There are 4 different scenarios how images are added to the component descriptor. 1. The image is defined with a tag and will be directly translated as oci image resource.

<pre> images:

  • name: pause-container sourceRepository: github.com/kubernetes/kubernetes/blob/master/build/pause/Dockerfile repository: gcr.io/google_containers/pause-amd64 tag: "3.1"

</pre>

<pre> meta:

schemaVersion: 'v2'

... resources:

  • name: pause-container version: "3.1" type: ociImage extraIdentity: "imagevector-gardener-cloud+tag": "3.1" labels:
  • name: imagevector.gardener.cloud/name value: pause-container
  • name: imagevector.gardener.cloud/repository value: gcr.io/google_containers/pause-amd64
  • name: imagevector.gardener.cloud/source-repository value: github.com/kubernetes/kubernetes/blob/master/build/pause/Dockerfile access: type: ociRegistry imageReference: gcr.io/google_containers/pause-amd64:3.1

</pre>

2. The image is defined by another component so the image is added as label ("imagevector.gardener.cloud/images") to the "componentReference".

Images that are defined by other components can be specified 1. when the image's repository matches the given "--component-prefixes" 2. the image is labeled with "imagevector.gardener.cloud/component-reference"

If the component reference is not yet defined it will be automatically added. If multiple images are defined for the same component reference they are added to the images list in the label.

<pre> images:

  • name: cluster-autoscaler sourceRepository: github.com/gardener/autoscaler repository: eu.gcr.io/gardener-project/gardener/autoscaler/cluster-autoscaler targetVersion: "< 1.16" tag: "v0.10.0" labels: # recommended bbut only needed when "--component-prefixes" is not defined
  • name: imagevector.gardener.cloud/component-reference value: name: cla # defaults to image.name componentName: github.com/gardener/autoscaler # defaults to image.sourceRepository version: v0.10.0 # defaults to image.version

</pre>

<pre> meta:

schemaVersion: 'v2'

... componentReferences:

  • name: cla componentName: github.com/gardener/autoscaler version: v0.10.0 extraIdentity: imagevector-gardener-cloud+tag: v0.10.0 labels:
  • name: imagevector.gardener.cloud/images value: images:
  • name: cluster-autoscaler repository: eu.gcr.io/gardener-project/gardener/autoscaler/cluster-autoscaler sourceRepository: github.com/gardener/autoscaler tag: v0.10.0 targetVersion: '< 1.16' </pre>

3. The image is a generic dependency where the actual images are defined by the overwrite. A generic dependency image is not part of a component descriptor's resource but will be added as label ("imagevector.gardener.cloud/images") to the component descriptor.

Generic dependencies can be defined by 1. defined as "--generic-dependency=<image name>" 2. the label "imagevector.gardener.cloud/generic"

<pre> images:

  • name: hyperkube sourceRepository: github.com/kubernetes/kubernetes repository: k8s.gcr.io/hyperkube targetVersion: "< 1.19" labels: # only needed if "--generic-dependency" is not set
  • name: imagevector.gardener.cloud/generic

</pre>

<pre> meta:

schemaVersion: 'v2'

component:

  labels:
  - name: imagevector.gardener.cloud/images
    value:
    images:
	 - name: hyperkube
	   repository: k8s.gcr.io/hyperkube
	   sourceRepository: github.com/kubernetes/kubernetes
	   targetVersion: '< 1.19'
 </pre>

4. The image has not tag and it's repository matches a already defined resource in the component descriptor. This usually means that the image is build as part of the build pipeline and the version depends on the current component. In this case only labels are added to the existing resource

<pre> images:

  • name: gardenlet sourceRepository: github.com/gardener/gardener repository: eu.gcr.io/gardener-project/gardener/gardenlet

</pre>

<pre> meta:

schemaVersion: 'v2'

... resources:

  • name: gardenlet version: "v0.0.0" type: ociImage relation: local labels:
  • name: imagevector.gardener.cloud/name value: gardenlet
  • name: imagevector.gardener.cloud/repository value: eu.gcr.io/gardener-project/gardener/gardenlet
  • name: imagevector.gardener.cloud/source-repository value: github.com/gardener/gardener access: type: ociRegistry imageReference: eu.gcr.io/gardener-project/gardener/gardenlet:v0.0.0

</pre>

func TagIsDigest

func TagIsDigest(tag string) bool

TagIsDigest validates of a tag is a valid digest.

Types

type ComponentReferenceImageEntry

type ComponentReferenceImageEntry struct {
	ImageEntry
	// ResourceID is the name of the resource that the image references in the component descriptor.
	// +optional
	ResourceID cdv2.Identity `json:"resourceId,omitempty"`
}

ComponentReferenceImageEntry defines one image entry of a image vector in a component reference

type ComponentReferenceImageVector

type ComponentReferenceImageVector struct {
	Images []ComponentReferenceImageEntry `json:"images"  yaml:"images,omitempty"`
}

ComponentReferenceImageVector defines a image vector that defines oci images with specific requirements.

type ComponentReferenceLabelValue

type ComponentReferenceLabelValue struct {
	Name          string `json:"name,omitempty" yaml:"name,omitempty"`
	ComponentName string `json:"componentName,omitempty" yaml:"componentName,omitempty"`
	Version       string `json:"version,omitempty" yaml:"version,omitempty"`
}

ComponentReferenceLabelValue is the value configuration for the component reference

type GenerateImageOverwriteOptions

type GenerateImageOverwriteOptions struct {
	// Components defines a list of component descriptors that
	// should be used as source for the generic image dependencies.
	// +optional
	Components *cdv2.ComponentDescriptorList
	// ReplaceWithDigests configures the overwrite to automatically resolve tags to use digests.
	// If this is set to true the oci client is required
	ReplaceWithDigests bool
	// OciClient is a oci client to resolve references.
	OciClient OCIResolver
}

GenerateImageOverwriteOptions are options to configure the image vector overwrite generation.

func (GenerateImageOverwriteOptions) Validate

func (o GenerateImageOverwriteOptions) Validate() error

Validate validates the GenerateImageOverwriteOptions.

type ImageEntry

type ImageEntry struct {
	// Name defines the name of the image entry
	Name string `json:"name" yaml:"name"`
	// SourceRepository is the name of the repository where the image was build from
	SourceRepository string `json:"sourceRepository,omitempty" yaml:"sourceRepository,omitempty"`
	// Repository defines the image repository
	Repository string `json:"repository" yaml:"repository,omitempty"`
	// +optional
	Tag *string `json:"tag,omitempty" yaml:"tag,omitempty"`
	// +optional
	RuntimeVersion *string `json:"runtimeVersion,omitempty" yaml:"runtimeVersion,omitempty"`
	// +optional
	TargetVersion *string `json:"targetVersion,omitempty" yaml:"targetVersion,omitempty"`
	// Labels describes optional labels that can be used to describe the image or add additional information.
	// +optional
	Labels cdv2.Labels `json:"labels,omitempty" yaml:"labels,omitempty"`
}

ImageEntry defines one image entry of a image vector

type ImageVector

type ImageVector struct {
	Images []ImageEntry `json:"images"  yaml:"images,omitempty"`
	Labels cdv2.Labels  `json:"labels,omitempty"  yaml:"labels,omitempty"`
}

ImageVector defines a image vector that defines oci images with specific requirements

func DecodeImageVector

func DecodeImageVector(r io.Reader) (*ImageVector, error)

func GenerateImageOverwrite

func GenerateImageOverwrite(ctx context.Context,
	compResolver ctf.ComponentResolver,
	cd *cdv2.ComponentDescriptor,
	opts GenerateImageOverwriteOptions) (*ImageVector, error)

GenerateImageOverwrite parses a component descriptor and returns the defined image vector.

Images can be defined in a component descriptor in 3 different ways:

  1. as 'ociImage' resource: The image is defined a default resource of type 'ociImage' with a access of type 'ociRegistry'. It is expected that the resource contains the following labels to be identified as image vector image. The resulting image overwrite will contain the repository and the tag/digest from the access method.

<pre> resources:

  • name: pause-container version: "3.1" type: ociImage relation: external extraIdentity: "imagevector-gardener-cloud+tag": "3.1" labels:
  • name: imagevector.gardener.cloud/name value: pause-container
  • name: imagevector.gardener.cloud/repository value: gcr.io/google_containers/pause-amd64
  • name: imagevector.gardener.cloud/source-repository value: github.com/kubernetes/kubernetes/blob/master/build/pause/Dockerfile
  • name: imagevector.gardener.cloud/target-version value: "< 1.16" access: type: ociRegistry imageReference: gcr.io/google_containers/pause-amd64:3.1

</pre>

  1. as component reference: The images are defined in a label "imagevector.gardener.cloud/images". The resulting image overwrite will contain all images defined in the images label. Their repository and tag/digest will be matched from the resources defined in the actual component's resources.

    Note: The images from the label are matched to the resources using their name and version. The original image reference do not exit anymore.

<pre> componentReferences:

  • name: cluster-autoscaler-abc componentName: github.com/gardener/autoscaler version: v0.10.1 labels:
  • name: imagevector.gardener.cloud/images value: images:
  • name: cluster-autoscaler repository: eu.gcr.io/gardener-project/gardener/autoscaler/cluster-autoscaler tag: "v0.10.1"

</pre>

  1. as generic images from the component descriptor labels. Generic images are images that do not directly result in a resource. They will be matched with another component descriptor that actually defines the images. The other component descriptor MUST have the "imagevector.gardener.cloud/name" label in order to be matched.

<pre> meta:

schemaVersion: 'v2'

component:

labels:
- name: imagevector.gardener.cloud/images
  value:
    images:
    - name: hyperkube
      repository: k8s.gcr.io/hyperkube
      targetVersion: "< 1.19"

</pre>

<pre> meta:

schemaVersion: 'v2'

component:

  resources:
  - name: hyperkube
    version: "v1.19.4"
    type: ociImage
    extraIdentity:
      "imagevector-gardener-cloud+tag": "v1.19.4"
    labels:
    - name: imagevector.gardener.cloud/name
      value: hyperkube
    - name: imagevector.gardener.cloud/repository
      value: k8s.gcr.io/hyperkube
    access:
	   type: ociRegistry
	   imageReference: my-registry/hyperkube:v1.19.4

</pre>

type OCIResolver

type OCIResolver interface {
	// Resolve attempts to resolve the reference into a name and descriptor.
	//
	// The argument `ref` should be a scheme-less URI representing the remote.
	// Structurally, it has a host and path. The "host" can be used to directly
	// reference a specific host or be matched against a specific handler.
	//
	// The returned name should be used to identify the referenced entity.
	// Depending on the remote namespace, this may be immutable or mutable.
	// While the name may differ from ref, it should itself be a valid ref.
	//
	// If the resolution fails, an error will be returned.
	Resolve(ctx context.Context, ref string) (name string, desc ocispecv1.Descriptor, err error)
}

OCIResolver resolves oci references

type ParseImageOptions

type ParseImageOptions struct {
	// ComponentReferencePrefixes are prefixes that are used to identify images from other components.
	// These images are then not added as direct resources but the source repository is used as the component reference.
	ComponentReferencePrefixes []string
	// ExcludeComponentReference defines a list of image names that should be added as component reference
	ExcludeComponentReference []string
	// GenericDependencies define images that should be untouched and not added as real dependency to the component descriptors.
	// These dependencies are added a specific label to the component descriptor.
	GenericDependencies []string
	// IgnoreDeprecatedFlags ignores the deprecated parse options.
	IgnoreDeprecatedFlags bool
}

ParseImageOptions are options to configure the image vector parsing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL