imageparser

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (

	// TagRegexp matches valid tag names. From docker/docker:graph/tags.go.
	TagRegexp = match(`[\w][\w.-]{0,127}`)

	// DigestRegexp matches valid digests.
	DigestRegexp = match(`[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[:xdigit:]]{32,}`)
)

Functions

func SplitHostname

func SplitHostname(name string) (hostname, remoteName string)

SplitHostname splits a repository name(ie: registry.k8s.io/kube-apiserver) to hostname(registry.k8s.io) and remotename(kube-apiserver) string.

Types

type Components

type Components struct {
	// contains filtered or unexported fields
}

Components make up a whole image. Basically we presume an image can be made of `[domain][:port][path]<name>[:tag][@sha256:digest]`, ie: fictional.registry.example:10443/karmada/karmada-controller-manager:v1.0.0 or fictional.registry.example:10443/karmada/karmada-controller-manager@sha256:50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c

func Parse

func Parse(image string) (*Components, error)

Parse returns a Components of the given image.

func (*Components) Digest

func (c *Components) Digest() string

Digest returns the digest.

func (*Components) FullRepository

func (c *Components) FullRepository() string

FullRepository returns the whole repository, including hostname if not empty.

func (*Components) Hostname

func (c *Components) Hostname() string

Hostname returns the hostname, as well known as image registry.

func (*Components) RemoveDigest

func (c *Components) RemoveDigest()

RemoveDigest removes the digest.

func (*Components) RemoveHostname

func (c *Components) RemoveHostname()

RemoveHostname removes the hostname.

func (*Components) RemoveRepository

func (c *Components) RemoveRepository()

RemoveRepository removes the repository.

func (*Components) RemoveTag

func (c *Components) RemoveTag()

RemoveTag removes the tag.

func (*Components) RemoveTagOrDigest

func (c *Components) RemoveTagOrDigest()

RemoveTagOrDigest removes tag or digest. Since tag and digest don't co-exist, so remove tag if tag not empty, otherwise remove digest.

func (*Components) Repository

func (c *Components) Repository() string

Repository returns the repository without hostname.

func (*Components) SetDigest

func (c *Components) SetDigest(digest string)

SetDigest sets the digest.

func (*Components) SetHostname

func (c *Components) SetHostname(hostname string)

SetHostname sets the hostname.

Example
image := "imagename:v1.0.0"
comp, err := Parse(image)
if err != nil {
	panic(err)
}

comp.SetHostname("fictional.registry.example") // add hostname
fmt.Println(comp.String())
comp.SetHostname("gcr.io") // update hostname
fmt.Println(comp.String())
comp.RemoveHostname() // remove hostname
fmt.Println(comp.String())
Output:

fictional.registry.example/imagename:v1.0.0
gcr.io/imagename:v1.0.0
imagename:v1.0.0

func (*Components) SetRepository

func (c *Components) SetRepository(repository string)

SetRepository sets the repository.

Example
image := "gcr.io/kube-apiserver:v1.19.0"
comp, err := Parse(image)
if err != nil {
	panic(err)
}

comp.SetRepository("kube-controller-manager") // update
fmt.Println(comp.String())
Output:

gcr.io/kube-controller-manager:v1.19.0

func (*Components) SetTag

func (c *Components) SetTag(tag string)

SetTag sets the tag.

func (*Components) SetTagOrDigest

func (c *Components) SetTagOrDigest(input string)

SetTagOrDigest sets image tag or digest by matching the input.

Example
image := "gcr.io/kube-apiserver"
comp, err := Parse(image)
if err != nil {
	panic(err)
}

comp.SetTagOrDigest("v1.19.0") // set
fmt.Println(comp.String())
comp.RemoveTagOrDigest() // remove tag
fmt.Println(comp.String())
comp.SetTagOrDigest("sha256:50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c") // update
fmt.Println(comp.String())
comp.RemoveTagOrDigest() // remove digest
fmt.Println(comp.String())
Output:

gcr.io/kube-apiserver:v1.19.0
gcr.io/kube-apiserver
gcr.io/kube-apiserver@sha256:50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c
gcr.io/kube-apiserver

func (Components) String

func (c Components) String() string

String returns the full name of the image, including repository and tag(or digest).

Example
key := Components{
	hostname:   "fictional.registry.example",
	repository: "karmada-scheduler",
	tag:        "v1.0.0",
}
pKey := &key
fmt.Printf("%s\n", key)
fmt.Printf("%v\n", key)
fmt.Printf("%s\n", key.String())
fmt.Printf("%s\n", pKey)
fmt.Printf("%v\n", pKey)
fmt.Printf("%s\n", pKey.String())
Output:

fictional.registry.example/karmada-scheduler:v1.0.0
fictional.registry.example/karmada-scheduler:v1.0.0
fictional.registry.example/karmada-scheduler:v1.0.0
fictional.registry.example/karmada-scheduler:v1.0.0
fictional.registry.example/karmada-scheduler:v1.0.0
fictional.registry.example/karmada-scheduler:v1.0.0

func (*Components) Tag

func (c *Components) Tag() string

Tag returns the tag.

func (*Components) TagOrDigest

func (c *Components) TagOrDigest() string

TagOrDigest returns image tag if not empty otherwise returns image digest.

Jump to

Keyboard shortcuts

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