ownerreference

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ownerreference contains logic to backup and restore owner references of k8s.cloudogu.com objects and its immediate children.

Basically, this logic only exists because the k8s-dogu-operator fails to properly reconcile owner references to its resources after a restore action. This package and its logic can be dropped if the k8s-dogu-operator supports proper owner reference reconciliation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Recreator

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

Recreator is responsible for creating and restoring backups of owner references referred in the metadata of a resource.

It leverages dynamic and discovery clients to interact with the Kubernetes API in a flexible and version-aware manner, enabling operations across different resource types and API groups.

Fields:

  • namespace: The Kubernetes namespace in which the Recreator operates.
  • dynamicClient: A dynamic client used to interact with arbitrary Kubernetes resources.
  • discoveryClient: A discovery interface used to fetch API resource information from the server.
  • groupVersionParser: A function used to parse and handle GroupVersion strings for resources.

func NewRecreator

func NewRecreator(cfg *rest.Config, namespace string) (*Recreator, error)

NewRecreator creates a new instance of Recreator using the provided Kubernetes REST configuration and namespace. It initializes a dynamic client and a discovery client for interacting with the Kubernetes API.

Parameters:

  • cfg: A pointer to a rest.Config that contains the configuration required to connect to the Kubernetes API.
  • namespace: The Kubernetes namespace in which the Recreator will operate.

Returns:

  • A pointer to the initialized Recreator instance.
  • An error if either the dynamic client or discovery client cannot be created.

func (Recreator) BackupOwnerReferences

func (r Recreator) BackupOwnerReferences(ctx context.Context) error

BackupOwnerReferences scans all resources in the configured namespace to identify which ones are referenced as owners by other resources and backs up these relationships into resource annotations.

This method performs the following steps:

  1. Fetches all Cloudogu CRD-based parent resources and a mapping of child resources referencing them via OwnerReferences.
  2. Starts a pool of worker goroutines to inspect each parent resource and determine if it's referenced as an owner.
  3. Collects both parent and child resources that need backup, annotates them with their UID or OwnerReferences
  4. Updates the annotated resources in the Kubernetes cluster.

The backup enables later restoration of the ownership structure between resources.

func (Recreator) RestoreOwnerReferences

func (r Recreator) RestoreOwnerReferences(ctx context.Context) error

RestoreOwnerReferences restores the OwnerReferences metadata on Kubernetes resources within the configured namespace using backup annotations previously stored by the BackupOwnerReferences method.

This method performs the following steps:

  1. Fetches all relevant parent and child resources in the namespace that contain backup annotations.
  2. Reconstructs the original OwnerReferences for each child resource based on the annotation data and appends them to a list for update.
  3. Cleans up parent resource annotations (e.g., backup UIDs) to restore them to their pre-backup state.
  4. Applies the changes to the cluster by updating each resource.

Jump to

Keyboard shortcuts

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