Skip to content

Commit dc53f87

Browse files
fix: refactor skip-file-capabilities flag
1 parent f62c056 commit dc53f87

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

internal/pkg/agent/cmd/container.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ var (
5454
// Used to strip the appended ({uuid}) from the name of an enrollment token. This makes much easier for
5555
// a container to reference a token by name, without having to know what the generated UUID is for that name.
5656
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}\)$`)
57-
58-
skipFileCapabilities bool
5957
)
6058

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

154-
cmd.Flags().BoolVar(&skipFileCapabilities, skipFileCapabilitiesFlag, false, "")
152+
cmd.Flags().Bool(skipFileCapabilitiesFlag, false, "skip setting file capabilities")
155153

156154
return &cmd
157155
}
@@ -164,8 +162,13 @@ func logInfo(streams *cli.IOStreams, a ...interface{}) {
164162
fmt.Fprintln(streams.Out, a...)
165163
}
166164

167-
func logContainerCmd(streams *cli.IOStreams) error {
168-
shouldExit, err := initContainer(streams)
165+
func logContainerCmd(cmd *cobra.Command, streams *cli.IOStreams) error {
166+
skipFileCapabilities, err := cmd.Flags().GetBool(skipFileCapabilitiesFlag)
167+
if err != nil {
168+
return err
169+
}
170+
171+
shouldExit, err := initContainer(streams, skipFileCapabilities)
169172
if err != nil {
170173
return err
171174
}

internal/pkg/agent/cmd/container_init_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333
// - chown all agent-related paths if DAC_OVERRIDE capability is not in the Effective set
3434
// If new binary capabilities are set then the returned cmd will be not nil. Note that it is up to caller to invoke
3535
// the returned cmd and spawn an agent instance with all the capabilities.
36-
func initContainer(streams *cli.IOStreams) (shouldExit bool, err error) {
36+
func initContainer(streams *cli.IOStreams, skipFileCapabilities bool) (shouldExit bool, err error) {
3737
isRoot, err := utils.HasRoot()
3838
if err != nil {
3939
return true, err

internal/pkg/agent/cmd/container_init_other.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ import (
1010
"github.com/elastic/elastic-agent/internal/pkg/cli"
1111
)
1212

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

0 commit comments

Comments
 (0)