Skip to content

Commit

Permalink
fix: Remove restic config from master branch
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 committed Jan 21, 2025
1 parent 338e8d5 commit cbd019d
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 188 deletions.
8 changes: 2 additions & 6 deletions api/v1alpha1/dataprotectionapplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,8 @@ type ResticConfig struct {
// ApplicationConfig defines the configuration for the Data Protection Application
type ApplicationConfig struct {
Velero *VeleroConfig `json:"velero,omitempty"`
// (deprecation warning) ResticConfig is the configuration for restic DaemonSet.
// restic is for backwards compatibility and is replaced by the nodeAgent
// restic will be removed in the future
// +kubebuilder:deprecatedversion:warning=1.3
// (do not use warning) restic field is for backwards compatibility and
// will be removed in the future. Use nodeAgent field instead
// +optional
Restic *ResticConfig `json:"restic,omitempty"`

Expand Down Expand Up @@ -675,8 +673,6 @@ func (dpa *DataProtectionApplication) AutoCorrect() {
if dpa.Spec.Configuration != nil {
if dpa.Spec.Configuration.NodeAgent != nil && len(dpa.Spec.Configuration.NodeAgent.Timeout) > 0 {
fsBackupTimeout = dpa.Spec.Configuration.NodeAgent.Timeout
} else if dpa.Spec.Configuration.Restic != nil && len(dpa.Spec.Configuration.Restic.Timeout) > 0 {
fsBackupTimeout = dpa.Spec.Configuration.Restic.Timeout
}
}
if pvOperationTimeout, err := time.ParseDuration(fsBackupTimeout); err == nil && dpa.Spec.Configuration.Velero.Args.PodVolumeOperationTimeout == nil {
Expand Down
2 changes: 1 addition & 1 deletion bundle/manifests/oadp-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ metadata:
"configuration": {
"nodeAgent": {
"enable": true,
"uploaderType": "restic"
"uploaderType": "kopia"
},
"velero": {
"defaultPlugins": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,8 @@ spec:
type: object
restic:
description: |-
(deprecation warning) ResticConfig is the configuration for restic DaemonSet.
restic is for backwards compatibility and is replaced by the nodeAgent
restic will be removed in the future
(do not use warning) restic field is for backwards compatibility and
will be removed in the future. Use nodeAgent field instead
properties:
enable:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,8 @@ spec:
type: object
restic:
description: |-
(deprecation warning) ResticConfig is the configuration for restic DaemonSet.
restic is for backwards compatibility and is replaced by the nodeAgent
restic will be removed in the future
(do not use warning) restic field is for backwards compatibility and
will be removed in the future. Use nodeAgent field instead
properties:
enable:
description: |-
Expand Down
1 change: 0 additions & 1 deletion config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ resources:
- downloadrequest.yaml
- podvolumebackup.yaml
- podvolumerestore.yaml
- resticrepository.yaml
- backup.yaml
- restore.yaml
- schedule.yaml
Expand Down
4 changes: 2 additions & 2 deletions config/samples/oadp_v1alpha1_dataprotectionapplication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
- kubevirt
nodeAgent:
enable: true
uploaderType: restic
uploaderType: kopia
backupLocations:
- velero:
provider: aws
Expand All @@ -26,7 +26,7 @@ spec:
name: cloud-credentials
key: cloud
snapshotLocations:
- velero:
- velero:
provider: aws
config:
region: us-west-2
Expand Down
6 changes: 0 additions & 6 deletions config/samples/resticrepository.yaml

This file was deleted.

110 changes: 21 additions & 89 deletions internal/controller/nodeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand All @@ -27,7 +26,6 @@ import (
)

const (
ResticRestoreHelperCM = "restic-restore-action-config"
FsRestoreHelperCM = "fs-restore-action-config"
HostPods = "host-pods"
HostPlugins = "host-plugins"
Expand All @@ -37,7 +35,6 @@ const (
IBMCloudPVHostPath = "/var/data/kubelet/pods"
GenericPluginsHostPath = "/var/lib/kubelet/plugins"
IBMCloudPluginsHostPath = "/var/data/kubelet/plugins"
ResticPVHostPathEnvVar = "RESTIC_PV_HOSTPATH"
FSPVHostPathEnvVar = "FS_PV_HOSTPATH"
PluginsHostPathEnvVar = "PLUGINS_HOSTPATH"
)
Expand All @@ -63,10 +60,6 @@ func getFsPvHostPath(platformType string) string {
return envFs
}

if env := os.Getenv(ResticPVHostPathEnvVar); env != "" {
return env
}

// Return platform-specific host paths
switch platformType {
case IBMCloudPlatform:
Expand Down Expand Up @@ -108,16 +101,7 @@ func (r *DataProtectionApplicationReconciler) ReconcileNodeAgentDaemonset(log lo
ObjectMeta: getNodeAgentObjectMeta(r),
}

if dpa.Spec.Configuration.Restic != nil {
// V(-1) corresponds to the warn level
var deprecationMsg string = "(Deprecation Warning) Use nodeAgent instead of restic, which is deprecated and will be removed in the future"
log.V(-1).Info(deprecationMsg)
r.EventRecorder.Event(dpa, corev1.EventTypeWarning, "DeprecationResticConfig", deprecationMsg)
}

if dpa.Spec.Configuration.Restic != nil && dpa.Spec.Configuration.Restic.Enable != nil && *dpa.Spec.Configuration.Restic.Enable {
deleteDaemonSet = false
} else if dpa.Spec.Configuration.NodeAgent != nil && dpa.Spec.Configuration.NodeAgent.Enable != nil && *dpa.Spec.Configuration.NodeAgent.Enable {
if dpa.Spec.Configuration.NodeAgent != nil && dpa.Spec.Configuration.NodeAgent.Enable != nil && *dpa.Spec.Configuration.NodeAgent.Enable {
deleteDaemonSet = false
}

Expand All @@ -132,11 +116,9 @@ func (r *DataProtectionApplicationReconciler) ReconcileNodeAgentDaemonset(log lo
}
return false, err
}
// no errors means there already is an existing DaeMonset.
// no errors means there is already an existing DaemonSet.
// TODO: Check if NodeAgent is in use, a backup is running, so don't blindly delete NodeAgent.
// If dpa.Spec.Configuration.NodeAgent enable exists and is false, attempt to delete.
deleteOptionPropagationForeground := metav1.DeletePropagationForeground
if err := r.Delete(deleteContext, ds, &client.DeleteOptions{PropagationPolicy: &deleteOptionPropagationForeground}); err != nil {
if err := r.Delete(deleteContext, ds, &client.DeleteOptions{PropagationPolicy: ptr.To(metav1.DeletePropagationForeground)}); err != nil {
// TODO: Come back and fix event recording to be consistent
r.EventRecorder.Event(ds, corev1.EventTypeNormal, "DeleteDaemonSetFailed", "Got DaemonSet to delete but could not delete err:"+err.Error())
return false, err
Expand Down Expand Up @@ -214,24 +196,16 @@ func (r *DataProtectionApplicationReconciler) ReconcileNodeAgentDaemonset(log lo
*/
func (r *DataProtectionApplicationReconciler) buildNodeAgentDaemonset(ds *appsv1.DaemonSet) (*appsv1.DaemonSet, error) {
dpa := r.dpa
if dpa == nil {
return nil, fmt.Errorf("dpa cannot be nil")
}

if ds == nil {
return nil, fmt.Errorf("ds cannot be nil")
return nil, fmt.Errorf("DaemonSet cannot be nil")
}

var nodeAgentResourceReqs corev1.ResourceRequirements

// get resource requirements for nodeAgent ds
// ignoring err here as it is checked in validator.go
if dpa.Spec.Configuration.Restic != nil {
nodeAgentResourceReqs, _ = getResticResourceReqs(dpa)
} else if dpa.Spec.Configuration.NodeAgent != nil {
nodeAgentResourceReqs, _ = getNodeAgentResourceReqs(dpa)
} else {
return nil, fmt.Errorf("NodeAgent or Restic configuration cannot be nil")
}
nodeAgentResourceReqs, _ = getNodeAgentResourceReqs(dpa)

installDs := install.DaemonSet(ds.Namespace,
install.WithResources(nodeAgentResourceReqs),
Expand All @@ -257,29 +231,6 @@ func (r *DataProtectionApplicationReconciler) buildNodeAgentDaemonset(ds *appsv1

func (r *DataProtectionApplicationReconciler) customizeNodeAgentDaemonset(ds *appsv1.DaemonSet) (*appsv1.DaemonSet, error) {
dpa := r.dpa
if dpa.Spec.Configuration == nil || (dpa.Spec.Configuration.Restic == nil && dpa.Spec.Configuration.NodeAgent == nil) {
// if restic and nodeAgent are not configured, therefore not enabled, return early.
return nil, nil
}

var useResticConf bool = true

if dpa.Spec.Configuration.NodeAgent != nil {
useResticConf = false
}

// add custom pod labels
var err error
if useResticConf {
if dpa.Spec.Configuration.Restic.PodConfig != nil && dpa.Spec.Configuration.Restic.PodConfig.Labels != nil {
ds.Spec.Template.Labels, err = common.AppendUniqueKeyTOfTMaps(ds.Spec.Template.Labels, dpa.Spec.Configuration.Restic.PodConfig.Labels)
}
} else if dpa.Spec.Configuration.NodeAgent.PodConfig != nil && dpa.Spec.Configuration.NodeAgent.PodConfig.Labels != nil {
ds.Spec.Template.Labels, err = common.AppendUniqueKeyTOfTMaps(ds.Spec.Template.Labels, dpa.Spec.Configuration.NodeAgent.PodConfig.Labels)
}
if err != nil {
return nil, fmt.Errorf("NodeAgent daemonset template custom label: %s", err)
}

// customize specs
ds.Spec.Selector = nodeAgentLabelSelector
Expand All @@ -288,16 +239,9 @@ func (r *DataProtectionApplicationReconciler) customizeNodeAgentDaemonset(ds *ap
}

// customize template specs
if useResticConf {
ds.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{
RunAsUser: pointer.Int64(0),
SupplementalGroups: dpa.Spec.Configuration.Restic.SupplementalGroups,
}
} else {
ds.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{
RunAsUser: pointer.Int64(0),
SupplementalGroups: dpa.Spec.Configuration.NodeAgent.SupplementalGroups,
}
ds.Spec.Template.Spec.SecurityContext = &corev1.PodSecurityContext{
RunAsUser: ptr.To(int64(0)),
SupplementalGroups: dpa.Spec.Configuration.NodeAgent.SupplementalGroups,
}
ds.Spec.Template.Spec.Volumes = append(ds.Spec.Template.Spec.Volumes,
// append certs volume
Expand Down Expand Up @@ -344,14 +288,17 @@ func (r *DataProtectionApplicationReconciler) customizeNodeAgentDaemonset(ds *ap
}

// Update with any pod config values
if useResticConf {
if dpa.Spec.Configuration.Restic.PodConfig != nil {
ds.Spec.Template.Spec.Tolerations = dpa.Spec.Configuration.Restic.PodConfig.Tolerations
ds.Spec.Template.Spec.NodeSelector = dpa.Spec.Configuration.Restic.PodConfig.NodeSelector
}
} else if dpa.Spec.Configuration.NodeAgent.PodConfig != nil {
if dpa.Spec.Configuration.NodeAgent.PodConfig != nil {
ds.Spec.Template.Spec.Tolerations = dpa.Spec.Configuration.NodeAgent.PodConfig.Tolerations
ds.Spec.Template.Spec.NodeSelector = dpa.Spec.Configuration.NodeAgent.PodConfig.NodeSelector
// add custom pod labels
if dpa.Spec.Configuration.NodeAgent.PodConfig.Labels != nil {
var err error
ds.Spec.Template.Labels, err = common.AppendUniqueKeyTOfTMaps(ds.Spec.Template.Labels, dpa.Spec.Configuration.NodeAgent.PodConfig.Labels)
if err != nil {
return nil, fmt.Errorf("NodeAgent daemonset template custom label: %s", err)
}
}
}

// fetch nodeAgent container in order to customize it
Expand Down Expand Up @@ -380,19 +327,15 @@ func (r *DataProtectionApplicationReconciler) customizeNodeAgentDaemonset(ds *ap
}
}
// append PodConfig envs to nodeAgent container
if useResticConf {
if dpa.Spec.Configuration.Restic.PodConfig != nil && dpa.Spec.Configuration.Restic.PodConfig.Env != nil {
nodeAgentContainer.Env = common.AppendUniqueEnvVars(nodeAgentContainer.Env, dpa.Spec.Configuration.Restic.PodConfig.Env)
}
} else if dpa.Spec.Configuration.NodeAgent.PodConfig != nil && dpa.Spec.Configuration.NodeAgent.PodConfig.Env != nil {
if dpa.Spec.Configuration.NodeAgent.PodConfig != nil && dpa.Spec.Configuration.NodeAgent.PodConfig.Env != nil {
nodeAgentContainer.Env = common.AppendUniqueEnvVars(nodeAgentContainer.Env, dpa.Spec.Configuration.NodeAgent.PodConfig.Env)
}

// append env vars to the nodeAgent container
nodeAgentContainer.Env = common.AppendUniqueEnvVars(nodeAgentContainer.Env, proxy.ReadProxyVarsFromEnv())

nodeAgentContainer.SecurityContext = &corev1.SecurityContext{
Privileged: pointer.Bool(true),
Privileged: ptr.To(true),
}

imagePullPolicy, err := common.GetImagePullPolicy(dpa.Spec.ImagePullPolicy, getVeleroImage(dpa))
Expand Down Expand Up @@ -447,7 +390,7 @@ func (r *DataProtectionApplicationReconciler) customizeNodeAgentDaemonset(ds *ap
}
}
if ds.Spec.RevisionHistoryLimit == nil {
ds.Spec.RevisionHistoryLimit = pointer.Int32(10)
ds.Spec.RevisionHistoryLimit = ptr.To(int32(10))
}

return ds, nil
Expand All @@ -461,17 +404,6 @@ func (r *DataProtectionApplicationReconciler) ReconcileFsRestoreHelperConfig(log
},
}

// Delete renamed CM restic-restore-action-config
// Velero uses labels to identify the CM. For consistency we have the
// same name as upstream, whch is `fs-restore-action-config`
resticRestoreHelperCM := corev1.ConfigMap{}
if err := r.Get(r.Context, types.NamespacedName{Namespace: r.NamespacedName.Namespace, Name: ResticRestoreHelperCM}, &resticRestoreHelperCM); err == nil {
r.Log.Info("Deleting deprecated ConfigMap restic-restore-action-config.")
if err := r.Delete(r.Context, &resticRestoreHelperCM); err != nil {
return false, err
}
}

op, err := controllerutil.CreateOrPatch(r.Context, r.Client, &fsRestoreHelperCM, func() error {

// update the Config Map
Expand Down
20 changes: 2 additions & 18 deletions internal/controller/nodeagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,10 @@ func TestDPAReconciler_buildNodeAgentDaemonset(t *testing.T) {
wantNodeAgentDaemonSet *appsv1.DaemonSet
errorMessage string
}{
{
name: "DPA CR is nil, error is returned",
errorMessage: "dpa cannot be nil",
},
{
name: "NodeAgent DaemonSet is nil, error is returned",
dpa: &oadpv1alpha1.DataProtectionApplication{},
errorMessage: "ds cannot be nil",
errorMessage: "DaemonSet cannot be nil",
},
{
name: "valid DPA CR, NodeAgent DaemonSet is built",
Expand Down Expand Up @@ -569,6 +565,7 @@ func TestDPAReconciler_buildNodeAgentDaemonset(t *testing.T) {
},
},
),
clientObjects: []client.Object{testGenericInfrastructure},
nodeAgentDaemonSet: testNodeAgentDaemonSet.DeepCopy(),
errorMessage: "NodeAgent daemonset template custom label: conflicting key name with value not-node-agent may not override node-agent",
},
Expand Down Expand Up @@ -1321,49 +1318,36 @@ func Test_getFsPvHostPath(t *testing.T) {
tests := []struct {
name string
platformType string
envRestic string
envFS string
want string
}{
{
name: "generic pv host path returned for empty platform type case",
platformType: "",
envRestic: "",
envFS: "",
want: GenericPVHostPath,
},
{
name: "IBMCloud pv host path returned for IBMCloud platform type",
platformType: IBMCloudPlatform,
envRestic: "",
envFS: "",
want: IBMCloudPVHostPath,
},
{
name: "empty platform type with restic env var set",
platformType: "",
envRestic: "/foo/restic/bar",
envFS: "",
want: "/foo/restic/bar",
},
{
name: "empty platform type with fs env var set",
platformType: "",
envRestic: "",
envFS: "/foo/file-system/bar",
want: "/foo/file-system/bar",
},
{
name: "IBMCloud platform type but env var also set, env var takes precedence",
platformType: IBMCloudPlatform,
envRestic: "",
envFS: "/foo/file-system/env/var/override",
want: "/foo/file-system/env/var/override",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv(ResticPVHostPathEnvVar, tt.envRestic)
t.Setenv(FSPVHostPathEnvVar, tt.envFS)
if got := getFsPvHostPath(tt.platformType); got != tt.want {
t.Errorf("getFsPvHostPath() = %v, want %v", got, tt.want)
Expand Down
Loading

0 comments on commit cbd019d

Please sign in to comment.