Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(prod) port KUBEDR-6163 #15

Merged
merged 1 commit into from
Dec 11, 2024
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
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 @@ -35,7 +35,7 @@
return nil
}
var err error
// Fill in the PVC realted information

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

View workflow job for this annotation

GitHub Actions / Run Codespell

realted ==> related
var pvcProgressObject = PvcInfo{}
if pvc != nil {
pvcProgressObject.Name = pvc.GetName()
Expand Down Expand Up @@ -68,7 +68,7 @@
requestData := make(map[string][]byte)
if requestData["snapshot_progress_payload"], err = json.Marshal(progress); err != nil {
newErr := errors.Wrap(err, "Failed to marshal progress while creating the snapshot progress configmap")
log.Error(newErr, "JSON marshalling failed")

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

View workflow job for this annotation

GitHub Actions / Run Linter Check

`marshalling` is a misspelling of `marshaling` (misspell)
return newErr
}
log.Info("Update Snapshot Progress -", "Marsahlled the JSON payload")
Expand All @@ -79,7 +79,7 @@
APIVersion: "v1",
},
ObjectMeta: v1.ObjectMeta{
Name: SnapshotProgressUpdateConfigMapName,
Name: SnapshotProgressUpdateConfigMapPrefix + jobID,
Namespace: CloudCasaNamespace,
},
BinaryData: requestData,
Expand All @@ -92,7 +92,7 @@
log.Error(newErr, "Failed to create in-cluster config")
return newErr

}

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

View workflow job for this annotation

GitHub Actions / Run Linter Check

unnecessary trailing newline (whitespace)
log.Info("Update Snapshot Progress -", "Created in-cluster config")
// Create clientset
clientset, err := kubernetes.NewForConfig(config)
Expand All @@ -104,14 +104,16 @@
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")
log.Error(newErr, "Failed to create configmap")
return newErr

}

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

View workflow job for this annotation

GitHub Actions / Run Linter Check

unnecessary trailing newline (whitespace)
log.Info("Created configmap to report snapshot progress", "Configmap Name", mcm.GetName())
} else {
mcm, err = clientset.CoreV1().ConfigMaps(CloudCasaNamespace).Update(context.TODO(), &moverConfigMap, v1.UpdateOptions{})
Expand All @@ -127,7 +129,7 @@
}

// 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 @@
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 @@
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 @@
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 @@
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 Expand Up @@ -260,7 +264,7 @@
log.Infof("Dynamically provisioned %s PV %s bounded with PVC %s/%s found", storageClass.Provisioner, pv.Name, pvc.Namespace, pvc.Name)
isDynamicallyProvisioned = true

} else {

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

View workflow job for this annotation

GitHub Actions / Run Linter Check

unnecessary trailing newline (whitespace)
log.Infof("Statically provisioned %s PV %s bounded with PVC %s/%s found", storageClass.Provisioner, pv.Name, pvc.Namespace, pvc.Name)
isDynamicallyProvisioned = false
}
Expand All @@ -280,7 +284,7 @@
secretNamespace, err = GetAzureFileSecretNamespace(*pvc, pv, storageClass, log, isDynamicallyProvisioned)
if err != nil {
log.Errorf(
"Could not find secret namesapce for %s PV %s bounded with PVC %s/%s",

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

View workflow job for this annotation

GitHub Actions / Run Codespell

namesapce ==> namespace
storageClass.Provisioner, pv.Name, pvc.Namespace, pvc.Namespace,
)
return errors.WithStack(err)
Expand Down Expand Up @@ -413,7 +417,7 @@
sc.Provisioner, pv.Name, pvc.Namespace, pvc.Name,
)
// If secret name is not present in the attributes, it means the storage Account
// was created the CSI drvier. In such case, get the Storage account name from

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

View workflow job for this annotation

GitHub Actions / Run Codespell

drvier ==> driver
// volumeHandle.
// Example:
// volumeHandle: <resource-group>#<storage-account-name>#<share-name>###<namespace>
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 @@
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 @@
nil,
"error",
message,
backup.Name,
jobID,
p.log,
)
if uErr != nil {
Expand All @@ -171,7 +172,7 @@
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 @@ -309,7 +310,7 @@
}

if storageClass.Provisioner == "file.csi.azure.com" {
catalogic.SetStaticAzureAnotation(&pvc, labels, storageClass, p.log)

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

View workflow job for this annotation

GitHub Actions / Run Linter Check

Error return value of `catalogic.SetStaticAzureAnotation` is not checked (errcheck)
}

annotations := labels
Expand Down Expand Up @@ -624,8 +625,10 @@
}
}

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
Loading