Skip to content

Commit

Permalink
refactor!(domains/kubernetes): #388 ResourceRule.Field is now a point…
Browse files Browse the repository at this point in the history
…er and has omitempty tag
  • Loading branch information
mike-winberry committed May 16, 2024
1 parent 1200f08 commit 13d384a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/pkg/domains/kubernetes/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func GetResourcesDynamically(ctx context.Context,
return nil, err
}
// If field is specified, get the field data
if resource.Field.Jsonpath != "" {
if resource.Field != nil && resource.Field.Jsonpath != "" {
item, err = getFieldValue(item, resource.Field)
if err != nil {
return nil, err
Expand Down Expand Up @@ -161,8 +161,10 @@ func reduceByName(name string, items []unstructured.Unstructured) (map[string]in
}

// getFieldValue() looks up the field from a resource and returns a map[string]interface{} representation of the data
func getFieldValue(item map[string]interface{}, field Field) (map[string]interface{}, error) {

func getFieldValue(item map[string]interface{}, field *Field) (map[string]interface{}, error) {
if field == nil {
return nil, fmt.Errorf("field is nil")
}
// Identify the field in item
pathParts := strings.Split(field.Jsonpath, ".")[1:]
current := item
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/domains/kubernetes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type ResourceRule struct {
Version string `json:"version" yaml:"version"`
Resource string `json:"resource" yaml:"resource"`
Namespaces []string `json:"namespaces" yaml:"namespaces"`
Field Field `json:"field" yaml:"field"`
Field *Field `json:"field,omitempty" yaml:"field,omitempty"`
}

type FieldType string
Expand Down

0 comments on commit 13d384a

Please sign in to comment.