Skip to content

Commit

Permalink
Merge pull request #640 from bharath-b-rh/issue-639
Browse files Browse the repository at this point in the history
issue-639: Add labels from command line option to filestore backup resource
  • Loading branch information
k8s-ci-robot authored Apr 15, 2024
2 parents 573a716 + 04771ec commit 17578a7
Show file tree
Hide file tree
Showing 5 changed files with 584 additions and 27 deletions.
28 changes: 16 additions & 12 deletions pkg/csi_driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,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 @@ -836,7 +832,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 @@ -857,12 +853,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 @@ -874,6 +870,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 @@ -946,7 +950,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 @@ -976,8 +980,8 @@ func (s *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSn

}

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

0 comments on commit 17578a7

Please sign in to comment.