sync

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package sync is used to sync the manifests defined in the GitSync object into the local cluster.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CascadeDeletion

func CascadeDeletion(ctx context.Context, k8sClient client.Client, cache LiveStateCache, gitSync *v1alpha1.GitSync) error

CascadeDeletion performs cascading deletion of live managed objects using GitSync. It utilizes the provided context, Kubernetes client, cache, and GitSync configuration. Returns an error if the deletion process encounters any issues.

func GetLiveManagedObjects

func GetLiveManagedObjects(cache LiveStateCache, gitSync *v1alpha1.GitSync) (map[kube.ResourceKey]*unstructured.Unstructured, error)

GetLiveManagedObjects retrieves live managed objects from the provided cache for the given GitSync configuration. It returns a map of Kubernetes resource keys to unstructured objects and an error if any.

func KeyOfGitSync

func KeyOfGitSync(gitSync *v1alpha1.GitSync) string

KeyOfGitSync returns the unique key of a gitsync

func NewIgnoreNormalizer

func NewIgnoreNormalizer(overrides map[string]ResourceOverride) (diff.Normalizer, error)

NewIgnoreNormalizer creates diff normalizer which removes ignored fields according to given application spec and resource overrides

func NewNoopNormalizer

func NewNoopNormalizer() diff.Normalizer

NewNoopNormalizer returns normalizer that does not apply any resource modifications

func ProcessGitSyncDeletion

func ProcessGitSyncDeletion(ctx context.Context, gitSync *v1alpha1.GitSync, s *Syncer) error

func StateDiffs

func StateDiffs(
	configs, lives []*unstructured.Unstructured,
	overrides map[string]ResourceOverride,
	diffOpts []diff.Option) (*diff.DiffResultList, error)

StateDiffs will apply all required normalizations and calculate the diffs between the live and the config/desired states.

Types

type LiveStateCache

type LiveStateCache interface {
	// GetClusterCache returns synced cluster cache
	GetClusterCache() (clustercache.ClusterCache, error)
	// GetManagedLiveObjs returns state of live nodes which correspond to target nodes of specified gitsync.
	GetManagedLiveObjs(gitsync *v1alpha1.GitSync, targetObjs []*unstructured.Unstructured) (map[kube.ResourceKey]*unstructured.Unstructured, error)
	// Init must be executed before cache can be used
	Init(numaLogger *logger.NumaLogger) error
	// PopulateResourceInfo is called by the cache to update ResourceInfo struct for a managed resource
	PopulateResourceInfo(un *unstructured.Unstructured, isRoot bool) (interface{}, bool)
}

LiveStateCache is a cluster caching that stores resource references and ownership references. It also stores custom metadata for resources managed by GitSyncs. It always ensures the cache is up-to-date before returning the resources.

func NewLiveStateCache

func NewLiveStateCache(
	clusterCacheConfig *rest.Config,
) LiveStateCache

type NoopNormalizer

type NoopNormalizer struct {
}

func (*NoopNormalizer) Normalize

func (n *NoopNormalizer) Normalize(un *unstructured.Unstructured) error

type ObjectUpdatedHandler

type ObjectUpdatedHandler = func(managedByGitSync map[string]bool, ref v1.ObjectReference)

type Option

type Option func(*options)

func WithTaskInterval

func WithTaskInterval(n int) Option

WithTaskInterval sets the interval of picking up a task from the work queue.

func WithWorkers

func WithWorkers(n int) Option

WithWorkers sets the number of workers working on autoscaling.

type OverrideIgnoreDiff

type OverrideIgnoreDiff struct {
	// JSONPointers is a JSON path list following the format defined in RFC4627 (https://datatracker.ietf.org/doc/html/rfc6902#section-3)
	JSONPointers []string
}

OverrideIgnoreDiff contains configurations about how fields should be ignored during diffs between the desired state and live state

type ResourceFilter

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

ResourceFilter filter resources based on allowed Resource Types

func (*ResourceFilter) IsExcludedResource

func (n *ResourceFilter) IsExcludedResource(group, kind, _ string) bool

type ResourceIgnoreDifferences

type ResourceIgnoreDifferences struct {
	Group        string
	Kind         string
	Name         string
	Namespace    string
	JSONPointers []string
}

ResourceIgnoreDifferences contains resource filter and list of json paths which should be ignored during comparison with live state.

type ResourceInfo

type ResourceInfo struct {
	GitSyncName string

	Health *health.HealthStatus
	// contains filtered or unexported fields
}

type ResourceOverride

type ResourceOverride struct {
	IgnoreDifferences OverrideIgnoreDiff
}

ResourceOverride holds configuration to customize resource diffing and health assessment

type ResourceType

type ResourceType struct {
	Group string
	Kind  string
}

type Syncer

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

func NewSyncer

func NewSyncer(
	client client.Client,
	config *rest.Config,
	rawConfig *rest.Config,
	kubectl kubeUtil.Kubectl,
	opts ...Option,
) *Syncer

NewSyncer returns a Synchronizer instance.

func (*Syncer) Contains

func (s *Syncer) Contains(key string) bool

Contains returns if the synchronizer contains the key (namespace/name).

func (*Syncer) Length

func (s *Syncer) Length() int

Length returns how many GitSync objects are watched

func (*Syncer) Start

func (s *Syncer) Start(ctx context.Context) error

Start function starts the synchronizer worker group. Each worker keeps picking up tasks (which contains GitSync keys) to sync the resources.

func (*Syncer) StartWatching

func (s *Syncer) StartWatching(key string)

StartWatching put a key (namespace/name) into the synchronizer

func (*Syncer) StopWatching

func (s *Syncer) StopWatching(key string)

StopWatching stops watching on the key (namespace/name)

Jump to

Keyboard shortcuts

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