Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

feature: Enable runner targeting by labels specified in runner profile #3145

Merged
merged 11 commits into from Mar 28, 2022

Conversation

xiaolin-ninja
Copy link
Contributor

@xiaolin-ninja xiaolin-ninja commented Mar 25, 2022

Another piece of the targetable runners puzzle.

This PR adds tests for job successfully queued and targeted, and CLI changes to allow creation of runner profiles with labels.
It also makes an important choice to allow definition of a runner profiles that targets a runner that does not exist yet. (Previous iteration of targetable runners did not allow this.)

❯ waypoint-dev runner profile set -name=efgh -target-runner-label=env=test -target-runner-label=region=testland -plugin-type=kubernetes
✓ Runner profile created
❯ waypoint-dev runner profile set -name=efgh -target-runner-label=env=test -target-runner-id=test -plugin-type=kubernetes 
✓ Runner profile updated
Both -target-runner-id and -target-runner-label detected, only one can be set at a time. ID takes priority.
❯ waypoint-dev runner profile list
Runner profiles
NAME | PLUGIN TYPE |            OCI URL            |               TARGET RUNNER                | DEFAULT  
-----+-------------+-------------------------------+--------------------------------------------+----------
1234 | kubernetes  | hashicorp/waypoint-odr:latest | *                                          | yes
abcd | kubernetes  | hashicorp/waypoint-odr:latest | test                                       |
efgh | kubernetes  | hashicorp/waypoint-odr:latest | labels: {"env":"test","region":"testland"} |    
❯ waypoint-dev runner profile inspect efgh

» Runner profile:
                   Name: efgh
                     ID: 01FYZBPNEWXEP00W5ZWN78XVD9
                Default: false
                OCI URL: hashicorp/waypoint-odr:latest
            Plugin Type: kubernetes
   Target Runner: labels: {"env":"test","region":"testland"}
  Environment Variables: map[]

@xiaolin-ninja
Copy link
Contributor Author

Connected to:
#3133
#3132

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Just a few nitpicks. Approved!

@@ -106,6 +109,9 @@ func (c *RunnerProfileInspectCommand) Run(args []string) int {
{
Name: "Target Runner ID", Value: targetRunner,
},
{
Name: "Target Runner Labels", Value: targetRunnerLabels,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but a target runner can have only one of any, id, or lables, so should this be one field that is like Target: instead that follows the format of list or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm that's a good point actually, right now it's not hard-coded to restrict only one of ID or Labels (so you could define both), but ID always takes precedence over labels. I think I was thinking at one point "if they define both, but we can't find the runner by ID, then we take the labels instead". But since we ended up removing that "runner with this ID" exists check, we should allow only ID or Label, not both.

@@ -1,6 +1,7 @@
package cli

import (
"encoding/json"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, across the project we typically do the pattern below, so we should have a newline between this and the next imports. Lots of tools automatically insert and break this once in awhile, not a big deal usually just manually clean it up.

import (
  stdlib

  external

  internal
)

Name: "target-runner-label",
Target: &c.flagTargetRunnerLabels,
Usage: "Labels on the runner to target for this remote runner profile. " +
"e.g. `-target-runner-labels=k=v`. Can be specified multiple times.",
Copy link
Contributor

Choose a reason for hiding this comment

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

plural to singular here

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me! 👍🏻 I'll let Mitchell chime in since he was following the previous puzzle pieces, but overall makes sense to me. (edit: he beat me by 5 minutes! 😂 )

f.StringMapVar(&flag.StringMapVar{
Name: "target-runner-label",
Target: &c.flagTargetRunnerLabels,
Usage: "Labels on the runner to target for this remote runner profile. " +
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this could use an additional sentence on what labels for targeting is used for?

PluginType: "magic-carpet",
PluginConfig: []byte("foo = 1"),
EnvironmentVariables: map[string]string{
"CARPET_DRIVER": "apu",
Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: targetable runners
3 participants