Documentation
¶
Index ¶
- func BuildServicesList(stored []kcmv1.ServiceWithValues, filtered []kcmv1.ServiceWithValues, ...) []kcmv1.ServiceWithValues
- func FilterServiceDependencies(ctx context.Context, c client.Client, systemNamespace string, ...) ([]kcmv1.Service, error)
- func GetServiceSetWithOperation(ctx context.Context, c client.Client, operationReq OperationRequisites) (*kcmv1.ServiceSet, kcmv1.ServiceSetOperation, error)
- func ObjectKey(systemNamespace string, cd *kcmv1.ClusterDeployment, ...) client.ObjectKey
- func ResolveServiceVersions(ctx context.Context, c client.Client, namespace string, services any) error
- func ResolveServicesToApply(ctx context.Context, c client.Client, systemNamespace string, ...) ([]kcmv1.ServiceWithValues, error)
- func ServiceKey(namespace, name string) client.ObjectKey
- func ServicesToDeploy(upgradePaths []kcmv1.ServiceUpgradePaths, filteredServices []kcmv1.Service, ...) []kcmv1.ServiceWithValues
- func ServicesUpgradePaths(ctx context.Context, c client.Client, services []kcmv1.Service, ...) ([]kcmv1.ServiceUpgradePaths, error)
- func ServicesWithDesiredChains(desiredServices []kcmv1.Service, deployedServices []kcmv1.ServiceWithValues) []kcmv1.Service
- func StateManagementProviderConfigFromServiceSpec(serviceSpec kcmv1.ServiceSpec) (kcmv1.StateManagementProviderConfig, error)
- type Builder
- type OperationRequisites
- type Processor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildServicesList ¶ added in v1.9.0
func BuildServicesList( stored []kcmv1.ServiceWithValues, filtered []kcmv1.ServiceWithValues, desired []kcmv1.Service, ) []kcmv1.ServiceWithValues
BuildServicesList produces the final list of services for the ServiceSet spec by:
- Including all services from filtered (with their computed target versions).
- Preserving services from stored that are still present in desired but were not included in filtered (locked — dependencies not yet satisfied).
- Dropping services from stored that are no longer present in desired (explicitly removed by the user).
func FilterServiceDependencies ¶ added in v1.4.0
func FilterServiceDependencies( ctx context.Context, c client.Client, systemNamespace string, mcs *kcmv1.MultiClusterService, cd *kcmv1.ClusterDeployment, desiredServices []kcmv1.Service, ) ([]kcmv1.Service, error)
FilterServiceDependencies filters out & returns the services from desired services that are NOT dependent on any other service. It does so by fetching all ServiceSets associated with provided cd & mcs from cd's namespace or from system namespace if cd is nil.
A service is eligible (its count reaches zero) only when every service it directly or transitively depends on has a Deployed status in the fetched ServiceSets. Services in a non-Deployed state (Failed, Provisioning, etc.) are NOT treated as deployed, even if their dependents are already in the ServiceSet spec. This guarantees that a failing dependency keeps its dependents locked at their stored version (via BuildServicesList) rather than allowing them to be upgraded or mutated.
NOTE: Every service referenced in a DependsOn field must also appear in the desired services list; referencing an absent service is an error.
NOTE: This function works under the assumption that there will always be just 1 ServiceSet for every unique combination of CD & MCS.
NOTE: This function depends solely on the ServiceSet to fetch the latest state of the services. Therefore, it works under the assumption that some other mechanism like the poller for the Sveltos adapter will update the ServiceSet by fetching the latest state from the specific state manager's objects.
func GetServiceSetWithOperation ¶
func GetServiceSetWithOperation( ctx context.Context, c client.Client, operationReq OperationRequisites, ) (*kcmv1.ServiceSet, kcmv1.ServiceSetOperation, error)
GetServiceSetWithOperation fetches or initialises the ServiceSet identified by operationReq.ObjectKey, runs the full services resolution pipeline, and returns the resulting ServiceSet together with the operation that should be performed on it.
Pipeline overview ¶
The function resolves which services to include in the ServiceSet spec through three stages:
Dependency filtering (FilterServiceDependencies): services whose dependencies are not yet fully deployed are excluded from the "eligible" set. Only services with all dependencies in kcmv1.ServiceStateDeployed state are eligible to be applied or upgraded in this reconcile cycle.
Version resolution (ServicesToDeploy): for each eligible service the correct target version is computed, respecting any in-flight upgrades already present in the stored spec and honouring step-wise upgrade paths defined in kcmv1.ServiceTemplateChain.
List merging (BuildServicesList): the final spec is assembled from the eligible services (with their computed versions) plus any stored services that are still desired but were excluded from the eligible set (locked at their current version). Services no longer present in the desired list are dropped.
Corner cases ¶
Unsatisfied dependency — if service B depends on A and A has not reached kcmv1.ServiceStateDeployed yet (e.g. it is still Provisioning), B is excluded from the eligible set. B is preserved in the ServiceSet spec at its current stored version (locked) and will become eligible once A is deployed.
Failing dependency — if A is in a Failed state, B remains locked for as long as A stays non-Deployed. Critically, B is never upgraded or mutated while its dependency is failing; it is carried over from the stored spec verbatim. This prevents accidental mutation of a running service because one of its upstream dependencies entered a degraded state.
Removed service with dependents — if a service is removed from the desired list while other desired services still reference it via DependsOn, the function returns an error. The controller will not reconcile until the spec is consistent (either the removed service is added back or all DependsOn references to it are cleaned up). This prevents accidental cascade-deletion of a dependent service stack.
New service added as dependency of an existing deployed service — the existing service gains an unsatisfied dependency and is locked until the newly-added dependency reaches Deployed. The existing service continues to run at its current version on the managed cluster.
In-flight upgrade — if the stored spec version for a service differs from its deployed version, the upgrade is already in progress. The service is emitted with its current in-flight version (mutable fields such as values are merged from the desired spec) and is not advanced to the next upgrade step until the in-flight version is fully deployed.
No-op — if the resolved spec is identical to the existing ServiceSet spec, kcmv1.ServiceSetOperationNone is returned and no write is performed.
New ServiceSet — if no ServiceSet exists at operationReq.ObjectKey, a new one is initialised and kcmv1.ServiceSetOperationCreate is returned.
func ObjectKey ¶ added in v1.6.0
func ObjectKey(systemNamespace string, cd *kcmv1.ClusterDeployment, mcs *kcmv1.MultiClusterService) client.ObjectKey
ObjectKey generates a unique key for a ServiceSet given the input and returns it.
func ResolveServiceVersions ¶ added in v1.6.0
func ResolveServicesToApply ¶ added in v1.9.0
func ResolveServicesToApply( ctx context.Context, c client.Client, systemNamespace string, mcs *kcmv1.MultiClusterService, cd *kcmv1.ClusterDeployment, desiredServices []kcmv1.Service, serviceSet *kcmv1.ServiceSet, ) ([]kcmv1.ServiceWithValues, error)
ResolveServicesToApply resolves which services from desiredServices are eligible to be applied now (all dependencies satisfied) and computes the correct target version for each, taking into account upgrade paths and any in-flight upgrades already present in the ServiceSet spec.
func ServiceKey ¶ added in v1.4.0
ServiceKey returns a unique identifier for a service within github.com/K0rdent/kcm/api/v1beta1.ServiceSpec.
func ServicesToDeploy ¶
func ServicesToDeploy( upgradePaths []kcmv1.ServiceUpgradePaths, filteredServices []kcmv1.Service, serviceSet *kcmv1.ServiceSet, ) []kcmv1.ServiceWithValues
ServicesToDeploy computes the target ServiceWithValues for each service in filteredServices (i.e. services whose dependencies are already satisfied), taking into account in-flight upgrades and upgrade-path constraints. Services not in filteredServices are handled separately by BuildServicesList.
func ServicesUpgradePaths ¶
func ServicesWithDesiredChains ¶
func ServicesWithDesiredChains( desiredServices []kcmv1.Service, deployedServices []kcmv1.ServiceWithValues, ) []kcmv1.Service
ServicesWithDesiredChains takes out the templateChain from desiredServices for each service and plugs it into matching service in deployedServices and returns the new list of services.
func StateManagementProviderConfigFromServiceSpec ¶ added in v1.6.0
func StateManagementProviderConfigFromServiceSpec(serviceSpec kcmv1.ServiceSpec) (kcmv1.StateManagementProviderConfig, error)
StateManagementProviderConfigFromServiceSpec converts ServiceSpec to StateManagementProviderConfig.
Types ¶
type Builder ¶
type Builder struct {
// ServiceSet is the base ServiceSet which will be mutated as needed
ServiceSet *kcmv1.ServiceSet
// ClusterDeployment is the related ClusterDeployment
ClusterDeployment *kcmv1.ClusterDeployment
// MultiClusterService is the related MultiClusterService if any
MultiClusterService *kcmv1.MultiClusterService
// Selector is the selector used to extract labels for the ServiceSet
Selector *metav1.LabelSelector
// ServicesToDeploy is the list of services to deploy
ServicesToDeploy []kcmv1.ServiceWithValues
}
Builder is a builder for ServiceSet objects. It defines all necessary parameters and dependencies to either create or update a ServiceSet object.
func NewBuilder ¶
func NewBuilder(clusterDeployment *kcmv1.ClusterDeployment, serviceSet *kcmv1.ServiceSet, selector *metav1.LabelSelector) *Builder
NewBuilder returns a new Builder with mandatory parameters set.
func (*Builder) Build ¶
func (b *Builder) Build() (*kcmv1.ServiceSet, error)
Build constructs and returns a ServiceSet object based on the builder's parameters or returns an error if invalid.
func (*Builder) WithMultiClusterService ¶
func (b *Builder) WithMultiClusterService(multiClusterService *kcmv1.MultiClusterService) *Builder
WithMultiClusterService sets the related MultiClusterService.
func (*Builder) WithServicesToDeploy ¶
func (b *Builder) WithServicesToDeploy(servicesToDeploy []kcmv1.ServiceWithValues) *Builder
WithServicesToDeploy sets the list of services to deploy.
type OperationRequisites ¶
type OperationRequisites struct {
ObjectKey client.ObjectKey
MCS *kcmv1.MultiClusterService
CD *kcmv1.ClusterDeployment
SystemNamespace string
}
type Processor ¶
type Processor struct {
client.Client
ProviderSpec kcmv1.StateManagementProviderConfig
Services []kcmv1.Service
}
Processor is used to process ServiceSet objects.
func NewProcessor ¶
NewProcessor creates a new Processor with the given client.
func (*Processor) CreateOrUpdateServiceSet ¶
func (p *Processor) CreateOrUpdateServiceSet( ctx context.Context, op kcmv1.ServiceSetOperation, serviceSet *kcmv1.ServiceSet, ) error
CreateOrUpdateServiceSet manages the lifecycle of a ServiceSet based on the specified operation (create, update, or no-op). It attempts to create or update the given ServiceSet object and handles errors such as conflicts or already exists. Returns a requeue flag to indicate if the parent object should be requeued and an error if the operation fails.