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 Sep 26, 2024
1 parent 94bc5ae commit 366766f
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 149 deletions.
8 changes: 2 additions & 6 deletions api/v1alpha1/oadp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,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 @@ -467,8 +465,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
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,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 @@ -420,9 +420,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
6 changes: 0 additions & 6 deletions config/samples/resticrepository.yaml

This file was deleted.

81 changes: 13 additions & 68 deletions controllers/nodeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

const (
ResticRestoreHelperCM = "restic-restore-action-config"
FsRestoreHelperCM = "fs-restore-action-config"
HostPods = "host-pods"
HostPlugins = "host-plugins"
Expand All @@ -36,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 @@ -62,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 @@ -111,16 +105,7 @@ func (r *DPAReconciler) ReconcileNodeAgentDaemonset(log logr.Logger) (bool, erro
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 Down Expand Up @@ -225,15 +210,12 @@ func (r *DPAReconciler) buildNodeAgentDaemonset(dpa *oadpv1alpha1.DataProtection

var nodeAgentResourceReqs corev1.ResourceRequirements

if dpa.Spec.Configuration.NodeAgent == nil {
return nil, fmt.Errorf("NodeAgent configuration cannot be nil")
}
// 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 @@ -258,24 +240,14 @@ func (r *DPAReconciler) buildNodeAgentDaemonset(dpa *oadpv1alpha1.DataProtection
}

func (r *DPAReconciler) customizeNodeAgentDaemonset(dpa *oadpv1alpha1.DataProtectionApplication, ds *appsv1.DaemonSet) (*appsv1.DaemonSet, error) {
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.
if dpa.Spec.Configuration == nil || dpa.Spec.Configuration.NodeAgent == nil {
// if nodeAgent is 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 {
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 {
Expand All @@ -289,16 +261,9 @@ func (r *DPAReconciler) customizeNodeAgentDaemonset(dpa *oadpv1alpha1.DataProtec
}

// 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: pointer.Int64(0),
SupplementalGroups: dpa.Spec.Configuration.NodeAgent.SupplementalGroups,
}

// append certs volume
Expand Down Expand Up @@ -330,12 +295,7 @@ func (r *DPAReconciler) customizeNodeAgentDaemonset(dpa *oadpv1alpha1.DataProtec
}

// 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
}
Expand All @@ -359,11 +319,7 @@ func (r *DPAReconciler) customizeNodeAgentDaemonset(dpa *oadpv1alpha1.DataProtec
}
}
// 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)
}

Expand Down Expand Up @@ -445,17 +401,6 @@ func (r *DPAReconciler) ReconcileFsRestoreHelperConfig(log logr.Logger) (bool, e
},
}

// 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
13 changes: 0 additions & 13 deletions controllers/nodeagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,49 +1296,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
16 changes: 9 additions & 7 deletions controllers/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error)
return false, errors.New("DPA CR Velero configuration cannot be nil")
}

if dpa.Spec.Configuration.Restic != nil && dpa.Spec.Configuration.NodeAgent != nil {
return false, errors.New("DPA CR cannot have restic (deprecated in OADP 1.3) as well as nodeAgent options at the same time")
}

if dpa.Spec.Configuration.Velero.NoDefaultBackupLocation {
if len(dpa.Spec.BackupLocations) != 0 {
return false, errors.New("DPA CR Velero configuration cannot have backup locations if noDefaultBackupLocation is set")
Expand All @@ -53,6 +49,11 @@ func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error)
return false, errors.New("Delete vsm from spec.configuration.velero.defaultPlugins and dataMover object from spec.features. Use Velero Built-in Data Mover instead")
}

// check for ResticConfig (OADP 1.3 or below) syntax
if dpa.Spec.Configuration != nil && dpa.Spec.Configuration.Restic != nil {
return false, errors.New("Delete restic object from spec.configuration, use spec.configuration.nodeAgent instead")
}

if val, found := dpa.Spec.UnsupportedOverrides[oadpv1alpha1.OperatorTypeKey]; found && val != oadpv1alpha1.OperatorTypeMTC {
return false, errors.New("only mtc operator type override is supported")
}
Expand All @@ -66,12 +67,13 @@ func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error)
if _, err := r.getVeleroResourceReqs(&dpa); err != nil {
return false, err
}
if _, err := getResticResourceReqs(&dpa); err != nil {
return false, err
}

if _, err := getNodeAgentResourceReqs(&dpa); err != nil {
return false, err
}
if validBsl, err := r.ValidateBackupStorageLocations(dpa); !validBsl || err != nil {
return validBsl, err
}

// validate non-admin enable and tech-preview-ack
if r.checkNonAdminEnabled(&dpa) {
Expand Down
3 changes: 2 additions & 1 deletion controllers/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
},
},
Restic: &oadpv1alpha1.ResticConfig{
NodeAgent: &oadpv1alpha1.NodeAgentConfig{
NodeAgentCommonFields: oadpv1alpha1.NodeAgentCommonFields{
PodConfig: &oadpv1alpha1.PodConfig{
ResourceAllocations: corev1.ResourceRequirements{
Expand All @@ -338,6 +338,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
},
},
},
UploaderType: "restic",
},
},
BackupImages: pointer.Bool(false),
Expand Down
15 changes: 0 additions & 15 deletions controllers/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ func (r *DPAReconciler) buildVeleroDeployment(veleroDeployment *appsv1.Deploymen
return fmt.Errorf("error appending pod annotations: %v", err)
}

// Since `restic` can be still be used and it default's to an empty string, we can't just
// pass the dpa.Spec.Configuration.NodeAgent.UploaderType directly
uploaderType := ""
if dpa.Spec.Configuration.NodeAgent != nil && len(dpa.Spec.Configuration.NodeAgent.UploaderType) > 0 {
uploaderType = dpa.Spec.Configuration.NodeAgent.UploaderType
Expand Down Expand Up @@ -584,9 +582,6 @@ func (r *DPAReconciler) customizeVeleroContainer(dpa *oadpv1alpha1.DataProtectio
}

func getFsBackupTimeout(dpa *oadpv1alpha1.DataProtectionApplication) string {
if dpa.Spec.Configuration.Restic != nil && len(dpa.Spec.Configuration.Restic.Timeout) > 0 {
return dpa.Spec.Configuration.Restic.Timeout
}
if dpa.Spec.Configuration.NodeAgent != nil && len(dpa.Spec.Configuration.NodeAgent.Timeout) > 0 {
return dpa.Spec.Configuration.NodeAgent.Timeout
}
Expand Down Expand Up @@ -735,17 +730,7 @@ func (r *DPAReconciler) getVeleroResourceReqs(dpa *oadpv1alpha1.DataProtectionAp
return *defaultContainerResourceRequirements.DeepCopy(), nil
}

// Get Restic Resource Requirements
func getResticResourceReqs(dpa *oadpv1alpha1.DataProtectionApplication) (corev1.ResourceRequirements, error) {
if dpa.Spec.Configuration.Restic != nil && dpa.Spec.Configuration.Restic.PodConfig != nil {
return getResourceReqs(&dpa.Spec.Configuration.Restic.PodConfig.ResourceAllocations)
}
return *defaultContainerResourceRequirements.DeepCopy(), nil
}

// Get NodeAgent Resource Requirements
// Separate function to getResticResourceReqs, so once Restic config is removed in the future
// It will be easier to delete obsolete getResticResourceReqs
func getNodeAgentResourceReqs(dpa *oadpv1alpha1.DataProtectionApplication) (corev1.ResourceRequirements, error) {
if dpa.Spec.Configuration.NodeAgent != nil && dpa.Spec.Configuration.NodeAgent.PodConfig != nil {
return getResourceReqs(&dpa.Spec.Configuration.NodeAgent.PodConfig.ResourceAllocations)
Expand Down
Loading

0 comments on commit 366766f

Please sign in to comment.