Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 6c2b173

Browse files
Merge pull request #751 from silvin-lubecki/remove-useless-inspect-flags
Remove extra flags on docker app inspect command
2 parents a04e9b3 + fb411ac commit 6c2b173

File tree

3 files changed

+12
-40
lines changed

3 files changed

+12
-40
lines changed

internal/commands/inspect.go

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ const inspectExample = `- $ docker app inspect my-running-app
2323
type inspectOptions struct {
2424
credentialOptions
2525
cliopts.InstallerContextOptions
26-
pretty bool
27-
orchestrator string
28-
kubeNamespace string
26+
pretty bool
2927
}
3028

3129
func inspectCmd(dockerCli command.Cli) *cobra.Command {
@@ -40,19 +38,12 @@ func inspectCmd(dockerCli command.Cli) *cobra.Command {
4038
},
4139
}
4240
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Pretty print the output")
43-
cmd.Flags().StringVar(&opts.orchestrator, "orchestrator", "", "Orchestrator where the App is running on (swarm, kubernetes)")
44-
cmd.Flags().StringVar(&opts.kubeNamespace, "namespace", "default", "Kubernetes namespace in which to find the App")
4541
opts.credentialOptions.addFlags(cmd.Flags())
4642
opts.InstallerContextOptions.AddFlags(cmd.Flags())
4743
return cmd
4844
}
4945

5046
func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions) error {
51-
orchestrator, err := getContextOrchestrator(dockerCli, inspectOptions.orchestrator)
52-
if err != nil {
53-
return err
54-
}
55-
5647
defer muteDockerCli(dockerCli)()
5748
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
5849
if err != nil {
@@ -63,11 +54,6 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
6354
return err
6455
}
6556

66-
orchestratorName, ok := installation.Parameters[internal.ParameterOrchestratorName].(string)
67-
if !ok || orchestratorName == "" {
68-
orchestratorName = string(orchestrator)
69-
}
70-
7157
creds, err := prepareCredentialSet(installation.Bundle, inspectOptions.CredentialSetOpts(dockerCli, credentialStore)...)
7258
if err != nil {
7359
return err
@@ -94,7 +80,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
9480
}
9581

9682
if inspectOptions.pretty {
97-
if err := inspect.Inspect(os.Stdout, installation, "pretty", orchestratorName); err != nil {
83+
if err := inspect.Inspect(os.Stdout, installation, "pretty"); err != nil {
9884
return err
9985
}
10086
fmt.Fprint(os.Stdout, buf.String())
@@ -107,7 +93,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
10793
AppInfo inspect.AppInfo `json:",omitempty"`
10894
Services interface{} `json:",omitempty"`
10995
}{
110-
inspect.GetAppInfo(installation, orchestratorName),
96+
inspect.GetAppInfo(installation),
11197
statusJSON,
11298
}, "", " ")
11399
if err != nil {
@@ -118,19 +104,6 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
118104
return nil
119105
}
120106

121-
func getContextOrchestrator(dockerCli command.Cli, orchestratorFlag string) (command.Orchestrator, error) {
122-
var orchestrator command.Orchestrator
123-
orchestrator, _ = command.NormalizeOrchestrator(orchestratorFlag)
124-
if string(orchestrator) == "" {
125-
orchestrator, err := dockerCli.StackOrchestrator("")
126-
if err != nil {
127-
return "", err
128-
}
129-
return orchestrator, nil
130-
}
131-
return orchestrator, nil
132-
}
133-
134107
func hasAction(bndl *bundle.Bundle, actionName string) bool {
135108
for key := range bndl.Actions {
136109
if key == actionName {

internal/inspect/inspect.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,13 @@ type AppInfo struct {
7070
Parameters map[string]interface{} `yaml:"Parameters,omitempty" json:"Parameters,omitempty"`
7171
}
7272

73-
func Inspect(out io.Writer, installation *store.Installation, outputFormat string, cliDefinedOrchestrator string) error {
73+
func Inspect(out io.Writer, installation *store.Installation, outputFormat string) error {
7474
// Collect all the relevant information about the application
75-
appInfo := GetAppInfo(installation, cliDefinedOrchestrator)
75+
appInfo := GetAppInfo(installation)
7676
return printAppInfo(out, appInfo, outputFormat)
7777
}
7878

79-
func GetAppInfo(installation *store.Installation, cliDefinedOrchestrator string) AppInfo {
80-
orchestrator := getOrchestrator(installation.Claim, cliDefinedOrchestrator)
79+
func GetAppInfo(installation *store.Installation) AppInfo {
8180
return AppInfo{
8281
Installation: Installation{
8382
Name: installation.Name,
@@ -86,7 +85,7 @@ func GetAppInfo(installation *store.Installation, cliDefinedOrchestrator string)
8685
Revision: installation.Revision,
8786
LastAction: installation.Result.Action,
8887
Result: installation.Result.Status,
89-
Orchestrator: orchestrator,
88+
Orchestrator: getOrchestrator(installation.Claim),
9089
},
9190
Application: Application{
9291
Name: installation.Bundle.Name,
@@ -232,11 +231,11 @@ func printSection(out io.Writer, len int, printer func(io.Writer), headers ...st
232231
w.Flush()
233232
}
234233

235-
func getOrchestrator(claim claim.Claim, cliDefaultOrchestrator string) string {
236-
if orchestrator, ok := claim.Parameters[internal.ParameterOrchestratorName]; ok && orchestrator != "" {
234+
func getOrchestrator(claim claim.Claim) string {
235+
if orchestrator, ok := claim.Parameters[internal.ParameterOrchestratorName]; ok && orchestrator != nil {
237236
return orchestrator.(string)
238237
}
239-
return cliDefaultOrchestrator
238+
return ""
240239
}
241240

242241
func removeDockerAppParameters(parameters map[string]interface{}) map[string]interface{} {

internal/inspect/inspect_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func getInstallation() store.Installation {
170170
"com.docker.app.args": "{}",
171171
"com.docker.app.inspect-format": "json",
172172
"com.docker.app.kubernetes-namespace": "default",
173-
"com.docker.app.orchestrator": "",
173+
"com.docker.app.orchestrator": "swarm",
174174
"com.docker.app.render-format": "yaml",
175175
"com.docker.app.share-registry-creds": false,
176176
"port": "8080",
@@ -202,7 +202,7 @@ func TestInspect(t *testing.T) {
202202
for _, testCase := range testCases {
203203
t.Run(testCase.name, func(t *testing.T) {
204204
var out bytes.Buffer
205-
err := Inspect(&out, &i, testCase.format, "swarm")
205+
err := Inspect(&out, &i, testCase.format)
206206
assert.NilError(t, err)
207207
golden.Assert(t, out.String(), fmt.Sprintf("inspect-app-%s.golden", testCase.name))
208208
})

0 commit comments

Comments
 (0)