version

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VersionMapToClusterVersions

func VersionMapToClusterVersions(versionMap map[string]string) []fedcorev1a1.ClusterObjectVersion

Types

type VersionAdapter

type VersionAdapter interface {
	TypeName() string

	Get(
		ctx context.Context,
		client fedcorev1a1client.CoreV1alpha1Interface,
		namespace, name string,
		opts metav1.GetOptions,
	) (client.Object, error)
	List(
		ctx context.Context,
		client fedcorev1a1client.CoreV1alpha1Interface,
		namespace string,
		opts metav1.ListOptions,
	) (client.ObjectList, error)
	Create(
		ctx context.Context,
		client fedcorev1a1client.CoreV1alpha1Interface,
		obj client.Object,
		opts metav1.CreateOptions,
	) (client.Object, error)
	UpdateStatus(
		ctx context.Context,
		client fedcorev1a1client.CoreV1alpha1Interface,
		obj client.Object,
		opts metav1.UpdateOptions,
	) (client.Object, error)

	// Create a populated instance of the version type
	NewVersion(
		qualifiedName common.QualifiedName,
		ownerReference metav1.OwnerReference,
		status *fedcorev1a1.PropagatedVersionStatus,
	) client.Object

	// Type-agnostic access / mutation of the Status field of a version resource
	GetStatus(obj client.Object) *fedcorev1a1.PropagatedVersionStatus
	SetStatus(obj client.Object, status *fedcorev1a1.PropagatedVersionStatus)
}

func NewVersionAdapter

func NewVersionAdapter(namespaced bool) VersionAdapter

type VersionManager

type VersionManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

VersionManager is used by the Sync controller to record the last synced version of a FederatedObject along with the versions of the cluster objects that were created/updated in the process. This is important in preventing unnecessary update requests from being sent to member clusters in subsequent reconciles. The VersionManager persists this information in the apiserver in the form of PropagatedVersion/ClusterPropagatedVersions, see pkg/apis/types_propagatedversion.go.

In the context of the Sync controller, we identify the "version" of a FederatedObject with the hash of its template and overrides and we identify the "version" of a cluster object to be either its Generation (if available) or its ResourceVersion.

VersionManager is required because created/updated cluster objects might not match the template exactly due to various reasons such as default values, admission plugins or webhooks. Thus we have to store the version returned by the create/update request to avoid false-positives when determining if the cluster object has diverged from the template in subsequent reconciles.

func NewClusterVersionManager

func NewClusterVersionManager(
	logger klog.Logger,
	client fedcorev1a1client.CoreV1alpha1Interface,
) *VersionManager

func NewNamespacedVersionManager

func NewNamespacedVersionManager(
	logger klog.Logger,
	client fedcorev1a1client.CoreV1alpha1Interface,
	namespace string,
) *VersionManager

func (*VersionManager) Delete

func (m *VersionManager) Delete(qualifiedName common.QualifiedName)

Delete removes the named propagated version from the manager. Versions are written to the API with an owner reference to the versioned resource, and they should be removed by the garbage collector when the resource is removed.

func (*VersionManager) Get

func (m *VersionManager) Get(resource VersionedResource) (map[string]string, error)

Get retrieves a mapping of cluster names to versions for the given versioned resource. It returns an empty map if the desired object for the versioned resource is different from last recorded.

func (*VersionManager) HasSynced

func (m *VersionManager) HasSynced() bool

HasSynced indicates whether the manager's in-memory state has been synced with the api.

func (*VersionManager) Sync

func (m *VersionManager) Sync(ctx context.Context)

Sync retrieves propagated versions from the api and loads it into memory.

func (*VersionManager) Update

func (m *VersionManager) Update(
	resource VersionedResource,
	selectedClusters []string,
	versionMap map[string]string,
) error

Update ensures that the propagated version for the given versioned resource is recorded.

type VersionedResource

type VersionedResource interface {
	// FederatedName returns the qualified name of the underlying
	// FederatedObject or ClusterFederatedObject.
	FederatedName() common.QualifiedName
	// Object returns the underlying FederatedObject or ClusterFederatedObject
	// as a GenericFederatedObject.
	Object() fedcorev1a1.GenericFederatedObject
	// TemplateVersion returns the resource's current template version.
	TemplateVersion() (string, error)
	// OverrideVersion returns the resource's current override version.
	OverrideVersion() (string, error)
	// FederatedGVK returns the GroupVersionKind of the underlying
	// FederatedObject or ClusterFederatedObject.
	FederatedGVK() schema.GroupVersionKind
}

VersionedResource defines the methods a federated resource must implement to allow versions to be tracked by the VersionManager.

Jump to

Keyboard shortcuts

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