Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions api/v1alpha1/dataprotectionapplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,16 @@ type ResticConfig struct {
NodeAgentCommonFields `json:",inline"`
}

type RepositoryMaintenanceConfig struct {
// LoadAffinity is the config for data path load affinity.
// +optional
LoadAffinityConfig []*LoadAffinity `json:"loadAffinity,omitempty"`

// PodResources is the config for the CPU and memory resources setting.
// +optional
PodResources *kube.PodResources `json:"podResources,omitempty"`
}

// ApplicationConfig defines the configuration for the Data Protection Application
type ApplicationConfig struct {
Velero *VeleroConfig `json:"velero,omitempty"`
Expand All @@ -498,6 +508,15 @@ type ApplicationConfig struct {
// NodeAgent is needed to allow selection between kopia or restic
// +optional
NodeAgent *NodeAgentConfig `json:"nodeAgent,omitempty"`

// RepositoryMaintenance maps a BackupRepository identifier to its configuration.
// Keys can be:
// - "global" : Applies to all repositories without specific config.
// - "<namespace>" : The namespace of the BackupRepository.
// - "<repository name>" : The specific BackupRepository name referencing the BSL.
// - "<repository type>" : Either "kopia" or "restic".
// +optional
RepositoryMaintenance map[string]RepositoryMaintenanceConfig `json:"repositoryMaintenance,omitempty"`
}

// CloudStorageLocation defines BackupStorageLocation using bucket referenced by CloudStorage CR.
Expand Down
38 changes: 38 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions bundle/manifests/oadp.openshift.io_dataprotectionapplications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,83 @@ spec:
required:
- uploaderType
type: object
repositoryMaintenance:
additionalProperties:
properties:
loadAffinity:
description: LoadAffinity is the config for data path load affinity.
items:
description: |-
LoadAffinity is the config for data path load affinity.
Used by the Node-Agent, that needs to match the DataMover and the RepositoryMaintenance pods.
properties:
nodeSelector:
description: NodeSelector specifies the label selector to match nodes
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements. The requirements are ANDed.
items:
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector applies to.
type: string
operator:
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
type: object
type: array
podResources:
description: PodResources is the config for the CPU and memory resources setting.
properties:
cpuLimit:
type: string
cpuRequest:
type: string
memoryLimit:
type: string
memoryRequest:
type: string
type: object
type: object
description: |-
RepositoryMaintenance maps a BackupRepository identifier to its configuration.
Keys can be:
- "global" : Applies to all repositories without specific config.
- "<namespace>" : The namespace of the BackupRepository.
- "<repository name>" : The specific BackupRepository name referencing the BSL.
- "<repository type>" : Either "kopia" or "restic".
type: object
restic:
description: |-
(do not use warning) restic field is for backwards compatibility and
Expand Down
77 changes: 77 additions & 0 deletions config/crd/bases/oadp.openshift.io_dataprotectionapplications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,83 @@ spec:
required:
- uploaderType
type: object
repositoryMaintenance:
additionalProperties:
properties:
loadAffinity:
description: LoadAffinity is the config for data path load affinity.
items:
description: |-
LoadAffinity is the config for data path load affinity.
Used by the Node-Agent, that needs to match the DataMover and the RepositoryMaintenance pods.
properties:
nodeSelector:
description: NodeSelector specifies the label selector to match nodes
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements. The requirements are ANDed.
items:
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector applies to.
type: string
operator:
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
type: object
type: array
podResources:
description: PodResources is the config for the CPU and memory resources setting.
properties:
cpuLimit:
type: string
cpuRequest:
type: string
memoryLimit:
type: string
memoryRequest:
type: string
type: object
type: object
description: |-
RepositoryMaintenance maps a BackupRepository identifier to its configuration.
Keys can be:
- "global" : Applies to all repositories without specific config.
- "<namespace>" : The namespace of the BackupRepository.
- "<repository name>" : The specific BackupRepository name referencing the BSL.
- "<repository type>" : Either "kopia" or "restic".
type: object
restic:
description: |-
(do not use warning) restic field is for backwards compatibility and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (r *DataProtectionApplicationReconciler) Reconcile(ctx context.Context, req
r.ReconcileVeleroDeployment,
r.ReconcileNodeAgentConfigMap,
r.ReconcileBackupRepositoryConfigMap,
r.ReconcileRepositoryMaintenanceConfigMap,
r.ReconcileNodeAgentDaemonset,
r.ReconcileVeleroMetricsSVC,
r.ReconcileNonAdminController,
Expand Down
106 changes: 106 additions & 0 deletions internal/controller/repository_maintenance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package controller

import (
"context"
"encoding/json"
"fmt"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1"
"github.com/openshift/oadp-operator/pkg/common"
)

func isRepositoryMaintenanceCmRequired(config *oadpv1alpha1.ApplicationConfig) bool {
return config != nil && config.RepositoryMaintenance != nil && len(config.RepositoryMaintenance) > 0
}

// updateRepositoryMaintenanceCM handles the creation or update of the RepositoryMaintenance ConfigMap with all required data.
func (r *DataProtectionApplicationReconciler) updateRepositoryMaintenanceCM(cm *corev1.ConfigMap) error {
// Set the owner reference to ensure the ConfigMap is managed by the DPA
if err := controllerutil.SetControllerReference(r.dpa, cm, r.Scheme); err != nil {
return fmt.Errorf("failed to set controller reference: %w", err)
}

// Convert NodeAgentConfigMapSettings to a generic map
configRepositoryMaintenanceJSON, err := json.Marshal(r.dpa.Spec.Configuration.RepositoryMaintenance)
if err != nil {
return fmt.Errorf("failed to serialize repository maintenance config: %w", err)
}

cm.Name = common.RepoMaintConfigMapPrefix + r.dpa.Name
cm.Namespace = r.NamespacedName.Namespace
cm.Labels = map[string]string{
"app.kubernetes.io/instance": r.dpa.Name,
"app.kubernetes.io/managed-by": common.OADPOperator,
"app.kubernetes.io/component": "repository-maintenance-config",
oadpv1alpha1.OadpOperatorLabel: "True",
}

if cm.Data == nil {
cm.Data = make(map[string]string)
}
cm.Data["repository-maintenance-config"] = string(configRepositoryMaintenanceJSON)

return nil
}

// GetRepositoryMaintenanceConfigMapName returns the NamespacedName of the RepositoryMaintenance ConfigMap
func (r *DataProtectionApplicationReconciler) GetRepositoryMaintenanceConfigMapName() types.NamespacedName {
return types.NamespacedName{
Name: common.RepoMaintConfigMapPrefix + r.dpa.Name,
Namespace: r.NamespacedName.Namespace,
}
}

// ReconcileRepositoryMaintenanceConfigMap handles creation, update, and deletion of the RepositoryMaintenance ConfigMap.
func (r *DataProtectionApplicationReconciler) ReconcileRepositoryMaintenanceConfigMap(log logr.Logger) (bool, error) {
dpa := r.dpa
cmName := r.GetRepositoryMaintenanceConfigMapName()
configMap := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: cmName.Name,
Namespace: cmName.Namespace,
},
}

// Delete CM if it is not required
if !isRepositoryMaintenanceCmRequired(dpa.Spec.Configuration) {
err := r.Get(r.Context, cmName, &configMap)
if err != nil && !errors.IsNotFound(err) {
return false, err
}
if errors.IsNotFound(err) {
return true, nil
}
deleteContext := context.Background()
if err := r.Delete(deleteContext, &configMap); err != nil {
if errors.IsNotFound(err) {
return true, nil
}
return false, err
}
r.EventRecorder.Event(&configMap, corev1.EventTypeNormal, "DeletedRepositoryMaintenanceConfigMap", "RepositoryMaintenance config map deleted")
return true, nil
}

op, err := controllerutil.CreateOrPatch(r.Context, r.Client, &configMap, func() error {
return r.updateRepositoryMaintenanceCM(&configMap)
})
if err != nil {
return false, fmt.Errorf("failed to create or patch config map: %w", err)
}

if op == controllerutil.OperationResultCreated {
r.EventRecorder.Event(&configMap, corev1.EventTypeNormal, "CreatedRepositoryMaintenanceConfigMap", "RepositoryMaintenance config map created")
} else if op == controllerutil.OperationResultUpdated {
r.EventRecorder.Event(&configMap, corev1.EventTypeNormal, "UpdatedRepositoryMaintenanceConfigMap", "RepositoryMaintenance config map updated")
}

return true, nil
}
Loading