Documentation
¶
Index ¶
- Variables
- func WithPushResultRefspec(refspecs []string) func(*PushResult)
- func WithPushResultSwitchBranch() func(*PushResult)
- type CheckoutOption
- type PushBranchError
- type PushConfig
- type PushResult
- type PushResultOption
- type RemovedTemplateFieldError
- type SourceManager
- func (sm *SourceManager) CheckoutSource(ctx context.Context, options ...CheckoutOption) (*git.Commit, error)
- func (sm SourceManager) Cleanup() error
- func (sm SourceManager) CommitAndPush(ctx context.Context, obj *imagev1.ImageUpdateAutomation, ...) (*PushResult, error)
- func (sm SourceManager) CompletePush(ctx context.Context, pushErr *PushBranchError, pushOptions ...PushConfig) (*PushResult, bool, error)
- func (sm *SourceManager) RefreshToRemote(ctx context.Context) error
- func (sm SourceManager) SwitchBranch() bool
- func (sm SourceManager) WorkDirectory() string
- type SourceOption
- func WithSourceOptionDefaultServiceAccount(name string) SourceOption
- func WithSourceOptionGitAllBranchReferences() SourceOption
- func WithSourceOptionInvolvedObject(name, namespace string) SourceOption
- func WithSourceOptionNoCrossNamespaceRef() SourceOption
- func WithSourceOptionSPIFFEBroker(client fluxbroker.Interface) SourceOption
- func WithSourceOptionTokenCache(tc *cache.TokenCache) SourceOption
- type SourceOptions
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSourceConfiguration = errors.New("invalid source configuration")
ErrInvalidSourceConfiguration is an error for invalid source configuration.
var ErrRemovedTemplateField = &RemovedTemplateFieldError{}
ErrRemovedTemplateField is a sentinel error for removed template field usage.
Functions ¶
func WithPushResultRefspec ¶
func WithPushResultRefspec(refspecs []string) func(*PushResult)
WithPushResultRefspec sets the refspecs in the PushResult.
func WithPushResultSwitchBranch ¶
func WithPushResultSwitchBranch() func(*PushResult)
WithPushResultSwitchBranch marks the PushResult with switchBranch.
Types ¶
type CheckoutOption ¶
type CheckoutOption func(*repository.CloneConfig)
CheckoutOption allows configuring the checkout options.
func WithCheckoutOptionLastObserved ¶
func WithCheckoutOptionLastObserved(commit string) CheckoutOption
WithCheckoutOptionLastObserved is a CheckoutOption option to configure the last observed commit.
func WithCheckoutOptionShallowClone ¶
func WithCheckoutOptionShallowClone() CheckoutOption
WithCheckoutOptionShallowClone is a CheckoutOption option to configure shallow clone.
func WithCheckoutOptionSparseCheckoutDirectories ¶ added in v1.0.0
func WithCheckoutOptionSparseCheckoutDirectories(updatePath string) CheckoutOption
WithCheckoutOptionSparseCheckoutDirectories is a CheckoutOption option to configure SparseCheckoutDirectories.
type PushBranchError ¶ added in v1.3.0
type PushBranchError struct {
// Revision is the revision of the commit that failed to be pushed.
Revision string
// Message is the message of the commit that failed to be pushed.
Message string
Err error
}
PushBranchError is returned by CommitAndPush when pushing the commit to the push branch fails. The push may still have reached the remote, for example when it timed out after the remote accepted it.
func (*PushBranchError) Error ¶ added in v1.3.0
func (e *PushBranchError) Error() string
func (*PushBranchError) Unwrap ¶ added in v1.3.0
func (e *PushBranchError) Unwrap() error
type PushConfig ¶
type PushConfig func(*repository.PushConfig)
PushConfig configures the options used in push operation.
func WithPushConfigForce ¶
func WithPushConfigForce() PushConfig
WithPushConfigForce configures the PushConfig to use force.
func WithPushConfigOptions ¶
func WithPushConfigOptions(opts map[string]string) PushConfig
WithPushConfigOptions configures the PushConfig Options that are used in push.
type PushResult ¶
type PushResult struct {
// contains filtered or unexported fields
}
PushResult is the result of a push operation.
func NewPushResult ¶
func NewPushResult(branch string, rev string, commitMsg string, opts ...PushResultOption) (*PushResult, error)
NewPushResult returns a new PushResult.
func (PushResult) Commit ¶
func (pr PushResult) Commit() *git.Commit
Commit returns the revision of the pushed commit.
func (PushResult) Summary ¶
func (pr PushResult) Summary() string
Summary returns a summary of the PushResult.
func (PushResult) SwitchBranch ¶
func (pr PushResult) SwitchBranch() bool
SwitchBranch returns if the source has different checkout and push branch.
func (PushResult) Time ¶
func (pr PushResult) Time() *metav1.Time
Time returns the time at which the push was performed.
type PushResultOption ¶
type PushResultOption func(*PushResult)
PushResultOption allows configuring the options of PushResult.
type RemovedTemplateFieldError ¶ added in v1.0.0
type RemovedTemplateFieldError struct {
Field string
}
RemovedTemplateFieldError represents an error when a removed template field is used.
func (*RemovedTemplateFieldError) Error ¶ added in v1.0.0
func (e *RemovedTemplateFieldError) Error() string
func (*RemovedTemplateFieldError) Is ¶ added in v1.0.0
func (e *RemovedTemplateFieldError) Is(target error) bool
type SourceManager ¶
type SourceManager struct {
// contains filtered or unexported fields
}
SourceManager manages source.
func NewSourceManager ¶
func NewSourceManager(ctx context.Context, c client.Client, obj *imagev1.ImageUpdateAutomation, options ...SourceOption) (*SourceManager, error)
NewSourceManager takes all the provided inputs, validates them and returns a SourceManager which can be used to operate on the configured source.
func (*SourceManager) CheckoutSource ¶
func (sm *SourceManager) CheckoutSource(ctx context.Context, options ...CheckoutOption) (*git.Commit, error)
CheckoutSource clones and checks out the source. If a push branch is configured that doesn't match with the checkout branch, a checkout to the push branch is also performed. This ensures any change and push operation following the checkout happens on the push branch.
func (SourceManager) Cleanup ¶
func (sm SourceManager) Cleanup() error
Cleanup deletes the working directory of the SourceManager.
func (SourceManager) CommitAndPush ¶
func (sm SourceManager) CommitAndPush(ctx context.Context, obj *imagev1.ImageUpdateAutomation, policyResult update.Result, pushOptions ...PushConfig) (*PushResult, error)
CommitAndPush performs a commit in the source and pushes it to the remote repository.
func (SourceManager) CompletePush ¶ added in v1.3.0
func (sm SourceManager) CompletePush(ctx context.Context, pushErr *PushBranchError, pushOptions ...PushConfig) (*PushResult, bool, error)
CompletePush completes a push that failed with pushErr, but reached the remote nonetheless, for example because it timed out after the remote accepted it. Call it after RefreshToRemote. If the push branch is at the commit of the failed push, it pushes the commit to the push refspec, if any, and returns the result and true. Otherwise, it returns false, and the changes have to be applied and pushed again.
func (*SourceManager) RefreshToRemote ¶ added in v1.3.0
func (sm *SourceManager) RefreshToRemote(ctx context.Context) error
RefreshToRemote catches up with the remote after a failed push by cloning the source again into a new working directory, discarding local commits and changes, so that they can be recomputed and pushed again. A separate push branch that is based on its remote state is cloned on its own, as only its tip is needed, unless a push refspec is set, as it can refer to the checkout branch. If cloning the push branch fails, for example because it does not exist on the remote, the source is cloned as at the last checkout.
Fetching into the existing clone is avoided, as it does not work with every Git server with go-git, and a shallow clone of a single branch costs about as much.
func (SourceManager) SwitchBranch ¶
func (sm SourceManager) SwitchBranch() bool
SwitchBranch returns if the checkout branch and push branch are different.
func (SourceManager) WorkDirectory ¶
func (sm SourceManager) WorkDirectory() string
CreateWorkingDirectory creates a working directory for the SourceManager.
type SourceOption ¶
type SourceOption func(*SourceOptions)
SourceOption configures the SourceManager options.
func WithSourceOptionDefaultServiceAccount ¶ added in v1.3.0
func WithSourceOptionDefaultServiceAccount(name string) SourceOption
WithSourceOptionDefaultServiceAccount configures the default ServiceAccount used for provider authentication when the GitRepository does not specify one.
func WithSourceOptionGitAllBranchReferences ¶
func WithSourceOptionGitAllBranchReferences() SourceOption
WithSourceOptionGitAllBranchReferences configures the SourceManager to fetch all the Git branch references that are present in the remote repository.
func WithSourceOptionInvolvedObject ¶ added in v0.41.0
func WithSourceOptionInvolvedObject(name, namespace string) SourceOption
WithSourceOptionInvolvedObject configures the SourceManager to use the provided ImageUpdateAutomation object.
func WithSourceOptionNoCrossNamespaceRef ¶
func WithSourceOptionNoCrossNamespaceRef() SourceOption
WithSourceOptionNoCrossNamespaceRef configures the SourceManager to disable cross namespace references.
func WithSourceOptionSPIFFEBroker ¶ added in v1.3.0
func WithSourceOptionSPIFFEBroker(client fluxbroker.Interface) SourceOption
WithSourceOptionSPIFFEBroker configures the SourceManager to use the given SPIFFE Broker client for the `spiffe` credential provider.
func WithSourceOptionTokenCache ¶ added in v0.41.0
func WithSourceOptionTokenCache(tc *cache.TokenCache) SourceOption
WithSourceOptionTokenCache configures the SourceManager to use the provided token cache.
type SourceOptions ¶
type SourceOptions struct {
// contains filtered or unexported fields
}
SourceOptions contains the optional attributes of SourceManager.
type TemplateData ¶
type TemplateData struct {
AutomationObject types.NamespacedName
Changed update.Result
Values map[string]string
}
TemplateData is the type of the value given to the commit message template.