Skip to content

Commit

Permalink
Fix profile flag for static pods
Browse files Browse the repository at this point in the history
Stop ranging over CLI flags; the type checks are tedious and
error-prone.

Fixes errors turned up in QA validation of #387.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Oct 1, 2020
1 parent 0735d3b commit 1d56fde
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewAgentCommand() cli.Command {

func AgentRun(clx *cli.Context) error {
switch profile {
case "cis-1.5":
case rke2.CISProfile:
if err := validateCISReqs("agent"); err != nil {
logrus.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/rancher/k3s/pkg/version"
"github.com/rancher/rke2/pkg/rke2"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -39,7 +40,7 @@ var (
},
&cli.StringFlag{
Name: "profile",
Usage: "(security) Validate system configuration against the selected benchmark (valid items: cis-1.5)",
Usage: "(security) Validate system configuration against the selected benchmark (valid items: " + rke2.CISProfile + ")",
EnvVar: "RKE2_CIS_PROFILE",
Destination: &profile,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewServerCommand() cli.Command {

func ServerRun(clx *cli.Context) error {
switch profile {
case "cis-1.5":
case rke2.CISProfile:
if err := validateCISReqs("server"); err != nil {
logrus.Fatal(err)
}
Expand Down
17 changes: 4 additions & 13 deletions pkg/rke2/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Config struct {

var cisMode bool

const CISProfile = "cis-1.5"

func Server(clx *cli.Context, cfg Config) error {
if err := setup(clx, cfg); err != nil {
return err
Expand Down Expand Up @@ -63,19 +65,8 @@ func Agent(clx *cli.Context, cfg Config) error {
}

func setup(clx *cli.Context, cfg Config) error {
var dataDir string

for _, f := range clx.Command.Flags {
switch t := f.(type) {
case cli.StringFlag:
if strings.Contains(t.Name, "data-dir") {
dataDir = *t.Destination
} else if t.Name == "profile" && t.Destination != nil && *t.Destination != "" {
cisMode = true
}

}
}
cisMode = clx.String("profile") == CISProfile
dataDir := clx.String("data-dir")

images := images.New(cfg.SystemDefaultRegistry)
if err := defaults.Set(clx, images, dataDir); err != nil {
Expand Down

0 comments on commit 1d56fde

Please sign in to comment.