-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Discover EKS: allow custom labels for Kube Server #49420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |
| eksTypes "github.com/aws/aws-sdk-go-v2/service/eks/types" | ||
| "github.com/aws/aws-sdk-go-v2/service/sts" | ||
| "github.com/aws/smithy-go/middleware" | ||
| "github.com/google/uuid" | ||
| "github.com/gravitational/trace" | ||
| "github.com/jonboulle/clockwork" | ||
| "github.com/stretchr/testify/require" | ||
|
|
@@ -621,3 +622,29 @@ func (m *mockEnrollEKSClusterClient) PresignGetCallerIdentityURL(ctx context.Con | |
| } | ||
|
|
||
| var _ EnrollEKSCLusterClient = &mockEnrollEKSClusterClient{} | ||
|
|
||
| func TestKubeAgentLabels(t *testing.T) { | ||
| kubeClusterLabels := map[string]string{ | ||
| "priority": "yes", | ||
| "region": "us-east-1", | ||
| } | ||
| resourceID := uuid.NewString() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to use UUID generation for testing?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use whatever value here 👍 |
||
| extraLabels := map[string]string{ | ||
| "priority": "no", | ||
| "custom": "yes", | ||
| } | ||
|
|
||
| got := kubeAgentLabels( | ||
| &types.KubernetesClusterV3{Metadata: types.Metadata{Labels: kubeClusterLabels}}, | ||
| resourceID, | ||
| extraLabels, | ||
| ) | ||
|
|
||
| expectedLabels := map[string]string{ | ||
| "priority": "yes", | ||
| "region": "us-east-1", | ||
| "custom": "yes", | ||
| "teleport.internal/resource-id": resourceID, | ||
| } | ||
| require.Equal(t, expectedLabels, got) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -534,12 +534,18 @@ func (h *Handler) awsOIDCEnrollEKSClusters(w http.ResponseWriter, r *http.Reques | |
| return nil, trace.Wrap(err) | ||
| } | ||
|
|
||
| extraLabels := make(map[string]string, len(req.ExtraLabels)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So, I don't think we can use |
||
| for _, label := range req.ExtraLabels { | ||
| extraLabels[label.Name] = label.Value | ||
| } | ||
|
|
||
| response, err := clt.IntegrationAWSOIDCClient().EnrollEKSClusters(ctx, &integrationv1.EnrollEKSClustersRequest{ | ||
| Integration: integrationName, | ||
| Region: req.Region, | ||
| EksClusterNames: req.ClusterNames, | ||
| EnableAppDiscovery: req.EnableAppDiscovery, | ||
| AgentVersion: agentVersion, | ||
| ExtraLabels: extraLabels, | ||
| }) | ||
| if err != nil { | ||
| return nil, trace.Wrap(err) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume "extraLabels" are basically user-provided labels and "static labels" are labels from EKS tags, correct? In that case, should user-defined labels take precedence, i.e. should we swap the order of these two copies?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍
My assumption was that we want static/cloud labels to always be applied after the custom ones, preventing any override of values such as the AWS Account ID/Region.
I looked into how Teleport Server + ServerInfo labels and it seems that its order is:
teleport/lib/srv/regular/sshserver.go
Lines 1026 to 1040 in 4846ef4
Static labels end up being the last to be applied.
Having said that, I'm ok changing the order 👍