Skip to content

Commit

Permalink
pb-4844: Adding changes to read directly from the cm in kdmp utils
Browse files Browse the repository at this point in the history
Signed-off-by: root <[email protected]>
  • Loading branch information
root committed Dec 12, 2023
1 parent 55ce29e commit eda9d77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 38 deletions.
1 change: 1 addition & 0 deletions pkg/drivers/kopiabackup/kopiabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func jobFor(
"/data",
}, " ")

// Read the config map from the job option and then add the debug level log if required
cmd = utils.CheckAndAddKopiaDebugModeEnabled(cmd, jobOption)

if jobOption.Compression != "" {
Expand Down
8 changes: 0 additions & 8 deletions pkg/drivers/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,6 @@ func WithVolumeBackupDeleteName(name string) JobOption {
}
}

// WithKopiaDebugMode is job parameter
func WithKopiaDebugMode(debugMode bool) JobOption {
return func(opts *JobOpts) error {
opts.KopiaDebugMode = debugMode
return nil
}
}

// WithVolumeBackupDeleteNamespace is job parameter.
func WithVolumeBackupDeleteNamespace(ns string) JobOption {
return func(opts *JobOpts) error {
Expand Down
38 changes: 8 additions & 30 deletions pkg/drivers/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package utils

import (
"context"
"errors"
"fmt"
"os"
Expand All @@ -13,7 +12,6 @@ import (
storkapi "github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1"
"github.com/libopenstorage/stork/pkg/k8sutils"
"github.com/portworx/kdmp/pkg/drivers"
kdmpops "github.com/portworx/kdmp/pkg/util/ops"
"github.com/portworx/kdmp/pkg/version"
"github.com/portworx/sched-ops/k8s/apps"
"github.com/portworx/sched-ops/k8s/core"
Expand Down Expand Up @@ -67,6 +65,8 @@ const (
PvcBoundFailedMsg = "pvc not bounded"
// KopiaDebugModeEnabled - debug level log messages are enabled for kopia
KopiaDebugModeEnabled = "kopia-debug-mode"
// KopiaExecutorDebugModeCMKey - key present in the config maps, which enables debug log level in kopia
KopiaExecutorDebugModeCMKey = "KDMP_KOPIAEXECUTOR_ENABLE_DEBUG_MODE"
)

var (
Expand Down Expand Up @@ -881,36 +881,14 @@ func IsJobPodMountFailed(job *batchv1.Job, namespace string) bool {
return false
}

func IsKopiaDebugModeAnnotationsEnabled(jobOption drivers.JobOpts) bool {
// Check for kopia delete and maintenance operations. Since, the debug is passed from job options
// and not from Data Export CR.
if jobOption.KopiaDebugMode {
return true
}

dataExportCR, err := kdmpops.Instance().GetDataExport(context.Background(), jobOption.DataExportName, jobOption.Namespace)
if err != nil {
logrus.Tracef("error reading data export job: %v", err)
return false
}

if _, ok := dataExportCR.Annotations[KopiaDebugModeEnabled]; ok {
logrus.Infof("annotation %v found in the data export CR.", KopiaDebugModeEnabled)
return true
}
return false
}

func CheckAndAddKopiaDebugModeEnabled(cmd string, jobOption drivers.JobOpts) string {
if IsKopiaDebugModeAnnotationsEnabled(jobOption) {
cmd = AddKopiaDebugModeCommand(cmd)
// check for the particular key-value pair
isKeyPresent := GetConfigValue(jobOption.JobConfigMap, jobOption.JobConfigMapNs, KopiaExecutorDebugModeCMKey)
if isKeyPresent == "true" {
splitCmd := strings.Split(cmd, " ")
splitCmd = append(splitCmd, "--log-level", "debug")
cmd = strings.Join(splitCmd, " ")
}
return cmd
}

func AddKopiaDebugModeCommand(cmd string) string {
splitCmd := strings.Split(cmd, " ")
splitCmd = append(splitCmd, "--log-level", "debug")
cmd = strings.Join(splitCmd, " ")
return cmd
}

0 comments on commit eda9d77

Please sign in to comment.