Skip to content

Commit 80f9c5a

Browse files
authored
Add cluster selector exist operator for empty key value (#21)
Add .idea path to gitignore Signed-off-by: melserngawy <[email protected]>
1 parent 2b6a227 commit 80f9c5a

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ vendor/
2121

2222
# IDE
2323
.vscode
24+
.idea

build/common/config/.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ run:
2727
linters:
2828
enable-all: true
2929
disable:
30+
- nestif
3031
- depguard
3132
- dupl
3233
- gochecknoglobals

internal/plugin.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,13 @@ func (p *Plugin) createPlacementRule(policyConf *types.PolicyConfig) (
540540
matchExpressions := []map[string]interface{}{}
541541
for _, label := range keys {
542542
matchExpression := map[string]interface{}{
543-
"key": label,
544-
"operator": "In",
545-
"values": []string{policyConf.Placement.ClusterSelectors[label]},
543+
"key": label,
544+
}
545+
if policyConf.Placement.ClusterSelectors[label] == "" {
546+
matchExpression["operator"] = "Exist"
547+
} else {
548+
matchExpression["operator"] = "In"
549+
matchExpression["values"] = []string{policyConf.Placement.ClusterSelectors[label]}
546550
}
547551
matchExpressions = append(matchExpressions, matchExpression)
548552
}

internal/plugin_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,9 @@ func TestCreatePlacementRuleClusterSelectors(t *testing.T) {
575575
p.PolicyDefaults.Namespace = "my-policies"
576576
policyConf := types.PolicyConfig{Name: "policy-app-config"}
577577
policyConf.Placement.ClusterSelectors = map[string]string{
578-
"cloud": "red hat",
579-
"game": "pacman",
578+
"cloud": "red hat",
579+
"doesIt": "",
580+
"game": "pacman",
580581
}
581582

582583
name, err := p.createPlacementRule(&policyConf)
@@ -603,6 +604,8 @@ spec:
603604
operator: In
604605
values:
605606
- red hat
607+
- key: doesIt
608+
operator: Exist
606609
- key: game
607610
operator: In
608611
values:

0 commit comments

Comments
 (0)