Skip to content

Commit

Permalink
Add fileSelector to the GitFileGenerator to support label-based file …
Browse files Browse the repository at this point in the history
…match

Signed-off-by: Sriteja TADAKALURU <[email protected]>
  • Loading branch information
Sriteja TADAKALURU committed Dec 21, 2024
1 parent 8841b0d commit 578e5d1
Show file tree
Hide file tree
Showing 13 changed files with 1,395 additions and 745 deletions.
41 changes: 39 additions & 2 deletions applicationset/generators/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

"github.com/jeremywohl/flatten"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -130,9 +132,44 @@ func (g *GitGenerator) generateParamsForGitFiles(appSetGenerator *argoprojiov1al
if err != nil {
return nil, err
}
for filePath, content := range files {
allFiles[filePath] = content
if requestedPath.FileSelector != nil {
for filePath, content := range files {
objects := map[string]interface{}{}
err := yaml.Unmarshal(content, &objects)
if err != nil {
log.Printf("unable to parse the file: %v", err)
continue
}

flat, err := flatten.Flatten(objects, "", flatten.DotStyle)
if err != nil {
log.Printf("error flattening the object: %v", err)
continue
}

labelSet := make(labels.Set)
for k, v := range flat {
if strVal, ok := v.(string); ok {
labelSet[k] = strVal
}
}

selector, err := metav1.LabelSelectorAsSelector(requestedPath.FileSelector)
if err != nil {
log.Printf("error parsing the label selector: %v", err)
continue
}

if selector.Matches(labelSet) {
allFiles[filePath] = content
}
}
} else {
for filePath, content := range files {
allFiles[filePath] = content
}
}

}

Check failure on line 173 in applicationset/generators/git.go

View workflow job for this annotation

GitHub Actions / Lint Go code

unnecessary trailing newline (whitespace)

// Extract the unduplicated map into a list, and sort by path to ensure a deterministic
Expand Down
3 changes: 3 additions & 0 deletions assets/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions manifests/core-install-with-hydrator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7142,6 +7142,32 @@ spec:
files:
items:
properties:
fileSelector:
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
path:
type: string
required:
Expand Down Expand Up @@ -9812,6 +9838,32 @@ spec:
files:
items:
properties:
fileSelector:
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
path:
type: string
required:
Expand Down Expand Up @@ -15562,6 +15614,32 @@ spec:
files:
items:
properties:
fileSelector:
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
path:
type: string
required:
Expand Down
78 changes: 78 additions & 0 deletions manifests/core-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions manifests/crds/applicationset-crd.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 578e5d1

Please sign in to comment.