Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

ignited: allow running help, completion, version subcommands without root permission #955

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/ignite/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
// Set the desired logging level, now that the flags are parsed
logs.Logger.SetLevel(logLevel)

// TODO Some commands do not need to check root
// Currently it seems to be only ignite version that does not require root
if isNonRootCommand(cmd.Name(), cmd.Parent().Name()) {
return
}
Expand All @@ -53,6 +51,9 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
// Create the directories needed for running
util.GenericCheckErr(util.CreateDirectories())

// Preload necessary providers
util.GenericCheckErr(providers.Populate(ignite.Preload))

if err := config.ApplyConfiguration(configPath); err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 0 additions & 6 deletions cmd/ignite/ignite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"os"

"github.com/weaveworks/ignite/cmd/ignite/cmd"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/providers/ignite"
"github.com/weaveworks/ignite/pkg/util"
)

func main() {
Expand All @@ -17,9 +14,6 @@ func main() {

// Run runs the main cobra command of this application
func Run() error {
// Preload necessary providers
util.GenericCheckErr(providers.Populate(ignite.Preload))

c := cmd.NewIgniteCommand(os.Stdin, os.Stdout, os.Stderr)
return c.Execute()
}
33 changes: 31 additions & 2 deletions cmd/ignited/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
logflag "github.com/weaveworks/ignite/pkg/logs/flag"
networkflag "github.com/weaveworks/ignite/pkg/network/flag"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/providers/ignite"
"github.com/weaveworks/ignite/pkg/providers/ignited"
"github.com/weaveworks/ignite/pkg/util"
runtimeflag "github.com/weaveworks/ignite/pkg/runtime/flag"
versioncmd "github.com/weaveworks/ignite/pkg/version/cmd"
)
Expand All @@ -34,12 +35,27 @@ func NewIgnitedCommand(in io.Reader, out, err io.Writer) *cobra.Command {
// Set the desired logging level, now that the flags are parsed
logs.Logger.SetLevel(logLevel)

if isNonRootCommand(cmd.Name(), cmd.Parent().Name()) {
return
}

// Ignited needs to run as root for now, see
// https://github.com/weaveworks/ignite/issues/46
// TODO: Remove this when ready
util.GenericCheckErr(util.TestRoot())

// Create the directories needed for running
util.GenericCheckErr(util.CreateDirectories())

// Preload necessary providers
util.GenericCheckErr(providers.Populate(ignited.Preload))

if err := config.ApplyConfiguration(configPath); err != nil {
log.Fatal(err)
}

// Populate the providers after flags have been parsed
if err := providers.Populate(ignite.Providers); err != nil {
if err := providers.Populate(ignited.Providers); err != nil {
log.Fatal(err)
}
},
Expand All @@ -60,6 +76,19 @@ func NewIgnitedCommand(in io.Reader, out, err io.Writer) *cobra.Command {
return root
}

func isNonRootCommand(cmd string, parentCmd string) bool {
if parentCmd != "ignited" {
return false
}

switch cmd {
case "version", "help", "completion":
return true
}

return false
}

func addGlobalFlags(fs *pflag.FlagSet) {
logflag.LogLevelFlagVar(fs, &logLevel)
runtimeflag.RuntimeVar(fs, &providers.RuntimeName)
Expand Down
14 changes: 0 additions & 14 deletions cmd/ignited/ignited.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (
log "github.com/sirupsen/logrus"
"github.com/weaveworks/ignite/cmd/ignited/cmd"
"github.com/weaveworks/ignite/pkg/constants"
"github.com/weaveworks/ignite/pkg/providers"
"github.com/weaveworks/ignite/pkg/providers/ignited"
"github.com/weaveworks/ignite/pkg/util"
)

func main() {
Expand Down Expand Up @@ -44,17 +41,6 @@ func cleanup() {

// Run runs the main cobra command of this application
func Run() error {
// Ignite needs to run as root for now, see
// https://github.com/weaveworks/ignite/issues/46
// TODO: Remove this when ready
util.GenericCheckErr(util.TestRoot())

// Create the directories needed for running
util.GenericCheckErr(util.CreateDirectories())

// Preload necessary providers
util.GenericCheckErr(providers.Populate(ignited.Preload))

c := cmd.NewIgnitedCommand(os.Stdin, os.Stdout, os.Stderr)
return c.Execute()
}