Skip to content

fix(BD-labels):add device attributes and location details as bd labels #618

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

Merged
merged 25 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8fdf4f5
added device attributes and location details as bd labels
Aug 25, 2021
3ef8aa5
node attributes to be added only when env variable specifies to do so
Aug 25, 2021
dca0b0f
fix failing unit tests
Aug 25, 2021
9ef2245
add unit test
Aug 25, 2021
f274c21
Added unit tests
Aug 26, 2021
ad03f13
refactored unit test
Aug 26, 2021
1542ec8
refactored code and removed unnecessary labels from BD
Aug 26, 2021
a82e5c3
added unit test for controller pkg change
Aug 26, 2021
41fd54a
made label addtion generic and changes unit tests accordingly
Aug 29, 2021
c8a7341
enhanced the unit tests
Aug 29, 2021
9bce455
formatted code
Aug 29, 2021
72a8672
updated comments and removed unwanted constants
Aug 31, 2021
cd06ddf
Merge remote-tracking branch 'origin' into add-bd-labels
Sep 12, 2021
7f48419
changes updated with configmap modification
Sep 13, 2021
82f8d76
removed unwamted unit tests
Sep 13, 2021
5bf9c3b
change code logic to avoid Off-by-one index comparison against length…
Sep 13, 2021
9b4fd68
removed .idea folder
Sep 13, 2021
c7ef9a8
fix failing checks
Sep 13, 2021
157508c
include quotes in the configmap fields
Sep 13, 2021
88d3f7f
Merge remote-tracking branch 'origin' into add-bd-labels
Oct 11, 2021
e63bc25
bump chart version
Oct 11, 2021
1c7b052
removed meta-configs from default config values and changed label val…
Oct 21, 2021
e1bf2b0
ran make-manifests to generate operator yaml
Oct 26, 2021
8299df8
removed kubectl dependency
Nov 22, 2021
77878d3
add kubectl repo reference in the comment
Nov 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
34 changes: 32 additions & 2 deletions cmd/ndm_daemonset/controller/blockdevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package controller

import (
"fmt"
"regexp"
"strings"

"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/client-go/util/jsonpath"
"k8s.io/klog"
"k8s.io/kubectl/pkg/cmd/get"

apis "github.com/openebs/node-disk-manager/api/v1alpha1"
bd "github.com/openebs/node-disk-manager/blockdevice"
Expand Down Expand Up @@ -106,7 +106,7 @@ func addBdLabels(bd *apis.BlockDevice, ctrl *Controller) error {
if len(JsonPathFields) > 0 {
for _, jsonPath := range JsonPathFields {
// Parse jsonpath
fields, err := get.RelaxedJSONPathExpression(strings.TrimSpace(jsonPath))
fields, err := RelaxedJSONPathExpression(strings.TrimSpace(jsonPath))
if err != nil {
klog.Errorf("Error converting into a valid jsonpath expression: %+v", err)
return err
Expand Down Expand Up @@ -157,6 +157,36 @@ func addBdLabels(bd *apis.BlockDevice, ctrl *Controller) error {
return nil
}

// RelaxedJSONPathExpression attempts to be flexible with JSONPath expressions, it accepts:
// * metadata.name (no leading '.' or curly braces '{...}'
// * {metadata.name} (no leading '.')
// * .metadata.name (no curly braces '{...}')
// * {.metadata.name} (complete expression)
// And transforms them all into a valid jsonpath expression:
// {.metadata.name}
func RelaxedJSONPathExpression(pathExpression string) (string, error) {
var jsonRegexp = regexp.MustCompile(`^\{\.?([^{}]+)\}$|^\.?([^{}]+)$`)

if len(pathExpression) == 0 {
return pathExpression, nil
}
submatches := jsonRegexp.FindStringSubmatch(pathExpression)
if submatches == nil {
return "", fmt.Errorf("unexpected path string, expected a 'name1.name2' or '.name1.name2' or '{name1.name2}' or '{.name1.name2}'")
}
if len(submatches) != 3 {
return "", fmt.Errorf("unexpected submatch list: %v", submatches)
}
var fieldSpec string
if len(submatches[1]) != 0 {
fieldSpec = submatches[1]
} else {
fieldSpec = submatches[2]
}
return fmt.Sprintf("{.%s}", fieldSpec), nil
}


// getObjectMeta returns ObjectMeta struct which contains
// labels and Name of resource. It is used to populate data
// of BlockDevice struct of BlockDevice CR.
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ require (
k8s.io/apimachinery v0.20.2
k8s.io/client-go v0.20.2
k8s.io/klog v1.0.0
k8s.io/kubectl v0.20.2
sigs.k8s.io/controller-runtime v0.8.2
)
47 changes: 0 additions & 47 deletions go.sum

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions vendor/github.com/Azure/go-ansiterm/LICENSE

This file was deleted.

12 changes: 0 additions & 12 deletions vendor/github.com/Azure/go-ansiterm/README.md

This file was deleted.

188 changes: 0 additions & 188 deletions vendor/github.com/Azure/go-ansiterm/constants.go

This file was deleted.

7 changes: 0 additions & 7 deletions vendor/github.com/Azure/go-ansiterm/context.go

This file was deleted.

49 changes: 0 additions & 49 deletions vendor/github.com/Azure/go-ansiterm/csi_entry_state.go

This file was deleted.

38 changes: 0 additions & 38 deletions vendor/github.com/Azure/go-ansiterm/csi_param_state.go

This file was deleted.

Loading