version

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnexpectedResponse is returned when an unexpected response is received from a repository.
	ErrUnexpectedResponse = errors.New("Unexpected response")
	// ErrChartNotFound is returned when a chart is not found in the repository.
	ErrChartNotFound = errors.New("Chart not found")
)

Functions

func UpdateCommitMessage

func UpdateCommitMessage(targetName, newVersion string) string

Types

type AvailableUpdate

type AvailableUpdate struct {
	// The current version that is being scanned for updates.
	// Format: tag@digest.
	// Digest is optional.
	CurrentVersion string
	// The new version that has been found.
	// Format: tag@digest.
	// Digest is optional.
	NewVersion string

	// Integration defines the method on how to push updates to the version control system.
	Integration UpdateIntegration

	// File where the versions were found.
	File string
	// Line number within the file where the versions were found.
	Line   int
	Target UpdateTarget

	// URL to find more information on the update/package.
	URL string
}

AvailableUpdate represents the result of a positive version scanning operation. It holds details about the current and new version, as well as the file and line at which these versions were found and the desired update integration method.

type ChartUpdateTarget

type ChartUpdateTarget struct {
	Chart *helm.Chart
}

ChartUpdateTarget defines the helm chart to be updated.

func (*ChartUpdateTarget) GetStructValue

func (c *ChartUpdateTarget) GetStructValue() string

func (*ChartUpdateTarget) Name

func (c *ChartUpdateTarget) Name() string

type ContainerUpdateTarget

type ContainerUpdateTarget struct {
	// Image value of the 'tagged' field.
	// It has the format 'repository:tag@digest'.
	Image string

	// Reference to the struct holding repository and version fields.
	UnstructuredNode map[string]any

	// Field key or label of the version field.
	UnstructuredKey string
}

ContainerUpdateTarget defines the container image to be updated.

func (*ContainerUpdateTarget) GetStructValue

func (c *ContainerUpdateTarget) GetStructValue() string

func (*ContainerUpdateTarget) Name

func (c *ContainerUpdateTarget) Name() string

type Scanner

type Scanner struct {
	Log        logr.Logger
	KubeClient kube.Client[unstructured.Unstructured, unstructured.Unstructured]

	OCIClient oci.Client

	// Kubernetes namespace where the registry credential secret is stored.
	Namespace string

	// Endpoint to the microsoft azure login server.
	// Default is: https://login.microsoftonline.com/.
	AzureLoginURL string

	// Endpoint to the google metadata server, which provides access tokens.
	// Default is: http://metadata.google.internal.
	GCPMetadataServerURL string
}

Scanner is the system for performing version scanning operations. It takes update instructions and contacts image registries to fetch remote tags and calculates the latest tag based on the provided update strategy. If the latest tag is greater than the current tag, it returns an AvailableUpdate.

func (*Scanner) Scan

func (scanner *Scanner) Scan(
	ctx context.Context,
	updateInstr UpdateInstruction,
) (*AvailableUpdate, bool, error)

type SemVerStrategy

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

Semantic Versioning as defined in https://semver.org/.

func (*SemVerStrategy) HasNewerRemoteVersion

func (strat *SemVerStrategy) HasNewerRemoteVersion(
	currentVersion string,
	remoteVersions VersionIter[string],
) (string, bool, int, error)

type Strategy

type Strategy interface {
	HasNewerRemoteVersion(
		currentVersion string,
		remoteVersions VersionIter[string],
	) (string, bool, int, error)
}

type Update

type Update struct {
	// CommitHash contains the SHA1 of the commit.
	CommitHash string

	// NewVersion contains the updated version.
	NewVersion string

	// IsPR tells whether this update is a direct commit or a pull request.
	IsPR bool
}

Update represents the result of an update operation.

type UpdateInstruction

type UpdateInstruction struct {
	// Strategy defines the method to update the target.
	Strategy UpdateStrategy
	// Constraint specifies any constraints that need to be considered during the update process.
	Constraint string
	// Auth contains authentication details required for accessing and updating the target.
	// Only relevant for manifest components. For Helm Charts, auth is taken from the component def.
	Auth *cloud.Auth

	// Integration defines the method on how to push updates to the version control system.
	Integration UpdateIntegration

	// Schedule is a string in cron format with an additional seconds field and defines when the target is scanned for updates.
	Schedule string

	// File is a relative path to the file where the version value is located.
	File string
	// Line number in the file where the version value resides.
	Line int

	// Target specifies what needs to be updated, which can be a container image or a Helm chart.
	// A container image follows the format 'repository:tag@digest'.
	// A Helm repository can either be of type 'oci' or 'https'.
	Target UpdateTarget
}

UpdateInstruction represents the instruction for updating a target, such as a container image or a Helm chart.

type UpdateIntegration

type UpdateIntegration int

UpdateIntegration defines the method on how to push updates to the version control system.

const (
	// PR indicates to push updates to a separate update branch and create a pull request. Updates are not applied immediately, only after the PR has been merged and the changes were pulled.
	PR UpdateIntegration = iota
	// Direct indicates to push updates directly to the base branch and reconcile them in the same run.
	Direct
)

type UpdateScheduler

type UpdateScheduler struct {
	Log logr.Logger

	Scanner Scanner
	Updater Updater

	Scheduler gocron.Scheduler

	QuitChan chan struct{}
}

UpdateScheduler runs background tasks periodically to update Container or Helm Charts.

func (*UpdateScheduler) Schedule

func (scheduler *UpdateScheduler) Schedule(
	ctx context.Context,
	updateInstructions []UpdateInstruction,
) (int, error)

type UpdateStrategy

type UpdateStrategy int

UpdateStrategy defines the container image or helm chart update strategy to calculate the latest version.

const (
	// Semantic Versioning as defined in https://semver.org/.
	SemVer UpdateStrategy = iota
)

type UpdateTarget

type UpdateTarget interface {
	// Name returns the name of the update target.
	// It is either a container name or a helm chart.
	Name() string
	// GetStructValue retrieves the current value of the struct field.
	// It is either an image field in an unstructured manifest or a version field in a helm chart.
	GetStructValue() string
}

Object to be updated.

type Updater

type Updater struct {
	Log        logr.Logger
	Repository vcs.Repository
	Branch     string
}

Updater accepts update information that tell which images to update. It pushes its changes to remote before returning.

func (*Updater) Update

func (updater *Updater) Update(
	ctx context.Context,
	availableUpdate AvailableUpdate,
) (*Update, error)

Update accepts available updates that tell which images or chart to update and returns update results. The update result can be nil in case a PR for the update currently already exists.

type VersionIter

type VersionIter[T any] interface {
	ForEach(do func(item T, idx int))
}

Jump to

Keyboard shortcuts

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