hydrate

package
v1.17.3 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DoneFile is the file name that indicates the hydration is done.
	DoneFile = "done"
	// ErrorFile is the file name of the hydration errors.
	ErrorFile = "error.json"
)
View Source
const (
	// HelmVersion is the recommended version of Helm for hydration.
	HelmVersion = "v3.13.3-gke.2"
	// KustomizeVersion is the recommended version of Kustomize for hydration.
	KustomizeVersion = "v5.3.0-gke.0"
	// Helm is the binary name of the installed Helm.
	Helm = "helm"
	// Kustomize is the binary name of the installed Kustomize.
	Kustomize = "kustomize"
)

Variables

This section is empty.

Functions

func Clean

func Clean(objects []ast.FileObject)

Clean removes invalid fields from objects before writing them to a file.

func ComputeCommit added in v1.15.1

func ComputeCommit(sourceDir cmpath.Absolute) (string, error)

ComputeCommit returns the computed commit from given sourceDir, or error if the sourceDir fails symbolic link evaluation

func DoneCommit

func DoneCommit(donePath string) string

DoneCommit extracts the commit hash from the done file if exists. It returns the commit hash if exists, otherwise, returns an empty string. If it fails to extract the commit hash for various errors, we only log a warning, and wait for the next hydration loop to retry the hydration.

func ForEachCluster

func ForEachCluster(ctx context.Context, parseOpts ParseOptions, validateOpts validate.Options, f ClusterFilterFunc)

ForEachCluster hydrates an AllConfigs for each declared cluster and executes the passed function on the result.

parser is the ConfigParser which returns a set of FileObjects and a possible MultiError when Parse is called.

getSyncedCRDs is the set of CRDs synced the the cluster used for APIServer checks. enableAPIServerChecks is whether to call Parse with APIServer checks enabled. apiResources is how to read cached API resources from the disk. filePaths is the list of absolute file paths to parse and the absolute and relative paths of the Nomos root.

f is a function with three arguments: - clusterName, the name of the Cluster the Parser was called with. - fileObjects, the FileObjects which Parser.Parse returned. - err, the MultiError which Parser.Parse returned, if there was one.

Per standard ForEach conventions, ForEachCluster has no return value.

func GenerateFileObjects

func GenerateFileObjects(multiCluster bool, objects ...ast.FileObject) []ast.FileObject

GenerateFileObjects returns a set of file objects with unique file names and invalid fields removed from objects.

func HasKustomization added in v1.16.0

func HasKustomization(filename string) bool

HasKustomization checks if the file is a Kustomize configuration file.

func PrintDirectoryOutput

func PrintDirectoryOutput(output, extension string, fileObjects []ast.FileObject) error

PrintDirectoryOutput prints the hydrated output to multiple files in a directory.

func PrintFile

func PrintFile(file, extension string, objects []*unstructured.Unstructured) (err error)

PrintFile prints the passed objects to file.

func PrintFlatOutput

func PrintFlatOutput(output, extension string, fileObjects []ast.FileObject) error

PrintFlatOutput prints the hydrated output to a single file.

func SourceCommitAndDir

func SourceCommitAndDir(sourceType v1beta1.SourceType, sourceRevDir cmpath.Absolute, syncDir cmpath.Relative, reconcilerName string) (string, cmpath.Absolute, error)

SourceCommitAndDir returns the source hash (a git commit hash or an OCI image digest or a helm chart version), the absolute path of the sync directory, and source errors.

func SourceCommitAndDirWithRetry added in v1.16.2

func SourceCommitAndDirWithRetry(backoff wait.Backoff, sourceType v1beta1.SourceType, sourceRevDir cmpath.Absolute, syncDir cmpath.Relative, reconcilerName string) (commit string, sourceDir cmpath.Absolute, _ status.Error)

SourceCommitAndDirWithRetry returns the source hash (a git commit hash or an OCI image digest or a helm chart version), the absolute path of the sync directory, and source errors. It retries with the provided backoff.

func ValidateAndRunKustomize

func ValidateAndRunKustomize(sourcePath string) (cmpath.Absolute, error)

ValidateAndRunKustomize validates if the Kustomize and Helm binaries are supported. If supported, it copies the source configs to a temp directory, run 'kustomize build', save the output to another temp directory, and return the output path for further parsing and validation.

func ValidateHydrateFlags

func ValidateHydrateFlags(sourceFormat filesystem.SourceFormat) (cmpath.Absolute, bool, error)

ValidateHydrateFlags validates the hydrate and vet flags. It returns the absolute path of the source directory, if hydration is needed, and errors.

func ValidateOptions

func ValidateOptions(ctx context.Context, rootDir cmpath.Absolute, apiServerTimeout time.Duration) (validate.Options, error)

ValidateOptions returns the validate options for nomos hydrate and vet commands.

Types

type ActionableError

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

ActionableError represents the user actionable hydration error.

func NewActionableError

func NewActionableError(e error) ActionableError

NewActionableError returns the wrapper of the user actionable error.

func (ActionableError) Code

func (e ActionableError) Code() string

Code returns the user actionable error code.

type ClusterFilterFunc added in v1.17.0

type ClusterFilterFunc func(clusterName string, fileObjects []ast.FileObject, err status.MultiError)

ClusterFilterFunc is the type alias for the function that filters objects for selected clusters.

type HydrationError

type HydrationError interface {
	// Code is the error code to indicate if it is a user error or an internal error.
	Code() string
	error
}

HydrationError is a wrapper of the error in the hydration process with the error code.

type HydrationErrorPayload

type HydrationErrorPayload struct {
	// Code is the error code to indicate if it is a user error or an internal error.
	Code string
	// Error is the message of the hydration error.
	Error string
}

HydrationErrorPayload is the payload of the hydration error in the error file.

type Hydrator

type Hydrator struct {
	// DonePath is the absolute path to the done file under the /repo directory.
	DonePath cmpath.Absolute
	// SourceType is the type of the source repository, must be git or oci.
	SourceType v1beta1.SourceType
	// SourceRoot is the absolute path to the source root directory.
	SourceRoot cmpath.Absolute
	// HydratedRoot is the absolute path to the hydrated root directory.
	HydratedRoot cmpath.Absolute
	// SourceLink is the name of (a symlink to) the source directory under SourceRoot, which contains the clone of the git repo.
	SourceLink string
	// HydratedLink is the name of (a symlink to) the source directory under HydratedRoot, which contains the hydrated configs.
	HydratedLink string
	// SyncDir is the relative path to the configs within the Git repository.
	SyncDir cmpath.Relative
	// PollingPeriod is the period of time between checking the filesystem for source updates to render.
	PollingPeriod time.Duration
	// RehydratePeriod is the period of time between rehydrating on errors.
	RehydratePeriod time.Duration
	// ReconcilerName is the name of the reconciler.
	ReconcilerName string
}

Hydrator runs the hydration process.

func (*Hydrator) Run

func (h *Hydrator) Run(ctx context.Context)

Run runs the hydration process periodically.

type InternalError

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

InternalError represents the internal hydration error.

func NewInternalError

func NewInternalError(e error) InternalError

NewInternalError returns the wrapper of the internal error.

func (InternalError) Code

func (e InternalError) Code() string

Code returns the internal error code.

type ParseOptions added in v1.17.0

type ParseOptions struct {
	// Parser is an interface to read configs from a filesystem.
	Parser filesystem.ConfigParser
	// SourceFormat specifies how the Parser should parse the source configs.
	SourceFormat filesystem.SourceFormat
	// FilePaths encapsulates the list of absolute file paths to read and the
	// absolute and relative path of the root directory.
	FilePaths reader.FilePaths
}

ParseOptions includes information needed by the parsing step in nomos CLI. It is different from pkg/parse/opts.go used in the reconciler container on the server side.

type TransientError added in v1.15.1

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

TransientError represents the transient error that will be autoresolved in the retry.

func NewTransientError added in v1.15.1

func NewTransientError(e error) TransientError

NewTransientError returns the wrapper of the transient error.

func (TransientError) Code added in v1.15.1

func (e TransientError) Code() string

Code returns the transient error code.

Jump to

Keyboard shortcuts

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