Documentation ¶
Index ¶
- Variables
- func SplitHostname(name string) (hostname, remoteName string)
- type Components
- func (c *Components) Digest() string
- func (c *Components) FullRepository() string
- func (c *Components) Hostname() string
- func (c *Components) RemoveDigest()
- func (c *Components) RemoveHostname()
- func (c *Components) RemoveRepository()
- func (c *Components) RemoveTag()
- func (c *Components) RemoveTagOrDigest()
- func (c *Components) Repository() string
- func (c *Components) SetDigest(digest string)
- func (c *Components) SetHostname(hostname string)
- func (c *Components) SetRepository(repository string)
- func (c *Components) SetTag(tag string)
- func (c *Components) SetTagOrDigest(input string)
- func (c *Components) String() string
- func (c *Components) Tag() string
- func (c *Components) TagOrDigest() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
SplitHostname splits a repository name(ie: k8s.gcr.io/kube-apiserver) to hostname(k8s.gcr.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) 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) 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) 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).
func (*Components) TagOrDigest ¶
func (c *Components) TagOrDigest() string
TagOrDigest returns image tag if not empty otherwise returns image digest.