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

[release-1.6] issue-639: Add labels from command line option to filestore backup resource #945

Open
wants to merge 1 commit into
base: release-1.6
Choose a base branch
from
Open
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
28 changes: 16 additions & 12 deletions pkg/csi_driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,10 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu
}

// Add labels.
labels, err := extractLabels(param, s.config.driver.config.Name)
labels, err := extractLabels(param, s.config.extraVolumeLabels, s.config.driver.config.Name)
if err != nil {
return nil, file.StatusError(err)
}
// Append extra lables from the command line option
for k, v := range s.config.extraVolumeLabels {
labels[k] = v
}
newFiler.Labels = labels

// Create the instance
Expand Down Expand Up @@ -841,7 +837,7 @@ func getZoneFromSegment(seg map[string]string) (string, error) {
return zone, nil
}

func extractLabels(parameters map[string]string, driverName string) (map[string]string, error) {
func extractLabels(parameters, cliLabels map[string]string, driverName string) (map[string]string, error) {
labels := make(map[string]string)
scLables := make(map[string]string)
for k, v := range parameters {
Expand All @@ -862,12 +858,12 @@ func extractLabels(parameters map[string]string, driverName string) (map[string]
}

labels[tagKeyCreatedBy] = strings.ReplaceAll(driverName, ".", "_")
return mergeLabels(scLables, labels)
return mergeLabels(scLables, labels, cliLabels)
}

func mergeLabels(scLabels map[string]string, metedataLabels map[string]string) (map[string]string, error) {
func mergeLabels(scLabels, metadataLabels, cliLabels map[string]string) (map[string]string, error) {
result := make(map[string]string)
for k, v := range metedataLabels {
for k, v := range metadataLabels {
result[k] = v
}

Expand All @@ -879,6 +875,14 @@ func mergeLabels(scLabels map[string]string, metedataLabels map[string]string) (
result[k] = v
}

// add labels from command line with precedence given to
// metadata and storage class labels in same order.
for k, v := range cliLabels {
if _, ok := result[k]; !ok {
result[k] = v
}
}

return result, nil
}

Expand Down Expand Up @@ -952,7 +956,7 @@ func (s *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSn
} else {
// create new backup

labels, err := extractBackupLabels(req.GetParameters(), s.config.driver.config.Name, req.Name)
labels, err := extractBackupLabels(req.GetParameters(), s.config.extraVolumeLabels, s.config.driver.config.Name, req.Name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -986,8 +990,8 @@ func (s *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSn
return snapshotResponse, nil
}

func extractBackupLabels(parameters map[string]string, driverName string, snapshotName string) (map[string]string, error) {
labels, err := extractLabels(parameters, driverName)
func extractBackupLabels(parameters, cliLabels map[string]string, driverName string, snapshotName string) (map[string]string, error) {
labels, err := extractLabels(parameters, cliLabels, driverName)
if err != nil {
return nil, err
}
Expand Down
Loading