forked from projectcapsule/capsule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbidden node labels and annotations (projectcapsule#464)
* feat: forbidden node labels and annotations * test(e2e): forbidden node labels and annotations * build(kustomize): forbidden node labels and annotations * build(helm): forbidden node labels and annotations * build(installer): forbidden node labels and annotations * chore(make): forbidden node labels and annotations * docs: forbidden node labels and annotations * test(e2e): forbidden node labels and annotations. Use EventuallyCreation func * feat: forbidden node labels and annotations. Check kubernetes version * test(e2e): forbidden node labels and annotations. Check kubernetes version * docs: forbidden node labels and annotations. Version restrictions * feat: forbidden node labels and annotations. Do not update deepcopy functions * docs: forbidden node labels and annotations. Use blockquotes for notes Co-authored-by: Maksim Fedotov <[email protected]>
- Loading branch information
Showing
23 changed files
with
862 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package v1alpha1 | ||
|
||
const ( | ||
ForbiddenNodeLabelsAnnotation = "capsule.clastix.io/forbidden-node-labels" | ||
ForbiddenNodeLabelsRegexpAnnotation = "capsule.clastix.io/forbidden-node-labels-regexp" | ||
ForbiddenNodeAnnotationsAnnotation = "capsule.clastix.io/forbidden-node-annotations" | ||
ForbiddenNodeAnnotationsRegexpAnnotation = "capsule.clastix.io/forbidden-node-annotations-regexp" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2020-2021 Clastix Labs | ||
// SPDX-License-Identifier: Apache-2.0 | ||
//nolint:dupl | ||
package v1beta1 | ||
|
||
import ( | ||
"regexp" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
type ForbiddenListSpec struct { | ||
Exact []string `json:"denied,omitempty"` | ||
Regex string `json:"deniedRegex,omitempty"` | ||
} | ||
|
||
func (in *ForbiddenListSpec) ExactMatch(value string) (ok bool) { | ||
if len(in.Exact) > 0 { | ||
sort.SliceStable(in.Exact, func(i, j int) bool { | ||
return strings.ToLower(in.Exact[i]) < strings.ToLower(in.Exact[j]) | ||
}) | ||
i := sort.SearchStrings(in.Exact, value) | ||
ok = i < len(in.Exact) && in.Exact[i] == value | ||
} | ||
return | ||
} | ||
|
||
func (in ForbiddenListSpec) RegexMatch(value string) (ok bool) { | ||
if len(in.Regex) > 0 { | ||
ok = regexp.MustCompile(in.Regex).MatchString(value) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2020-2021 Clastix Labs | ||
// SPDX-License-Identifier: Apache-2.0 | ||
//nolint:dupl | ||
package v1beta1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestForbiddenListSpec_ExactMatch(t *testing.T) { | ||
type tc struct { | ||
In []string | ||
True []string | ||
False []string | ||
} | ||
for _, tc := range []tc{ | ||
{ | ||
[]string{"foo", "bar", "bizz", "buzz"}, | ||
[]string{"foo", "bar", "bizz", "buzz"}, | ||
[]string{"bing", "bong"}, | ||
}, | ||
{ | ||
[]string{"one", "two", "three"}, | ||
[]string{"one", "two", "three"}, | ||
[]string{"a", "b", "c"}, | ||
}, | ||
{ | ||
nil, | ||
nil, | ||
[]string{"any", "value"}, | ||
}, | ||
} { | ||
a := ForbiddenListSpec{ | ||
Exact: tc.In, | ||
} | ||
for _, ok := range tc.True { | ||
assert.True(t, a.ExactMatch(ok)) | ||
} | ||
for _, ko := range tc.False { | ||
assert.False(t, a.ExactMatch(ko)) | ||
} | ||
} | ||
} | ||
|
||
func TestForbiddenListSpec_RegexMatch(t *testing.T) { | ||
type tc struct { | ||
Regex string | ||
True []string | ||
False []string | ||
} | ||
for _, tc := range []tc{ | ||
{`first-\w+-pattern`, []string{"first-date-pattern", "first-year-pattern"}, []string{"broken", "first-year", "second-date-pattern"}}, | ||
{``, nil, []string{"any", "value"}}, | ||
} { | ||
a := ForbiddenListSpec{ | ||
Regex: tc.Regex, | ||
} | ||
for _, ok := range tc.True { | ||
assert.True(t, a.RegexMatch(ok)) | ||
} | ||
for _, ko := range tc.False { | ||
assert.False(t, a.RegexMatch(ko)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.