Skip to content

Discover EKS: allow custom labels for Kube Server#49420

Merged
marcoandredinis merged 1 commit intomasterfrom
marco/discover_eks_extra_labels
Dec 11, 2024
Merged

Discover EKS: allow custom labels for Kube Server#49420
marcoandredinis merged 1 commit intomasterfrom
marco/discover_eks_extra_labels

Conversation

@marcoandredinis
Copy link
Copy Markdown
Contributor

@marcoandredinis marcoandredinis commented Nov 25, 2024

This PR allows the UI to send extra labels for setting up the EKS cluster.

Related #46976

Demo

$ curl 'https://lenix.marcoandredinis.com/v1/webapi/sites/lenix.marcoandredinis.com/integrations/aws-oidc/teleportdev/enrolleksclusters' \
--data-raw '{"region":"eu-west-2","enableAppDiscovery":true,"clusterNames":["MarcoEKSCustomLabels01"], "extraLabels":[{"name":"marco-label-key", "value":"marco-label-value"}]}'
image

@marcoandredinis marcoandredinis added discover Issues related to Teleport Discover no-changelog Indicates that a PR does not require a changelog entry backport/branch/v16 backport/branch/v17 labels Nov 25, 2024
@marcoandredinis marcoandredinis marked this pull request as ready for review November 25, 2024 18:38
@marcoandredinis marcoandredinis force-pushed the marco/discover_eks_extra_labels branch 4 times, most recently from f2be289 to 55a8e42 Compare December 2, 2024 11:00
@marcoandredinis
Copy link
Copy Markdown
Contributor Author

@doggydogworld @timothyb89 Can you please take a look when you get a chance?

Copy link
Copy Markdown
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with a question/suggestion

Comment on lines +705 to +706
maps.Copy(labels, extraLabels)
maps.Copy(labels, kubeCluster.GetStaticLabels())
Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Contributor Author

@marcoandredinis marcoandredinis Dec 6, 2024

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?

Yes 👍

In that case, should user-defined labels take precedence, i.e. should we swap the order of these two copies?

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:

  • Cloud Labels
  • ServerInfo Labels
  • Static Labels
    func (s *Server) getStaticLabels() map[string]string {
    labels := make(map[string]string, len(s.labels))
    if s.cloudLabels != nil {
    maps.Copy(labels, s.cloudLabels.Get())
    }
    // Let labels sent over ics override labels from instance metadata.
    if s.inventoryHandle != nil {
    maps.Copy(labels, s.inventoryHandle.GetUpstreamLabels(proto.LabelUpdateKind_SSHServerCloudLabels))
    }
    // Let static labels override any other labels.
    maps.Copy(labels, s.labels)
    return labels
    }

Static labels end up being the last to be applied.

Having said that, I'm ok changing the order 👍

@marcoandredinis marcoandredinis force-pushed the marco/discover_eks_extra_labels branch 3 times, most recently from 379aa3f to 9178e6c Compare December 10, 2024 11:36
"priority": "yes",
"region": "us-east-1",
}
resourceID := uuid.NewString()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to use UUID generation for testing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use whatever value here 👍
Is it bad to use it? I was trying to use a real value here instead of a static one.

return nil, trace.Wrap(err)
}

extraLabels := make(map[string]string, len(req.ExtraLabels))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use maps.Clone instead? Since maps.Copy is used I think it might make it more consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req.ExtraLabels format is not a map.
It's a []ui.Label where ui.Label is a struct with Name, Value.

So, I don't think we can use maps.Clone here

Copy link
Copy Markdown
Contributor

@doggydogworld doggydogworld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits otherwise lgtm.

This PR allows the UI to send extra labels for setting up the EKS
cluster.
@marcoandredinis marcoandredinis force-pushed the marco/discover_eks_extra_labels branch from 9178e6c to 1c601d1 Compare December 11, 2024 09:46
@marcoandredinis marcoandredinis added this pull request to the merge queue Dec 11, 2024
Merged via the queue into master with commit 0e1f1bc Dec 11, 2024
@marcoandredinis marcoandredinis deleted the marco/discover_eks_extra_labels branch December 11, 2024 10:25
@public-teleport-github-review-bot
Copy link
Copy Markdown

@marcoandredinis See the table below for backport results.

Branch Result
branch/v16 Failed
branch/v17 Create PR

marcoandredinis added a commit that referenced this pull request Dec 11, 2024
This PR allows the UI to send extra labels for setting up the EKS
cluster.
marcoandredinis added a commit that referenced this pull request Dec 11, 2024
This PR allows the UI to send extra labels for setting up the EKS
cluster.
marcoandredinis added a commit that referenced this pull request Dec 17, 2024
This PR allows the UI to send extra labels for setting up the EKS
cluster.
github-merge-queue Bot pushed a commit that referenced this pull request Dec 17, 2024
This PR allows the UI to send extra labels for setting up the EKS
cluster.
carloscastrojumo pushed a commit to carloscastrojumo/teleport that referenced this pull request Feb 19, 2025
This PR allows the UI to send extra labels for setting up the EKS
cluster.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/branch/v17 discover Issues related to Teleport Discover no-changelog Indicates that a PR does not require a changelog entry size/sm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants