Skip to content

Commit

Permalink
KUBEDR-6163: Add a jobid to configmaps that agent is using to run a job
Browse files Browse the repository at this point in the history
(cherry picked from commit c985030)
  • Loading branch information
dzaninovic authored and jongarner committed Dec 11, 2024
1 parent 74007b3 commit aacd6b0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ HUGO_IMAGE := hugo-builder
local : ARCH ?= $(shell go env GOOS)-$(shell go env GOARCH)
ARCH ?= linux-amd64

VERSION ?= v1.14.0.6-1
VERSION ?= v1.14.0.8

TAG_LATEST ?= false

Expand Down
8 changes: 4 additions & 4 deletions internal/catalogic/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ type PluginConfig struct {
const (
CloudCasaNamespace = "cloudcasa-io"

// Name of configmap used to to report progress of snapshot
SnapshotProgressUpdateConfigMapName = "cloudcasa-io-snapshot-updater"
// Prefix name of configmap used to to report progress of snapshot
SnapshotProgressUpdateConfigMapPrefix = "cloudcasa-io-snapshot-updater-"

TimeFormat = "2006-01-06 15:04:05 UTC: "

// VeleroCsiPluginConfigMapName is the name of the configmap used to store configuration parameters
VeleroCsiPluginConfigMapName = "cloudcasa-io-velero-csi-plugin"
// VeleroCsiPluginConfigMapPrefix is the name prefix of the configmap used to store configuration parameters
VeleroCsiPluginConfigMapPrefix = "cloudcasa-io-velero-csi-plugin-"
)

const (
Expand Down
28 changes: 16 additions & 12 deletions internal/catalogic/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func UpdateSnapshotProgress(
APIVersion: "v1",
},
ObjectMeta: v1.ObjectMeta{
Name: SnapshotProgressUpdateConfigMapName,
Name: SnapshotProgressUpdateConfigMapPrefix + jobID,
Namespace: CloudCasaNamespace,
},
BinaryData: requestData,
Expand All @@ -104,7 +104,9 @@ func UpdateSnapshotProgress(
log.Info("Update Snapshot Progress -", "Created clientset")
//Create or update the configmap
var mcm *corev1api.ConfigMap
if _, mErr := clientset.CoreV1().ConfigMaps(CloudCasaNamespace).Get(context.TODO(), SnapshotProgressUpdateConfigMapName, v1.GetOptions{}); kerror.IsNotFound(mErr) {
if _, mErr := clientset.CoreV1().ConfigMaps(CloudCasaNamespace).Get(context.TODO(), SnapshotProgressUpdateConfigMapPrefix+jobID,
v1.GetOptions{}); kerror.IsNotFound(mErr) {

Check failure on line 108 in internal/catalogic/utils.go

View workflow job for this annotation

GitHub Actions / Run Linter Check

unnecessary leading newline (whitespace)

mcm, err = clientset.CoreV1().ConfigMaps(CloudCasaNamespace).Create(context.TODO(), &moverConfigMap, v1.CreateOptions{})
if err != nil {
newErr := errors.Wrap(err, "Failed to create configmap to report snapshotprogress")
Expand All @@ -127,7 +129,7 @@ func UpdateSnapshotProgress(
}

// DeleteSnapshotProgressConfigMap deletes the configmap used to report snapshot progress
func DeleteSnapshotProgressConfigMap(log logrus.FieldLogger) {
func DeleteSnapshotProgressConfigMap(jobID string, log logrus.FieldLogger) {
// creates the in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
Expand All @@ -138,32 +140,34 @@ func DeleteSnapshotProgressConfigMap(log logrus.FieldLogger) {
if err != nil {
log.Error(errors.Wrap(err, "Failed to create in-cluster clientset"))
}
err = clientset.CoreV1().ConfigMaps(CloudCasaNamespace).Delete(context.TODO(), SnapshotProgressUpdateConfigMapName, v1.DeleteOptions{})
snapshotProgressUpdateConfigMapName := SnapshotProgressUpdateConfigMapPrefix + jobID
err = clientset.CoreV1().ConfigMaps(CloudCasaNamespace).Delete(context.TODO(), snapshotProgressUpdateConfigMapName, v1.DeleteOptions{})
if err != nil {
log.Error(errors.Wrap(err, "Failed to delete configmap used to report snapshot progress"))
} else {
log.Info("Deleted configmap used to report snapshot progress", "Configmap Name", SnapshotProgressUpdateConfigMapName)
log.Info("Deleted configmap used to report snapshot progress", "Configmap Name", snapshotProgressUpdateConfigMapName)
}
}

// GetPluginConfig reads the configmap that contains config parameters for this plugin
func GetPluginConfig(log logrus.FieldLogger) (*PluginConfig, error) {
func GetPluginConfig(jobID string, log logrus.FieldLogger) (*PluginConfig, error) {
clientset, err := GetClientset(log)
if err != nil {
return nil, err
}

configMap, err := clientset.CoreV1().ConfigMaps(CloudCasaNamespace).Get(context.TODO(), VeleroCsiPluginConfigMapName, v1.GetOptions{})
veleroCsiPluginConfigMapName := VeleroCsiPluginConfigMapPrefix + jobID
configMap, err := clientset.CoreV1().ConfigMaps(CloudCasaNamespace).Get(context.TODO(), veleroCsiPluginConfigMapName, v1.GetOptions{})
if err != nil {
log.Error(errors.Wrapf(err, "Failed to get %q configmap in %q namespace", VeleroCsiPluginConfigMapName, CloudCasaNamespace))
log.Error(errors.Wrapf(err, "Failed to get %q configmap in %q namespace", veleroCsiPluginConfigMapName, CloudCasaNamespace))
return nil, err
}

snapshotWherePossibleString := string(configMap.BinaryData["snapshotWherePossible"])
snapshotWherePossible, err := strconv.ParseBool(snapshotWherePossibleString)
if err != nil {
log.Error(errors.Wrapf(err, "Failed to parse snapshotWherePossible value %q from %q", snapshotWherePossibleString,
VeleroCsiPluginConfigMapName))
veleroCsiPluginConfigMapName))
return nil, err
}
if snapshotWherePossible {
Expand All @@ -175,7 +179,7 @@ func GetPluginConfig(log logrus.FieldLogger) (*PluginConfig, error) {
snapshotLonghornString := string(configMap.BinaryData["snapshotLonghorn"])
snapshotLonghorn, err := strconv.ParseBool(snapshotLonghornString)
if err != nil {
log.Error(errors.Wrapf(err, "Failed to parse snapshotLonghorn value %q from %q", snapshotLonghornString, VeleroCsiPluginConfigMapName))
log.Error(errors.Wrapf(err, "Failed to parse snapshotLonghorn value %q from %q", snapshotLonghornString, veleroCsiPluginConfigMapName))
return nil, err
}
if snapshotLonghorn {
Expand All @@ -185,7 +189,7 @@ func GetPluginConfig(log logrus.FieldLogger) (*PluginConfig, error) {
csiSnapshotTimeoutString := string(configMap.BinaryData["csiSnapshotTimeout"])
csiSnapshotTimeout, err := strconv.Atoi(csiSnapshotTimeoutString)
if err != nil {
log.Error(errors.Wrapf(err, "Failed to parse csiSnapshotTimeout value %q from %q", csiSnapshotTimeoutString, VeleroCsiPluginConfigMapName))
log.Error(errors.Wrapf(err, "Failed to parse csiSnapshotTimeout value %q from %q", csiSnapshotTimeoutString, veleroCsiPluginConfigMapName))
return nil, err
}
if csiSnapshotTimeout != 0 {
Expand All @@ -196,7 +200,7 @@ func GetPluginConfig(log logrus.FieldLogger) (*PluginConfig, error) {
var storageClassBackupMethodMap map[string]string
if err := json.Unmarshal(storageClassBackupMethodMapBytes, &storageClassBackupMethodMap); err != nil {
log.Error(errors.Wrapf(err, "Failed to parse storageClassBackupMethodMap value %q from %q", string(storageClassBackupMethodMapBytes),
VeleroCsiPluginConfigMapName))
veleroCsiPluginConfigMapName))
return nil, err
}
if len(storageClassBackupMethodMap) != 0 {
Expand Down
11 changes: 7 additions & 4 deletions pkg/backup/actions/csi/pvc_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (p *pvcBackupItemAction) createVolumeSnapshot(
skip bool,
err error,
) {
jobID := backup.Name
p.log.Debugf("Fetching storage class for PV %s", *pvc.Spec.StorageClassName)
storageClass = new(storagev1api.StorageClass)
if err := p.crClient.Get(
Expand All @@ -162,7 +163,7 @@ func (p *pvcBackupItemAction) createVolumeSnapshot(
nil,
"error",
message,
backup.Name,
jobID,
p.log,
)
if uErr != nil {
Expand All @@ -171,7 +172,7 @@ func (p *pvcBackupItemAction) createVolumeSnapshot(
return nil, nil, false, errors.Wrap(err, "error getting storage class")
}

if shouldSkipSnapshot, err := p.shouldSkipSnapshot(&pvc, pv.Name, storageClass.Provisioner); err != nil {
if shouldSkipSnapshot, err := p.shouldSkipSnapshot(&pvc, pv.Name, storageClass.Provisioner, jobID); err != nil {
return nil, nil, false, err
} else if shouldSkipSnapshot {
return nil, nil, true, nil
Expand Down Expand Up @@ -624,8 +625,10 @@ func NewPvcBackupItemAction(f client.Factory) plugincommon.HandlerInitializer {
}
}

func (p *pvcBackupItemAction) shouldSkipSnapshot(pvc *corev1api.PersistentVolumeClaim, pvName string, provisioner string) (bool, error) {
config, err := catalogic.GetPluginConfig(p.log)
func (p *pvcBackupItemAction) shouldSkipSnapshot(pvc *corev1api.PersistentVolumeClaim, pvName string, provisioner string,
jobID string) (bool, error) {

Check failure on line 629 in pkg/backup/actions/csi/pvc_action.go

View workflow job for this annotation

GitHub Actions / Run Linter Check

unnecessary leading newline (whitespace)

config, err := catalogic.GetPluginConfig(jobID, p.log)
if err != nil {
return false, errors.Wrap(err, "error getting plugin config")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/csi/volume_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,15 @@ func WaitUntilVSCHandleIsReady(
var snapshotStateMessage string
jobID := volSnap.Labels["velero.io/backup-name"]

defer catalogic.DeleteSnapshotProgressConfigMap(log)
defer catalogic.DeleteSnapshotProgressConfigMap(jobID, log)
defer func(err error) {
uErr := catalogic.UpdateSnapshotProgress(nil, volSnap, nil, snapshotState, snapshotStateMessage, jobID, log)
if uErr != nil {
log.Error(err, "<SNAPSHOT PROGRESS UPDATE> Failed to update snapshot progress. Continuing...")
}
}(err)

config, err := catalogic.GetPluginConfig(log)
config, err := catalogic.GetPluginConfig(jobID, log)
if err != nil {
return nil, errors.Wrap(err, "error getting plugin config")
}
Expand Down

0 comments on commit aacd6b0

Please sign in to comment.