Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sriteja-Tadakaluru authored and Sriteja TADAKALURU committed Dec 29, 2024
2 parents a88dca0 + 26ebb9b commit f248068
Show file tree
Hide file tree
Showing 102 changed files with 1,430 additions and 1,060 deletions.
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ linters-settings:
# Optimizes even if it requires an int or uint type cast.
int-conversion: true
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
err-error: false
err-error: true
# Optimizes `fmt.Errorf`.
errorf: false
# Optimizes `fmt.Sprintf` with only one argument.
sprintf1: true
# Optimizes into strings concatenation.
strconcat: false
strconcat: true
testifylint:
enable-all: true
disable:
Expand Down
4 changes: 2 additions & 2 deletions applicationset/generators/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ func (g *ClusterGenerator) GenerateParams(appSetGenerator *argoappsetv1alpha1.Ap
params["metadata"] = meta
} else {
for key, value := range cluster.ObjectMeta.Annotations {
params[fmt.Sprintf("metadata.annotations.%s", key)] = value
params["metadata.annotations."+key] = value
}

for key, value := range cluster.ObjectMeta.Labels {
params[fmt.Sprintf("metadata.labels.%s", key)] = value
params["metadata.labels."+key] = value
}
}

Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/duck_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (g *DuckTypeGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.A
}
params["values"].(map[string]string)[key] = value
} else {
params[fmt.Sprintf("values.%s", key)] = value
params["values."+key] = value
}
}

Expand Down
7 changes: 3 additions & 4 deletions applicationset/generators/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (g *GitGenerator) generateParamsForGitFiles(appSetGenerator *argoprojiov1al
if err != nil {
return nil, err
}
if requestedPath.FileSelector != nil {
if requestedPath.FileLabelSelector != nil {
for filePath, content := range files {
objects := map[string]interface{}{}
err := yaml.Unmarshal(content, &objects)
Expand All @@ -154,10 +154,9 @@ func (g *GitGenerator) generateParamsForGitFiles(appSetGenerator *argoprojiov1al
}
}

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

if selector.Matches(labelSet) {
Expand Down
295 changes: 295 additions & 0 deletions applicationset/generators/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,301 @@ cluster:
},
expectedError: nil,
},
{
name: "create params from git files using matchLabels",
files: []argoprojiov1alpha1.GitFileGeneratorItem{{
Path: "**/config.json",
FileLabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"cluster.name": "production",
"key1": "val1",
},
},
}},
repoFileContents: map[string][]byte{
"cluster-config/production/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "production",
"address": "https://kubernetes.default.svc"
},
"key1": "val1",
"key2": {
"key2_1": "val2_1",
"key2_2": {
"key2_2_1": "val2_2_1"
}
},
"key3": 123
}`),
"cluster-config/staging/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "staging",
"address": "https://kubernetes.default.svc"
}
}`),
},
repoPathsError: nil,
expected: []map[string]interface{}{
{
"cluster.owner": "[email protected]",
"cluster.name": "production",
"cluster.address": "https://kubernetes.default.svc",
"key1": "val1",
"key2.key2_1": "val2_1",
"key2.key2_2.key2_2_1": "val2_2_1",
"key3": "123",
"path": "cluster-config/production",
"path.basename": "production",
"path[0]": "cluster-config",
"path[1]": "production",
"path.basenameNormalized": "production",
"path.filename": "config.json",
"path.filenameNormalized": "config.json",
},
},
expectedError: nil,
},
{
name: "create params from git files using matchExpressions",
files: []argoprojiov1alpha1.GitFileGeneratorItem{{
Path: "**/config.json",
FileLabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{Key: "cluster.name", Operator: metav1.LabelSelectorOpIn, Values: []string{"production", "test"}},
},
},
}},
repoFileContents: map[string][]byte{
"cluster-config/production/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "production",
"address": "https://kubernetes.default.svc"
},
"key1": "val1",
"key2": {
"key2_1": "val2_1",
"key2_2": {
"key2_2_1": "val2_2_1"
}
},
"key3": 123
}`),
"cluster-config/staging/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "staging",
"address": "https://kubernetes.default.svc"
}
}`),
"cluster-config/test/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "test",
"address": "https://kubernetes.default.svc"
},
"key1": "val1",
"key2": {
"key2_1": "val2_1",
"key2_2": {
"key2_2_1": "val2_2_1"
}
},
"key3": 123,
"key4": "val4",
}`),
},
repoPathsError: nil,
expected: []map[string]interface{}{
{
"cluster.owner": "[email protected]",
"cluster.name": "production",
"cluster.address": "https://kubernetes.default.svc",
"key1": "val1",
"key2.key2_1": "val2_1",
"key2.key2_2.key2_2_1": "val2_2_1",
"key3": "123",
"path": "cluster-config/production",
"path.basename": "production",
"path[0]": "cluster-config",
"path[1]": "production",
"path.basenameNormalized": "production",
"path.filename": "config.json",
"path.filenameNormalized": "config.json",
},
{
"cluster.owner": "[email protected]",
"cluster.name": "test",
"cluster.address": "https://kubernetes.default.svc",
"key1": "val1",
"key2.key2_1": "val2_1",
"key2.key2_2.key2_2_1": "val2_2_1",
"key3": "123",
"key4": "val4",
"path": "cluster-config/test",
"path.basename": "test",
"path[0]": "cluster-config",
"path[1]": "test",
"path.basenameNormalized": "test",
"path.filename": "config.json",
"path.filenameNormalized": "config.json",
},
},
expectedError: nil,
},
{
name: "create params from git files matchLabels and matchExpressions",
files: []argoprojiov1alpha1.GitFileGeneratorItem{{
Path: "**/config.json",
FileLabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{Key: "cluster.name", Operator: metav1.LabelSelectorOpIn, Values: []string{"production", "test"}},
},
MatchLabels: map[string]string{
"key4": "val4",
},
},
}},
repoFileContents: map[string][]byte{
"cluster-config/production/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "production",
"address": "https://kubernetes.default.svc"
},
"key1": "val1",
"key2": {
"key2_1": "val2_1",
"key2_2": {
"key2_2_1": "val2_2_1"
}
},
"key3": 123
}`),
"cluster-config/staging/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "staging",
"address": "https://kubernetes.default.svc"
}
}`),
"cluster-config/test/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "test",
"address": "https://kubernetes.default.svc"
},
"key1": "val1",
"key2": {
"key2_1": "val2_1",
"key2_2": {
"key2_2_1": "val2_2_1"
}
},
"key3": 123,
"key4": "val4",
}`),
},
repoPathsError: nil,
expected: []map[string]interface{}{
{
"cluster.owner": "[email protected]",
"cluster.name": "test",
"cluster.address": "https://kubernetes.default.svc",
"key1": "val1",
"key2.key2_1": "val2_1",
"key2.key2_2.key2_2_1": "val2_2_1",
"key3": "123",
"key4": "val4",
"path": "cluster-config/test",
"path.basename": "test",
"path[0]": "cluster-config",
"path[1]": "test",
"path.basenameNormalized": "test",
"path.filename": "config.json",
"path.filenameNormalized": "config.json",
},
},
expectedError: nil,
},
{
name: "invalid value for matchLabels",
files: []argoprojiov1alpha1.GitFileGeneratorItem{{
Path: "**/config.json",
FileLabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"cluster.owner": "[email protected]",
},
},
}},
repoFileContents: map[string][]byte{
"cluster-config/production/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "production",
"address": "https://kubernetes.default.svc"
},
"key1": "val1",
"key2": {
"key2_1": "val2_1",
"key2_2": {
"key2_2_1": "val2_2_1"
}
},
"key3": 123
}`),
"cluster-config/staging/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "staging",
"address": "https://kubernetes.default.svc"
}
}`),
},
repoPathsError: nil,
expected: []map[string]interface{}{},
expectedError: fmt.Errorf("error generating params from git: error parsing the label selector: values[0][cluster.owner]: Invalid value: \"[email protected]\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')"),
},
{
name: "test no match found",
files: []argoprojiov1alpha1.GitFileGeneratorItem{{
Path: "**/config.json",
FileLabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"cluster.owner": "test-owner",
},
},
}},
repoFileContents: map[string][]byte{
"cluster-config/production/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "production",
"address": "https://kubernetes.default.svc"
},
"key1": "val1",
"key2": {
"key2_1": "val2_1",
"key2_2": {
"key2_2_1": "val2_2_1"
}
},
"key3": 123
}`),
"cluster-config/staging/config.json": []byte(`{
"cluster": {
"owner": "[email protected]",
"name": "staging",
"address": "https://kubernetes.default.svc"
}
}`),
},
repoPathsError: nil,
expected: []map[string]interface{}{},
expectedError: nil,
},
}

for _, testCase := range cases {
Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (g *ListGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.Appli
if !ok {
return nil, fmt.Errorf("error parsing value as string %w", err)
}
params[fmt.Sprintf("values.%s", k)] = value
params["values."+k] = value
}
} else {
v, ok := value.(string)
Expand Down
2 changes: 1 addition & 1 deletion applicationset/generators/value_interpolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func appendTemplatedValues(values map[string]string, params map[string]interface
}
tmp["values"].(map[string]string)[key] = result
} else {
tmp[fmt.Sprintf("values.%s", key)] = result
tmp["values."+key] = result
}
}

Expand Down
3 changes: 1 addition & 2 deletions applicationset/services/plugin/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package plugin

import (
"fmt"
"strings"

"github.com/argoproj/argo-cd/v2/common"
Expand All @@ -12,7 +11,7 @@ func ParseSecretKey(key string) (secretName string, tokenKey string) {
if strings.Contains(key, ":") {
parts := strings.Split(key, ":")
secretName = parts[0][1:]
tokenKey = fmt.Sprintf("$%s", parts[1])
tokenKey = "$" + parts[1]
} else {
secretName = common.ArgoCDSecretName
tokenKey = key
Expand Down
Loading

0 comments on commit f248068

Please sign in to comment.