plan

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HiddenVerboseCRDChanges    = "<hidden verbose CRD changes>"
	HiddenVerboseChanges       = "<hidden verbose changes>"
	HiddenInsignificantChanges = "<hidden insignificant changes>"
	HiddenSensitiveChanges     = "<hidden sensitive changes>"
)

Variables

Functions

func BuildResourceInfos added in v1.13.0

func BuildResourceInfos(ctx context.Context, deployType common.DeployType, releaseName, releaseNamespace string, instResources []*resource.InstallableResource, delResources []*resource.DeletableResource, prevReleaseFailed bool, clientFactory kube.ClientFactorier, opts BuildResourceInfosOptions) (instResourceInfos []*InstallableResourceInfo, delResourceInfos []*DeletableResourceInfo, err error)

From Installable/DeletableResource builds Installable/DeletableResourceInfo. If you can do something earlier than in BuildReleaseInfos - do it there. Here you can access the cluster to get more info, and here we actually decide what to do with each resource. Initially all this logic was in BuildPlan, but it became way too complex, so we extracted it here.

func ExecutePlan added in v1.13.0

func ExecutePlan(parentCtx context.Context, releaseNamespace string, plan *Plan, taskStore *kdutil.Concurrent[*statestore.TaskStore], logStore *kdutil.Concurrent[*logstore.LogStore], informerFactory *kdutil.Concurrent[*informer.InformerFactory], history release.Historier, clientFactory kube.ClientFactorier, opts ExecutePlanOptions) error

Executes the given plan. It doesn't care what kind of plan it is (install, upgrade, failure plan, etc.). All the differences between these plans must be figured out earlier, e.g. in BuildPlan. This generic design must be preserved. Keep it simple: if something can be done on earlier stages, do it there.

func InstallableResourceInfoSortByMustInstallHandler added in v1.13.0

func InstallableResourceInfoSortByMustInstallHandler(r1, r2 *InstallableResourceInfo) bool

func InstallableResourceInfoSortByStageHandler added in v1.13.0

func InstallableResourceInfoSortByStageHandler(r1, r2 *InstallableResourceInfo) bool

func OperationID added in v1.13.0

func OperationID(t OperationType, version OperationVersion, iteration OperationIteration, configID string) string

func OperationIDHuman added in v1.13.0

func OperationIDHuman(t OperationType, iteration OperationIteration, configIDHuman string) string

func ResourceInstallTypeSortHandler added in v1.13.0

func ResourceInstallTypeSortHandler(type1, type2 ResourceInstallType) bool

func ValidateRemote added in v1.13.0

func ValidateRemote(releaseName, releaseNamespace string, installableResourceInfos []*InstallableResourceInfo, forceAdoption bool) error

Should only be called if cluster access is allowed.

Types

type BuildFailurePlanOptions added in v1.14.0

type BuildFailurePlanOptions struct {
	NoFinalTracking bool
}

type BuildPlanOptions added in v1.14.0

type BuildPlanOptions struct {
	NoFinalTracking bool
}

type BuildResourceInfosOptions added in v1.15.1

type BuildResourceInfosOptions struct {
	NetworkParallelism    int
	NoRemoveManualChanges bool
}

type CalculatePlannedChangesOptions added in v1.13.0

type CalculatePlannedChangesOptions struct {
	DiffContextLines       int
	ShowVerboseCRDDiffs    bool
	ShowVerboseDiffs       bool
	ShowSensitiveDiffs     bool
	ShowInsignificantDiffs bool
}

type DeletableResourceInfo added in v1.13.0

type DeletableResourceInfo struct {
	*spec.ResourceMeta

	LocalResource *resource.DeletableResource
	GetResult     *unstructured.Unstructured

	MustDelete       bool
	MustTrackAbsence bool

	Stage common.Stage
}

A data class, which stores all info to make a decision on what to do with the to-be-deleted resource in the plan.

type ExecutePlanOptions added in v1.13.0

type ExecutePlanOptions struct {
	common.TrackingOptions

	NetworkParallelism int
}

type InstallableResourceInfo added in v1.13.0

type InstallableResourceInfo struct {
	*spec.ResourceMeta

	LocalResource  *resource.InstallableResource
	GetResult      *unstructured.Unstructured
	DryApplyResult *unstructured.Unstructured
	DryApplyErr    error

	MustInstall                   ResourceInstallType
	MustDeleteOnSuccessfulInstall bool
	MustDeleteOnFailedInstall     bool
	MustTrackReadiness            bool

	Stage                          common.Stage
	StageDeleteOnSuccessfulInstall common.Stage
	Iteration                      int
}

A data class, which stores all info to make a decision on what to do with the to-be-installed resource in the plan.

type Operation added in v1.13.0

type Operation struct {
	Type      OperationType
	Version   OperationVersion
	Category  OperationCategory
	Iteration OperationIteration
	Status    OperationStatus
	Config    OperationConfig
}

Represents an operation on a resource, such as create, update, track readiness, etc. The operation ID must be unique: you can't have two operations with the same ID in the plan/graph. Operation must be easily serializable.

func (*Operation) ID added in v1.13.0

func (o *Operation) ID() string

func (*Operation) IDHuman added in v1.13.0

func (o *Operation) IDHuman() string

type OperationCategory added in v1.13.0

type OperationCategory string
const (
	// Does nothing. Used for things like  grouping.
	OperationCategoryMeta OperationCategory = "meta"
	// Operations that mutate Kubernetes resources in the cluster.
	OperationCategoryResource OperationCategory = "resource"
	// Operations that track resources in the cluster. Never mutate anything.
	OperationCategoryTrack OperationCategory = "track"
	// Operations that mutate Helm releases in the cluster.
	OperationCategoryRelease OperationCategory = "release"
)

type OperationConfig added in v1.13.0

type OperationConfig interface {
	ID() string
	IDHuman() string
}

Any config that is needed to execute the operation goes here, as long as it doesn't fit into other fields of the Operation struct. The underlying struct can have any number of fields of any kind, just make sure they are easily serializable.

type OperationConfigApply added in v1.13.0

type OperationConfigApply struct {
	ResourceSpec *spec.ResourceSpec
}

func (*OperationConfigApply) ID added in v1.13.0

func (c *OperationConfigApply) ID() string

func (*OperationConfigApply) IDHuman added in v1.13.0

func (c *OperationConfigApply) IDHuman() string

type OperationConfigCreate added in v1.13.0

type OperationConfigCreate struct {
	ResourceSpec  *spec.ResourceSpec
	ForceReplicas *int
}

func (*OperationConfigCreate) ID added in v1.13.0

func (c *OperationConfigCreate) ID() string

func (*OperationConfigCreate) IDHuman added in v1.13.0

func (c *OperationConfigCreate) IDHuman() string

type OperationConfigCreateRelease added in v1.13.0

type OperationConfigCreateRelease struct {
	Release *helmrelease.Release
}

func (*OperationConfigCreateRelease) ID added in v1.13.0

func (*OperationConfigCreateRelease) IDHuman added in v1.13.0

func (c *OperationConfigCreateRelease) IDHuman() string

type OperationConfigDelete added in v1.13.0

type OperationConfigDelete struct {
	ResourceMeta      *spec.ResourceMeta
	DeletePropagation metav1.DeletionPropagation
}

func (*OperationConfigDelete) ID added in v1.13.0

func (c *OperationConfigDelete) ID() string

func (*OperationConfigDelete) IDHuman added in v1.13.0

func (c *OperationConfigDelete) IDHuman() string

type OperationConfigDeleteRelease added in v1.13.0

type OperationConfigDeleteRelease struct {
	ReleaseName      string
	ReleaseNamespace string
	ReleaseRevision  int
}

func (*OperationConfigDeleteRelease) ID added in v1.13.0

func (*OperationConfigDeleteRelease) IDHuman added in v1.13.0

func (c *OperationConfigDeleteRelease) IDHuman() string

type OperationConfigNoop added in v1.13.0

type OperationConfigNoop struct {
	OpID string
}

func (*OperationConfigNoop) ID added in v1.13.0

func (c *OperationConfigNoop) ID() string

func (*OperationConfigNoop) IDHuman added in v1.13.0

func (c *OperationConfigNoop) IDHuman() string

type OperationConfigRecreate added in v1.13.0

type OperationConfigRecreate struct {
	ResourceSpec      *spec.ResourceSpec
	DeletePropagation metav1.DeletionPropagation
	ForceReplicas     *int
}

func (*OperationConfigRecreate) ID added in v1.13.0

func (*OperationConfigRecreate) IDHuman added in v1.13.0

func (c *OperationConfigRecreate) IDHuman() string

type OperationConfigTrackAbsence added in v1.13.0

type OperationConfigTrackAbsence struct {
	ResourceMeta *spec.ResourceMeta
}

func (*OperationConfigTrackAbsence) ID added in v1.13.0

func (*OperationConfigTrackAbsence) IDHuman added in v1.13.0

func (c *OperationConfigTrackAbsence) IDHuman() string

type OperationConfigTrackPresence added in v1.13.0

type OperationConfigTrackPresence struct {
	ResourceMeta *spec.ResourceMeta
}

func (*OperationConfigTrackPresence) ID added in v1.13.0

func (*OperationConfigTrackPresence) IDHuman added in v1.13.0

func (c *OperationConfigTrackPresence) IDHuman() string

type OperationConfigTrackReadiness added in v1.13.0

type OperationConfigTrackReadiness struct {
	ResourceMeta *spec.ResourceMeta

	FailMode                                 multitrack.FailMode
	FailuresAllowed                          int
	IgnoreLogs                               bool
	IgnoreLogsForContainers                  []string
	IgnoreLogsByRegex                        *regexp.Regexp
	IgnoreLogsByRegexForContainers           map[string]*regexp.Regexp
	IgnoreReadinessProbeFailsByContainerName map[string]time.Duration
	NoActivityTimeout                        time.Duration
	SaveEvents                               bool
	SaveLogsByRegex                          *regexp.Regexp
	SaveLogsByRegexForContainers             map[string]*regexp.Regexp
	SaveLogsOnlyForContainers                []string
	SaveLogsOnlyForNumberOfReplicas          int
}

func (*OperationConfigTrackReadiness) ID added in v1.13.0

func (*OperationConfigTrackReadiness) IDHuman added in v1.13.0

type OperationConfigUpdate added in v1.13.0

type OperationConfigUpdate struct {
	ResourceSpec *spec.ResourceSpec
}

func (*OperationConfigUpdate) ID added in v1.13.0

func (c *OperationConfigUpdate) ID() string

func (*OperationConfigUpdate) IDHuman added in v1.13.0

func (c *OperationConfigUpdate) IDHuman() string

type OperationConfigUpdateRelease added in v1.13.0

type OperationConfigUpdateRelease struct {
	Release *helmrelease.Release
}

func (*OperationConfigUpdateRelease) ID added in v1.13.0

func (*OperationConfigUpdateRelease) IDHuman added in v1.13.0

func (c *OperationConfigUpdateRelease) IDHuman() string

type OperationIteration added in v1.13.0

type OperationIteration int

Helps to avoid operation ID collisions. Since you can't have two operations with the same ID in the graph, you can increment the iteration to get a new unique ID for the operation. The higher the iteration, the later in the plan/graph the operation should appear.

type OperationStatus added in v1.13.0

type OperationStatus string
const (
	OperationStatusUnknown   OperationStatus = ""
	OperationStatusPending   OperationStatus = "pending"
	OperationStatusCompleted OperationStatus = "completed"
	OperationStatusFailed    OperationStatus = "failed"
)

type OperationType added in v1.13.0

type OperationType string
const (
	OperationTypeApply          OperationType = "apply"
	OperationTypeCreate         OperationType = "create"
	OperationTypeCreateRelease  OperationType = "create-release"
	OperationTypeDelete         OperationType = "delete"
	OperationTypeDeleteRelease  OperationType = "delete-release"
	OperationTypeNoop           OperationType = "noop"
	OperationTypeRecreate       OperationType = "recreate"
	OperationTypeTrackAbsence   OperationType = "track-absence"
	OperationTypeTrackPresence  OperationType = "track-presence"
	OperationTypeTrackReadiness OperationType = "track-readiness"
	OperationTypeUpdate         OperationType = "update"
	OperationTypeUpdateRelease  OperationType = "update-release"
)

type OperationVersion added in v1.13.0

type OperationVersion int

Used to handle breaking changes in the Operation struct.

const (
	OperationVersionApply          OperationVersion = 1
	OperationVersionCreate         OperationVersion = 1
	OperationVersionCreateRelease  OperationVersion = 1
	OperationVersionDelete         OperationVersion = 1
	OperationVersionDeleteRelease  OperationVersion = 1
	OperationVersionNoop           OperationVersion = 1
	OperationVersionRecreate       OperationVersion = 1
	OperationVersionTrackAbsence   OperationVersion = 1
	OperationVersionTrackPresence  OperationVersion = 1
	OperationVersionTrackReadiness OperationVersion = 1
	OperationVersionUpdate         OperationVersion = 1
	OperationVersionUpdateRelease  OperationVersion = 1
)

type Plan

type Plan struct {
	Graph graph.Graph[string, *Operation]
}

Wrapper over dominikbraun/graph to make it easier to use as a plan/graph of operations.

func BuildFailurePlan added in v1.13.0

func BuildFailurePlan(failedPlan *Plan, installableInfos []*InstallableResourceInfo, releaseInfos []*ReleaseInfo, opts BuildFailurePlanOptions) (*Plan, error)

When the main plan fails, the failure plan must be built and executed.

func BuildPlan added in v1.13.0

func BuildPlan(installableInfos []*InstallableResourceInfo, deletableInfos []*DeletableResourceInfo, releaseInfos []*ReleaseInfo, opts BuildPlanOptions) (*Plan, error)

Builds any kind of a plan, be it for install, upgrade, rollback or uninstall. The only exception is a failure plan (see BuildFailurePlan), because it's way too different. Any differences between different kinds of plans must be figured out earlier, e.g. at BuildResourceInfos level. This generic design must be preserved. Keep it simple: if something can be done on earlier stages, do it there.

func NewPlan

func NewPlan() *Plan

func (*Plan) AddOperationChain added in v1.13.0

func (p *Plan) AddOperationChain() *planChainBuilder

func (*Plan) Connect added in v1.13.0

func (p *Plan) Connect(fromID, toID string) error

func (*Plan) Operation

func (p *Plan) Operation(id string) (op *Operation, found bool)

func (*Plan) Operations

func (p *Plan) Operations() []*Operation

func (*Plan) Optimize

func (p *Plan) Optimize(noFinalTracking bool) error

func (*Plan) SquashOperation added in v1.14.0

func (p *Plan) SquashOperation(op *Operation)

func (*Plan) ToDOT added in v1.13.0

func (p *Plan) ToDOT() ([]byte, error)

type ReleaseInfo added in v1.13.0

type ReleaseInfo struct {
	Release *helmrelease.Release

	Must                   ReleaseType
	MustFailOnFailedDeploy bool
}

Data class, which stores all info to make a decision on what to do with the release revision in the plan.

func BuildReleaseInfos added in v1.13.0

func BuildReleaseInfos(ctx context.Context, deployType common.DeployType, prevReleases []*helmrelease.Release, newRel *helmrelease.Release) ([]*ReleaseInfo, error)

Build ReleaseInfos from Releases that we got from the cluster. Here we actually decide on what to do with each release revision. Compute here as much as you can: Release shouldn't be used for decision making (its just a JSON representation of a Helm release) and BuildPlan is complex enough already.

type ReleaseType added in v1.13.0

type ReleaseType string
const (
	// No-op
	ReleaseTypeNone ReleaseType = "none"
	// First release revision is to be installed
	ReleaseTypeInstall ReleaseType = "install"
	// New release revision is to be installed as an upgrade over the previous one
	ReleaseTypeUpgrade ReleaseType = "upgrade"
	// New release revision is to be installed, based on one of the previous revisions
	ReleaseTypeRollback ReleaseType = "rollback"
	// One of the previous revisions is to be superseded by a successful release
	ReleaseTypeSupersede ReleaseType = "supersede"
	// Release is to be uninstalled as a whole, with its resources
	ReleaseTypeUninstall ReleaseType = "uninstall"
	// Release revision is to be dropped/deleted (its resources are untouched)
	ReleaseTypeDelete ReleaseType = "delete"
)

type ResourceChange added in v1.13.0

type ResourceChange struct {
	// Any operations on the resource after the initial one.
	ExtraOperations []string
	// The reason for the change.
	Reason       string
	ResourceMeta *spec.ResourceMeta
	Type         string
	TypeStyle    color.Style
	Udiff        string
}

func CalculatePlannedChanges

func CalculatePlannedChanges(installableInfos []*InstallableResourceInfo, deletableInfos []*DeletableResourceInfo, opts CalculatePlannedChangesOptions) ([]*ResourceChange, error)

Calculate planned changes for informational purposes. Doesn't need the full plan, just having Installable/DeletableResourceInfos is enough. Returns the structured result and shouldn't decide on how to present this data.

type ResourceInstallType added in v1.13.0

type ResourceInstallType string
const (
	ResourceInstallTypeNone     ResourceInstallType = "none"
	ResourceInstallTypeCreate   ResourceInstallType = "create"
	ResourceInstallTypeRecreate ResourceInstallType = "recreate"
	ResourceInstallTypeUpdate   ResourceInstallType = "update"
	// When we can't figure out whether to create or update the resource, we blindly apply it
	ResourceInstallTypeApply ResourceInstallType = "apply"
)

Jump to

Keyboard shortcuts

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