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

Commit

Permalink
Merge pull request #3897 from hashicorp/backport/fix-k8s-static-runne…
Browse files Browse the repository at this point in the history
…r-image/incredibly-magnetic-pig

This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-waypoint authored Sep 16, 2022
2 parents 499c92e + 0952c3e commit 34f4a25
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .changelog/3890.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
runner-install/kubernetes: Fix the static runner image used in the `waypoint runner install` command
```
4 changes: 3 additions & 1 deletion internal/cli/runner_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
empty "google.golang.org/protobuf/types/known/emptypb"

"github.com/hashicorp/waypoint-plugin-sdk/terminal"

"github.com/hashicorp/waypoint/internal/clierrors"
"github.com/hashicorp/waypoint/internal/installutil"
"github.com/hashicorp/waypoint/internal/pkg/flag"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (c *RunnerInstallCommand) Flags() *flag.Sets {
f.StringVar(&flag.StringVar{
Name: "odr-image",
Usage: "Docker image for the on-demand runners.",
Default: installutil.DefaultRunnerImage,
Default: installutil.DefaultODRImage,
Target: &c.runnerProfileOdrImage,
})

Expand Down Expand Up @@ -288,6 +289,7 @@ func (c *RunnerInstallCommand) Run(args []string) int {
if odc, ok := p.(installutil.OnDemandRunnerConfigProvider); ok {
odrConfig = odc.OnDemandRunnerConfig()
odrConfig.Name = odrConfig.Name + "-" + strings.ToUpper(id)
odrConfig.OciUrl = c.runnerProfileOdrImage // Use what we got from flags (or the default)
} else {
odrConfig = &pb.OnDemandRunnerConfig{
Name: platform[0] + "-" + strings.ToUpper(id),
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/runner_profile_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
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/installutil"
"github.com/hashicorp/waypoint/internal/pkg/flag"
Expand Down Expand Up @@ -257,7 +258,7 @@ func (c *RunnerProfileSetCommand) Flags() *flag.Sets {
f.StringVar(&flag.StringVar{
Name: "oci-url",
Target: &c.flagOCIUrl,
Default: installutil.DefaultRunnerImage,
Default: installutil.DefaultODRImage,
Usage: "The url for the OCI image to launch for the on-demand runner.",
})

Expand Down
3 changes: 2 additions & 1 deletion internal/cli/server_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/hashicorp/go-version"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"

"github.com/hashicorp/waypoint/builtin/k8s"
clientpkg "github.com/hashicorp/waypoint/internal/client"
"github.com/hashicorp/waypoint/internal/clierrors"
Expand Down Expand Up @@ -431,7 +432,7 @@ func (c *ServerUpgradeCommand) upgradeRunner(
} else {
ociUrl := odr.OciUrl
if ociUrl == "" {
ociUrl = installutil.DefaultRunnerImage
ociUrl = installutil.DefaultODRImage
}
odr = &pb.OnDemandRunnerConfig{
Id: oldRunnerConfig.Config.Id,
Expand Down
11 changes: 7 additions & 4 deletions internal/installutil/odr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"fmt"

"github.com/distribution/distribution/v3/reference"

pb "github.com/hashicorp/waypoint/pkg/server/gen"
)

// DefaultODRImage returns the default Waypoint ODR image based on the
// DeriveDefaultODRImage returns the default Waypoint ODR image based on the
// supplied server image. We default the ODR image to the name of the server
// image with the `-odr` suffix attached to it.
func DefaultODRImage(serverImage string) (string, error) {
func DeriveDefaultODRImage(serverImage string) (string, error) {
image, err := reference.Parse(serverImage)
if err != nil {
return "", fmt.Errorf("server image name %q is not a valid oci reference: %s", serverImage, err)
Expand All @@ -29,11 +30,13 @@ func DefaultODRImage(serverImage string) (string, error) {
return fmt.Sprintf("%s-odr:%s", imageName, tag), nil
}

// NOTE: the server image is also used for static (non-ODR) runners.
// Static runners cannot use the ODR image.
const DefaultServerImage = "hashicorp/waypoint:latest"

// When we have a serverImage value to give to DefaultODRImage,
// When we have a serverImage value to give to DeriveDefaultOdrImage,
// we should use that. When we don't, we can use this value
const DefaultRunnerImage = "hashicorp/waypoint-odr:latest"
const DefaultODRImage = "hashicorp/waypoint-odr:latest"

func DefaultRunnerName(id string) string {
return "waypoint-" + id + "-runner"
Expand Down
7 changes: 4 additions & 3 deletions internal/runnerinstall/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package runnerinstall
import (
"context"
"fmt"
"github.com/hashicorp/waypoint/internal/installutil"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
"os"
"time"

Expand All @@ -15,7 +13,10 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"

"github.com/hashicorp/waypoint/internal/installutil"
"github.com/hashicorp/waypoint/internal/pkg/flag"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
)

type DockerConfig struct {
Expand Down Expand Up @@ -217,7 +218,7 @@ func (i *DockerRunnerInstaller) OnDemandRunnerConfig() *pb.OnDemandRunnerConfig
// TODO: Add options for plugin config here
return &pb.OnDemandRunnerConfig{
Name: "docker",
OciUrl: i.Config.RunnerImage,
OciUrl: installutil.DefaultODRImage,
PluginType: "docker",
Default: false,
}
Expand Down
6 changes: 4 additions & 2 deletions internal/runnerinstall/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
"strconv"
"strings"
"time"

pb "github.com/hashicorp/waypoint/pkg/server/gen"

"github.com/hashicorp/waypoint/internal/clierrors"
"github.com/hashicorp/waypoint/internal/installutil"

Expand All @@ -20,6 +21,7 @@ import (
"github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"

"github.com/hashicorp/waypoint/builtin/aws/utils"
awsinstallutil "github.com/hashicorp/waypoint/internal/installutil/aws"
"github.com/hashicorp/waypoint/internal/pkg/flag"
Expand Down Expand Up @@ -729,7 +731,7 @@ func (i *ECSRunnerInstaller) OnDemandRunnerConfig() *pb.OnDemandRunnerConfig {

return &pb.OnDemandRunnerConfig{
Name: "ecs",
OciUrl: i.Config.RunnerImage,
OciUrl: installutil.DefaultODRImage,
PluginType: "aws-ecs",
Default: false,
PluginConfig: cfgJson,
Expand Down
42 changes: 14 additions & 28 deletions internal/runnerinstall/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,6 @@ func (i *K8sRunnerInstaller) Install(ctx context.Context, opts *InstallOpts) err
return err
}

odrImage := i.Config.OdrImage
if odrImage == "" {
odrImage, err = installutil.DefaultODRImage(i.Config.RunnerImage)
if err != nil {
opts.UI.Output("Error getting default ODR image: %s", clierrors.Humanize(err), terminal.WithErrorStyle())
return err
}
}
odrImageRef, err := dockerparser.Parse(odrImage)
if err != nil {
opts.UI.Output("Error parsing ODR image name: %s", clierrors.Humanize(err), terminal.WithErrorStyle())
return err
}

clientSet, err := k8sinstallutil.NewClient(i.Config)
if err != nil {
opts.UI.Output("Error creating k8s clientset: %s", clierrors.Humanize(err), terminal.StatusError)
Expand Down Expand Up @@ -163,16 +149,10 @@ func (i *K8sRunnerInstaller) Install(ctx context.Context, opts *InstallOpts) err
"repository": runnerImageRef.Repository(),
"tag": runnerImageRef.Tag(),
},
"odr": map[string]interface{}{
"image": map[string]interface{}{
"repository": odrImageRef.Repository(),
"tag": odrImageRef.Tag(),
},
"serviceAccount": map[string]interface{}{
"create": i.Config.CreateServiceAccount,
"name": "waypoint-runner-odr",
},
},
// odr stanza not specified - this is used by the helm chart to
// give to the bootstrap job to populate the ODR profile, but only
// during a server install. For runner installs, we'll create the
// ODR profile ourselves later.
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"memory": i.Config.MemRequest,
Expand Down Expand Up @@ -236,9 +216,11 @@ func (i *K8sRunnerInstaller) InstallFlags(set *flag.Set) {
})

set.StringVar(&flag.StringVar{
Name: "k8s-runner-image",
Target: &i.Config.RunnerImage,
Default: installutil.DefaultRunnerImage,
Name: "k8s-runner-image",
Target: &i.Config.RunnerImage,
// This is the static (non-odr) runner, and therefore needs to use the non-ODR
// image. The server and the static runner use the same image.
Default: installutil.DefaultServerImage,
Usage: "Docker image for the Waypoint runner.",
})

Expand Down Expand Up @@ -552,10 +534,14 @@ func (i *K8sRunnerInstaller) OnDemandRunnerConfig() *pb.OnDemandRunnerConfig {

return &pb.OnDemandRunnerConfig{
Name: "kubernetes",
OciUrl: i.Config.RunnerImage,
PluginType: "kubernetes",
Default: false,
PluginConfig: cfgJson,
ConfigFormat: pb.Hcl_JSON,
// Can't use i.Config.OdrImage here, because it hasn't been initalized.
// This doesn't matter in practice - this is used in the `runner install` command,
// which has its own -odr-image flag that it's going to use to overwrite
// this value.
OciUrl: installutil.DefaultODRImage,
}
}
11 changes: 5 additions & 6 deletions internal/runnerinstall/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"strings"
"time"

"github.com/hashicorp/waypoint/internal/installutil"
pb "github.com/hashicorp/waypoint/pkg/server/gen"

"github.com/hashicorp/nomad/api"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/hashicorp/waypoint/internal/clierrors"
"github.com/hashicorp/waypoint/internal/installutil"
nomadutil "github.com/hashicorp/waypoint/internal/installutil/nomad"
"github.com/hashicorp/waypoint/internal/pkg/flag"
"k8s.io/apimachinery/pkg/util/wait"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
)

type NomadRunnerInstaller struct {
Expand All @@ -29,7 +29,6 @@ type NomadConfig struct {
ServiceAnnotations map[string]string `hcl:"service_annotations,optional"`

RunnerImage string `hcl:"runner_image,optional"`
OdrImage string `hcl:"odr_image,optional"`

Region string `hcl:"namespace,optional"`
Datacenters []string `hcl:"datacenters,optional"`
Expand Down Expand Up @@ -435,7 +434,7 @@ func (i *NomadRunnerInstaller) OnDemandRunnerConfig() *pb.OnDemandRunnerConfig {

return &pb.OnDemandRunnerConfig{
Name: "nomad",
OciUrl: i.Config.RunnerImage,
OciUrl: installutil.DefaultODRImage,
PluginType: "nomad",
Default: false,
PluginConfig: cfgJson,
Expand Down
11 changes: 4 additions & 7 deletions internal/serverinstall/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (
"os"
"time"

"github.com/hashicorp/waypoint/internal/installutil"

"github.com/hashicorp/waypoint/internal/runnerinstall"

"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand All @@ -18,11 +14,12 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/go-connections/nat"

"github.com/hashicorp/waypoint-plugin-sdk/terminal"

"github.com/hashicorp/waypoint/internal/clicontext"
"github.com/hashicorp/waypoint/internal/installutil"
"github.com/hashicorp/waypoint/internal/pkg/flag"
"github.com/hashicorp/waypoint/internal/runnerinstall"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
"github.com/hashicorp/waypoint/pkg/serverconfig"
)
Expand Down Expand Up @@ -53,7 +50,7 @@ func (i *DockerInstaller) Install(
) (*InstallResults, string, error) {
if i.config.odrImage == "" {
var err error
i.config.odrImage, err = installutil.DefaultODRImage(i.config.serverImage)
i.config.odrImage, err = installutil.DeriveDefaultODRImage(i.config.serverImage)
if err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -295,7 +292,7 @@ func (i *DockerInstaller) Upgrade(
) {
if i.config.odrImage == "" {
var err error
i.config.odrImage, err = installutil.DefaultODRImage(i.config.serverImage)
i.config.odrImage, err = installutil.DeriveDefaultODRImage(i.config.serverImage)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/serverinstall/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/client-go/tools/clientcmd"

"github.com/hashicorp/waypoint-plugin-sdk/terminal"

"github.com/hashicorp/waypoint/builtin/k8s"
"github.com/hashicorp/waypoint/internal/clicontext"
"github.com/hashicorp/waypoint/internal/clierrors"
Expand Down Expand Up @@ -102,7 +103,7 @@ func (i *K8sInstaller) Install(
) (*InstallResults, string, error) {
if i.Config.OdrImage == "" {
var err error
i.Config.OdrImage, err = installutil.DefaultODRImage(i.Config.ServerImage)
i.Config.OdrImage, err = installutil.DeriveDefaultODRImage(i.Config.ServerImage)
if err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -431,7 +432,7 @@ func (i *K8sInstaller) Upgrade(
) {
if i.Config.OdrImage == "" {
var err error
i.Config.OdrImage, err = installutil.DefaultODRImage(i.Config.ServerImage)
i.Config.OdrImage, err = installutil.DeriveDefaultODRImage(i.Config.ServerImage)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/serverinstall/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/hashicorp/nomad/api"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"

"github.com/hashicorp/waypoint/internal/clicontext"
"github.com/hashicorp/waypoint/internal/clierrors"
"github.com/hashicorp/waypoint/internal/pkg/flag"
Expand Down Expand Up @@ -149,7 +150,7 @@ func (i *NomadInstaller) Install(

if i.config.odrImage == "" {
var err error
i.config.odrImage, err = installutil.DefaultODRImage(i.config.serverImage)
i.config.odrImage, err = installutil.DeriveDefaultODRImage(i.config.serverImage)
if err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -394,7 +395,7 @@ func (i *NomadInstaller) Upgrade(

if i.config.odrImage == "" {
var err error
i.config.odrImage, err = installutil.DefaultODRImage(i.config.serverImage)
i.config.odrImage, err = installutil.DeriveDefaultODRImage(i.config.serverImage)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -628,7 +629,6 @@ func (i *NomadInstaller) InstallRunner(
RunnerImage: i.config.serverImage,
Namespace: i.config.namespace,
ServiceAnnotations: i.config.serviceAnnotations,
OdrImage: i.config.odrImage,
Region: i.config.region,
Datacenters: i.config.datacenters,
PolicyOverride: i.config.policyOverride,
Expand Down
Loading

0 comments on commit 34f4a25

Please sign in to comment.