diff --git a/internal/commands/inspect.go b/internal/commands/inspect.go index 1778a7831..97543a378 100644 --- a/internal/commands/inspect.go +++ b/internal/commands/inspect.go @@ -23,9 +23,7 @@ const inspectExample = `- $ docker app inspect my-running-app type inspectOptions struct { credentialOptions cliopts.InstallerContextOptions - pretty bool - orchestrator string - kubeNamespace string + pretty bool } func inspectCmd(dockerCli command.Cli) *cobra.Command { @@ -40,19 +38,12 @@ func inspectCmd(dockerCli command.Cli) *cobra.Command { }, } cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Pretty print the output") - cmd.Flags().StringVar(&opts.orchestrator, "orchestrator", "", "Orchestrator where the App is running on (swarm, kubernetes)") - cmd.Flags().StringVar(&opts.kubeNamespace, "namespace", "default", "Kubernetes namespace in which to find the App") opts.credentialOptions.addFlags(cmd.Flags()) opts.InstallerContextOptions.AddFlags(cmd.Flags()) return cmd } func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions) error { - orchestrator, err := getContextOrchestrator(dockerCli, inspectOptions.orchestrator) - if err != nil { - return err - } - defer muteDockerCli(dockerCli)() _, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext()) if err != nil { @@ -63,11 +54,6 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt return err } - orchestratorName, ok := installation.Parameters[internal.ParameterOrchestratorName].(string) - if !ok || orchestratorName == "" { - orchestratorName = string(orchestrator) - } - creds, err := prepareCredentialSet(installation.Bundle, inspectOptions.CredentialSetOpts(dockerCli, credentialStore)...) if err != nil { return err @@ -94,7 +80,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt } if inspectOptions.pretty { - if err := inspect.Inspect(os.Stdout, installation, "pretty", orchestratorName); err != nil { + if err := inspect.Inspect(os.Stdout, installation, "pretty"); err != nil { return err } fmt.Fprint(os.Stdout, buf.String()) @@ -107,7 +93,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt AppInfo inspect.AppInfo `json:",omitempty"` Services interface{} `json:",omitempty"` }{ - inspect.GetAppInfo(installation, orchestratorName), + inspect.GetAppInfo(installation), statusJSON, }, "", " ") if err != nil { @@ -118,19 +104,6 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt return nil } -func getContextOrchestrator(dockerCli command.Cli, orchestratorFlag string) (command.Orchestrator, error) { - var orchestrator command.Orchestrator - orchestrator, _ = command.NormalizeOrchestrator(orchestratorFlag) - if string(orchestrator) == "" { - orchestrator, err := dockerCli.StackOrchestrator("") - if err != nil { - return "", err - } - return orchestrator, nil - } - return orchestrator, nil -} - func hasAction(bndl *bundle.Bundle, actionName string) bool { for key := range bndl.Actions { if key == actionName { diff --git a/internal/inspect/inspect.go b/internal/inspect/inspect.go index 873b00a92..eddab2673 100644 --- a/internal/inspect/inspect.go +++ b/internal/inspect/inspect.go @@ -70,14 +70,13 @@ type AppInfo struct { Parameters map[string]interface{} `yaml:"Parameters,omitempty" json:"Parameters,omitempty"` } -func Inspect(out io.Writer, installation *store.Installation, outputFormat string, cliDefinedOrchestrator string) error { +func Inspect(out io.Writer, installation *store.Installation, outputFormat string) error { // Collect all the relevant information about the application - appInfo := GetAppInfo(installation, cliDefinedOrchestrator) + appInfo := GetAppInfo(installation) return printAppInfo(out, appInfo, outputFormat) } -func GetAppInfo(installation *store.Installation, cliDefinedOrchestrator string) AppInfo { - orchestrator := getOrchestrator(installation.Claim, cliDefinedOrchestrator) +func GetAppInfo(installation *store.Installation) AppInfo { return AppInfo{ Installation: Installation{ Name: installation.Name, @@ -86,7 +85,7 @@ func GetAppInfo(installation *store.Installation, cliDefinedOrchestrator string) Revision: installation.Revision, LastAction: installation.Result.Action, Result: installation.Result.Status, - Orchestrator: orchestrator, + Orchestrator: getOrchestrator(installation.Claim), }, Application: Application{ Name: installation.Bundle.Name, @@ -232,11 +231,11 @@ func printSection(out io.Writer, len int, printer func(io.Writer), headers ...st w.Flush() } -func getOrchestrator(claim claim.Claim, cliDefaultOrchestrator string) string { - if orchestrator, ok := claim.Parameters[internal.ParameterOrchestratorName]; ok && orchestrator != "" { +func getOrchestrator(claim claim.Claim) string { + if orchestrator, ok := claim.Parameters[internal.ParameterOrchestratorName]; ok && orchestrator != nil { return orchestrator.(string) } - return cliDefaultOrchestrator + return "" } func removeDockerAppParameters(parameters map[string]interface{}) map[string]interface{} { diff --git a/internal/inspect/inspect_test.go b/internal/inspect/inspect_test.go index 11f1e2bee..eb76ef169 100644 --- a/internal/inspect/inspect_test.go +++ b/internal/inspect/inspect_test.go @@ -170,7 +170,7 @@ func getInstallation() store.Installation { "com.docker.app.args": "{}", "com.docker.app.inspect-format": "json", "com.docker.app.kubernetes-namespace": "default", - "com.docker.app.orchestrator": "", + "com.docker.app.orchestrator": "swarm", "com.docker.app.render-format": "yaml", "com.docker.app.share-registry-creds": false, "port": "8080", @@ -202,7 +202,7 @@ func TestInspect(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { var out bytes.Buffer - err := Inspect(&out, &i, testCase.format, "swarm") + err := Inspect(&out, &i, testCase.format) assert.NilError(t, err) golden.Assert(t, out.String(), fmt.Sprintf("inspect-app-%s.golden", testCase.name)) })