reimage

package module
v0.0.0-alpha0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

README

#Re-image

A tool for mass update of images for kubernetes manifests. This is a Work In Progress, YMMV, configuration and settings may change.

  • Works with helm post-renderer, or arbitrary k8s manifests
  • Check images used by Deployments, StatefulSets, DaemonSets, Cronjobs and Job (or arbitrary objects using jsonpath queries):
    • Exists (prevents deploy of manifests with bad references)
    • Remap tags (e.g latest) to a tag for the explicit digest they currently map to
    • Optionally syncs images from third party repositories to known repository

This is intended to:

  • Prevent deploying assets with un-pullable images
  • Localise images for faster start times
  • Potentially improve availability by reducing runtime third party service dependencies (e.g. dockerhub)
  • Help with compliance by pulling all images from registries with image scanning
  • Help with the use of in-cluster binary authorization

Documentation

Overview

Package reimage provides tools for processing/updating the images listed in k8s manifests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Process

func Process(w io.Writer, r io.Reader, u Updater) error

Process runs the Updater for each kubernetes resource found in the file. Unknown field are converted to

Types

type ImageSetters

type ImageSetters []Setter

ImageSetters is list of one of more Setters

func (ImageSetters) Set

func (ss ImageSetters) Set(img string)

Set all the image setters in the list to the provided image

type ImagesFinder

type ImagesFinder interface {
	FindImages(obj *unstructured.Unstructured) (map[string]ImageSetters, error)
}

ImagesFinder specifies any mechanism for finding images within any k8s Unstructured data. Each entry in the map is an image name that was found. Calling the Set method on the map values will replace the discovered image name with a replacement.

func CompileJSONImageFinders

func CompileJSONImageFinders(jmCfgs []JSONImageFinderConfig) (ImagesFinder, error)

CompileJSONImageFinders builds an ImagesFinder than can find image configuration strings from arbitrary unstructured K8S JSON objects, using JSONP queries

type JSONImageFinderConfig

type JSONImageFinderConfig struct {
	Kind       string   `json:"kind" yaml:"kind"`             // regexp to match k8s kind
	APIVersion string   `json:"apiVersion" yaml:"apiVersion"` // regexp to match k8s apiVersion
	ImageJSONP []string `json:"imageJSONP" yaml:"imageJSONP"` // jsonP queries to find individual image fields
}

JSONImageFinderConfig describes the settings for finding arbitrary image fields in K8S types

type MultiRemapper

type MultiRemapper []Remapper

MultiRemapper applies each remapper, passing results from one to the next.

func (MultiRemapper) ReMap

func (t MultiRemapper) ReMap(ref name.Reference) (name.Reference, error)

ReMap applies each remapper, passing results from one to the next. An error is returned as soon as any remapper fails

type RemapUpdater

type RemapUpdater struct {
	Ignore                   *regexp.Regexp
	UnstructuredImagesFinder ImagesFinder
	Remapper                 Remapper
}

RemapUpdater applies the Remapper to all images found in object passed to Update. For Objects of unknown types the UnstructuredImagesFinder is used. TODO(tcm): rename this thinger.

func (*RemapUpdater) Update

func (s *RemapUpdater) Update(obj runtime.Object) error

Update applies the Remapper to all found images in the object

type Remapper

type Remapper interface {
	ReMap(ref name.Reference) (name.Reference, error)
}

A Remapper transforms OCI images references, and may perform side effects

type RepoRemapper

type RepoRemapper struct {
	RemotePath string             // used for the .RemotePath value in the template
	RemoteTmpl *template.Template // template to build the final image string
	NoClobber  bool               // If true, we'll refuse to overwrite remote images
}

RepoRemapper is a Remapper implementation that copies images to a remote registry/repository path. The new path is built using RemoteTmpl, and the copy is performed using crane.Copy.

func (*RepoRemapper) ReMap

func (t *RepoRemapper) ReMap(ref name.Reference) (name.Reference, error)

ReMap copies an image from the original registry to a given new destination registry

type RepoTemplateInput

type RepoTemplateInput struct {
	RemotePath string // The request remote repository and registry prefix
	Digest     string // The digest of the image
	DigestAlgo string // The hash algorithm of the image digest
	DigestHex  string // The hex string of the digest hash
	Tag        string // The image tag (TODO(tcm): not used at the moment)
	Registry   string // The image registry
	Repository string // The image repository
}

RepoTemplateInput is the input provied to the RemoteTmpl of the RepoRemapper

type Setter

type Setter func(img string)

A Setter is used for setting the string description of an image

type TagRemapper

type TagRemapper struct {
	CheckOnly bool // CheckOnly will ensure the remote image exists, but will leave it unchanged
}

TagRemapper looks up the remote image and translates it to the current digest form

func (*TagRemapper) ReMap

func (t *TagRemapper) ReMap(ref name.Reference) (name.Reference, error)

ReMap looks up the remote image and translates it to the current digest form

type Updater

type Updater interface {
	Update(obj runtime.Object) error
}

Updater is used by Process search for, and update, images in k8s objects

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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