Skip to content

Commit

Permalink
fix: refactor skip-file-capabilities flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoutsovasilis committed Jun 13, 2024
1 parent f62c056 commit dc53f87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions internal/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ var (
// Used to strip the appended ({uuid}) from the name of an enrollment token. This makes much easier for
// a container to reference a token by name, without having to know what the generated UUID is for that name.
tokenNameStrip = regexp.MustCompile(`\s\([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)$`)

skipFileCapabilities bool
)

func newContainerCommand(_ []string, streams *cli.IOStreams) *cobra.Command {
Expand Down Expand Up @@ -144,14 +142,14 @@ all the above actions will be skipped, because the Elastic Agent has already bee
occurs on every start of the container set FLEET_FORCE to 1.
`,
Run: func(c *cobra.Command, args []string) {
if err := logContainerCmd(streams); err != nil {
if err := logContainerCmd(c, streams); err != nil {
logError(streams, err)
os.Exit(1)
}
},
}

cmd.Flags().BoolVar(&skipFileCapabilities, skipFileCapabilitiesFlag, false, "")
cmd.Flags().Bool(skipFileCapabilitiesFlag, false, "skip setting file capabilities")

return &cmd
}
Expand All @@ -164,8 +162,13 @@ func logInfo(streams *cli.IOStreams, a ...interface{}) {
fmt.Fprintln(streams.Out, a...)
}

func logContainerCmd(streams *cli.IOStreams) error {
shouldExit, err := initContainer(streams)
func logContainerCmd(cmd *cobra.Command, streams *cli.IOStreams) error {
skipFileCapabilities, err := cmd.Flags().GetBool(skipFileCapabilitiesFlag)
if err != nil {
return err
}

shouldExit, err := initContainer(streams, skipFileCapabilities)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/cmd/container_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
// - chown all agent-related paths if DAC_OVERRIDE capability is not in the Effective set
// If new binary capabilities are set then the returned cmd will be not nil. Note that it is up to caller to invoke
// the returned cmd and spawn an agent instance with all the capabilities.
func initContainer(streams *cli.IOStreams) (shouldExit bool, err error) {
func initContainer(streams *cli.IOStreams, skipFileCapabilities bool) (shouldExit bool, err error) {
isRoot, err := utils.HasRoot()
if err != nil {
return true, err
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/cmd/container_init_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/cli"
)

func initContainer(streams *cli.IOStreams) (shouldExit bool, err error) {
func initContainer(streams *cli.IOStreams, skipFileCapabilities bool) (shouldExit bool, err error) {
return false, nil
}

0 comments on commit dc53f87

Please sign in to comment.