-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow labels to be copied to delegate pods without prefix (#213)
Signed-off-by: Marwan Ahmed <[email protected]> Signed-off-by: Adrien Trouillaud <[email protected]> Co-authored-by: Adrien Trouillaud <[email protected]>
- Loading branch information
Showing
5 changed files
with
153 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: Pod Configuration | ||
custom_edit_url: https://github.com/admiraltyio/admiralty/edit/master/docs/user_guide/pod_configuration.md | ||
--- | ||
|
||
|
||
## Label Prefixing | ||
Admiralty prefixes delegate pod labels with `multicluster.admiralty.io/` in the target clusters. This behavior is useful in bursting cluster topologies, where the source cluster is also a target cluster, so as not to confuse controllers of proxy pods, e.g., replicasets. The behavior | ||
can be overridden per pod through the `multicluster.admiralty.io/no-prefix-label-regexp` annotation. This is useful to | ||
support components that have functionality that relies on pod labels. For example, webhooks or monitoring resources. | ||
|
||
|
||
:::tip | ||
One use-case is to prevent prefixing the Kueue queue name label. This can be achieved through: | ||
``` | ||
multicluster.admiralty.io/no-prefix-label-regexp="^kueue\.x-k8s\.io\/queue-name" | ||
``` | ||
::: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright The Multicluster-Scheduler Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package delegatepod | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestChangeLabels(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputLabels map[string]string | ||
noPrefixLabelRegex string | ||
outputLabels map[string]string | ||
expectedErr error | ||
}{ | ||
{ | ||
name: "mix of keys, no skip", | ||
inputLabels: map[string]string{ | ||
"foo.com/bar": "a", | ||
"baz.com/foo": "b", | ||
"multicluster.admiralty.io/baz": "c", | ||
"a": "d", | ||
}, | ||
noPrefixLabelRegex: "", | ||
outputLabels: map[string]string{ | ||
"multicluster.admiralty.io/bar": "a", | ||
"multicluster.admiralty.io/foo": "b", | ||
"multicluster.admiralty.io/baz": "c", | ||
"multicluster.admiralty.io/a": "d", | ||
}, | ||
}, | ||
{ | ||
name: "skip multiple keys", | ||
inputLabels: map[string]string{ | ||
"foo.com/bar": "a", | ||
"baz.com/foo": "b", | ||
"multicluster.admiralty.io/foo": "c", | ||
"a": "d", | ||
}, | ||
noPrefixLabelRegex: "foo.com/bar|baz.com/foo", | ||
outputLabels: map[string]string{ | ||
"foo.com/bar": "a", | ||
"baz.com/foo": "b", | ||
"multicluster.admiralty.io/foo": "c", | ||
"multicluster.admiralty.io/a": "d", | ||
}, | ||
}, | ||
{ | ||
name: "skip key/value pair", | ||
inputLabels: map[string]string{ | ||
"foo.com/bar": "a", | ||
"baz.com/foo": "b", | ||
"a": "d", | ||
}, | ||
noPrefixLabelRegex: "^a=d$", | ||
outputLabels: map[string]string{ | ||
"multicluster.admiralty.io/bar": "a", | ||
"multicluster.admiralty.io/foo": "b", | ||
"a": "d", | ||
}, | ||
}, | ||
{ | ||
name: "skip value", | ||
inputLabels: map[string]string{ | ||
"foo.com/bar": "skip", | ||
}, | ||
noPrefixLabelRegex: "^.*=skip$", | ||
outputLabels: map[string]string{ | ||
"foo.com/bar": "skip", | ||
}, | ||
}, | ||
{ | ||
name: "invalid regex lookahead", | ||
inputLabels: map[string]string{ | ||
"foo.com/bar": "a", | ||
}, | ||
noPrefixLabelRegex: "?!foo", | ||
outputLabels: nil, | ||
expectedErr: errors.New("invalid regex"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
out, _, err := ChangeLabels(tt.inputLabels, tt.noPrefixLabelRegex) | ||
if tt.expectedErr != nil { | ||
require.Error(t, err) | ||
} | ||
require.Equal(t, tt.outputLabels, out) | ||
}) | ||
} | ||
} |