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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2ccc172
add test for creating odr config with target labels
xiaolin-ninja eaf40ef
runner profile set, list and inspect include labels
xiaolin-ninja 2b57cc0
create queue config op
xiaolin-ninja d794bb4
revise targetrunnerlabels flag on profile set
xiaolin-ninja 3db94bb
runner profile set, list and inspect include labels
xiaolin-ninja 69124c4
tests for targeting by id, remove pre-check for existing runner
xiaolin-ninja 852fc21
fix service job tests target runner id
xiaolin-ninja 48667c2
target by labels server tests
xiaolin-ninja 6b7084c
rm queue config op
xiaolin-ninja e42c59b
changelog
xiaolin-ninja b58a875
organize imports and website gen
xiaolin-ninja File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,8 @@ | ||
```release-note:feature | ||
**Targetable Runners with Labels**: Waypoint now supports runner profiles that target specific on-demand runners by labels. | ||
Projects and/or Apps can be configured to use a specific runner profile, identified by name. | ||
The runner profile will target all operations to a specific on-demand runner by ID, or labels on the runner. | ||
``` | ||
```release-note:improvement | ||
cli: `runner profile` command set now supports target runner labels | ||
``` |
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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/hashicorp/waypoint/internal/clierrors" | ||
"github.com/hashicorp/waypoint/internal/pkg/flag" | ||
pb "github.com/hashicorp/waypoint/pkg/server/gen" | ||
"encoding/json" | ||
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. 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.
|
||
|
||
"github.com/posener/complete" | ||
empty "google.golang.org/protobuf/types/known/emptypb" | ||
|
||
"github.com/hashicorp/waypoint-plugin-sdk/terminal" | ||
empty "google.golang.org/protobuf/types/known/emptypb" | ||
"github.com/hashicorp/waypoint/internal/clierrors" | ||
"github.com/hashicorp/waypoint/internal/pkg/flag" | ||
pb "github.com/hashicorp/waypoint/pkg/server/gen" | ||
) | ||
|
||
type RunnerProfileListCommand struct { | ||
|
@@ -37,7 +38,7 @@ func (c *RunnerProfileListCommand) Run(args []string) int { | |
|
||
c.ui.Output("Runner profiles") | ||
|
||
tbl := terminal.NewTable("Name", "Plugin Type", "OCI Url", "Target Runner ID", | ||
tbl := terminal.NewTable("Name", "Plugin Type", "OCI Url", "Target Runner", | ||
"Default") | ||
|
||
for _, p := range resp.Configs { | ||
|
@@ -53,6 +54,9 @@ func (c *RunnerProfileListCommand) Run(args []string) int { | |
targetRunner = "*" | ||
case *pb.Ref_Runner_Id: | ||
targetRunner = t.Id.Id | ||
case *pb.Ref_Runner_Labels: | ||
s, _ := json.Marshal(t.Labels.Labels) | ||
targetRunner = "labels: " + string(s) | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -5,29 +5,31 @@ import ( | |
"path/filepath" | ||
"strings" | ||
|
||
"github.com/posener/complete" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/hashicorp/hcl/v2" | ||
"github.com/hashicorp/hcl/v2/hclsyntax" | ||
hcljson "github.com/hashicorp/hcl/v2/json" | ||
"github.com/hashicorp/waypoint-plugin-sdk/terminal" | ||
"github.com/hashicorp/waypoint/internal/clierrors" | ||
"github.com/hashicorp/waypoint/internal/pkg/flag" | ||
pb "github.com/hashicorp/waypoint/pkg/server/gen" | ||
"github.com/posener/complete" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
type RunnerProfileSetCommand struct { | ||
*baseCommand | ||
//TODO(XX): after `-env-vars` as a slice is deprecated, rename flagEnvVar to flagEnvVars | ||
flagName string | ||
flagOCIUrl string | ||
flagEnvVar map[string]string | ||
flagEnvVars []string | ||
flagPluginType string | ||
flagPluginConfig string | ||
flagDefault bool | ||
flagTargetRunnerId string | ||
flagName string | ||
flagOCIUrl string | ||
flagEnvVar map[string]string | ||
flagEnvVars []string | ||
flagPluginType string | ||
flagPluginConfig string | ||
flagDefault bool | ||
flagTargetRunnerId string | ||
flagTargetRunnerLabels map[string]string | ||
} | ||
|
||
func (c *RunnerProfileSetCommand) Run(args []string) int { | ||
|
@@ -107,6 +109,18 @@ func (c *RunnerProfileSetCommand) Run(args []string) int { | |
}, | ||
}, | ||
} | ||
if c.flagTargetRunnerLabels != nil { | ||
c.ui.Output("Both -target-runner-id and -target-runner-label detected, only one can be set at a time. ID takes priority.", | ||
terminal.WithWarningStyle()) | ||
} | ||
} else if c.flagTargetRunnerLabels != nil { | ||
od.TargetRunner = &pb.Ref_Runner{ | ||
Target: &pb.Ref_Runner_Labels{ | ||
Labels: &pb.Ref_RunnerLabels{ | ||
Labels: c.flagTargetRunnerLabels, | ||
}, | ||
}, | ||
} | ||
} else { | ||
od.TargetRunner = &pb.Ref_Runner{Target: &pb.Ref_Runner_Any{}} | ||
} | ||
|
@@ -285,7 +299,14 @@ func (c *RunnerProfileSetCommand) Flags() *flag.Sets { | |
Name: "target-runner-id", | ||
Target: &c.flagTargetRunnerId, | ||
Default: "", | ||
Usage: "ID of the remote runner to target for the profile.", | ||
Usage: "ID of the runner to target for this remote runner profile.", | ||
}) | ||
|
||
f.StringMapVar(&flag.StringMapVar{ | ||
Name: "target-runner-label", | ||
Target: &c.flagTargetRunnerLabels, | ||
Usage: "Labels on the runner to target for this remote runner profile. " + | ||
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. Maybe this could use an additional sentence on what labels for targeting is used for? |
||
"e.g. `-target-runner-label=k=v`. Can be specified multiple times.", | ||
}) | ||
}) | ||
} | ||
|
@@ -305,16 +326,12 @@ func (c *RunnerProfileSetCommand) Synopsis() string { | |
func (c *RunnerProfileSetCommand) Help() string { | ||
return formatHelp(` | ||
Usage: waypoint runner profile set [OPTIONS] | ||
|
||
Create or update a runner profile. | ||
|
||
This will register a new runner profile with the given options. If | ||
a runner profile with the same id already exists, this will update the | ||
existing runner profile using the fields that are set. | ||
|
||
Waypoint will use a runner profile to spawn containers for | ||
various kinds of work as needed on the platform requested during any given | ||
lifecycle operation. | ||
|
||
` + c.Flags().Help()) | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 oflist
or something?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.
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.