From 8746c7b4aa77f4c75138509a818ef56d2c0c838a Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Wed, 17 Jan 2018 15:13:21 -0500 Subject: [PATCH] openshift-diagnostics => diagnostics subcommands Instead of building a separate `openshift-diagnostics` just turn its subcommands into hidden subcommands on `oc adm diagnostics`. Then use these within diagnostics pods. fixes https://github.com/openshift/origin/issues/18141 fixes https://bugzilla.redhat.com/show_bug.cgi?id=1534513 --- cmd/openshift-diagnostics/main.go | 46 ------------------- contrib/vagrant/provision-util.sh | 2 +- docs/man/man1/.files_generated_oc | 4 ++ .../oc-adm-diagnostics-inpod-networkcheck.1 | 3 ++ .../oc-adm-diagnostics-inpod-poddiagnostic.1 | 3 ++ .../oc-ex-diagnostics-inpod-networkcheck.1 | 3 ++ .../oc-ex-diagnostics-inpod-poddiagnostic.1 | 3 ++ hack/dind-cluster.sh | 1 - hack/lib/constants.sh | 1 - images/dind/node/Dockerfile | 1 - pkg/oc/admin/diagnostics/diagnostics.go | 7 +++ .../diagnostics/client/run_diagnostics_pod.go | 9 ++-- .../diagnostics/network/run_pod.go | 15 +++--- pkg/oc/admin/diagnostics/network_pod.go | 7 +-- pkg/oc/admin/diagnostics/pod.go | 7 +-- 15 files changed, 45 insertions(+), 67 deletions(-) delete mode 100644 cmd/openshift-diagnostics/main.go create mode 100644 docs/man/man1/oc-adm-diagnostics-inpod-networkcheck.1 create mode 100644 docs/man/man1/oc-adm-diagnostics-inpod-poddiagnostic.1 create mode 100644 docs/man/man1/oc-ex-diagnostics-inpod-networkcheck.1 create mode 100644 docs/man/man1/oc-ex-diagnostics-inpod-poddiagnostic.1 diff --git a/cmd/openshift-diagnostics/main.go b/cmd/openshift-diagnostics/main.go deleted file mode 100644 index ccd5ca006213..000000000000 --- a/cmd/openshift-diagnostics/main.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "math/rand" - "os" - "runtime" - "time" - - "k8s.io/apiserver/pkg/util/logs" - - "github.com/openshift/origin/pkg/cmd/util/serviceability" - "github.com/openshift/origin/pkg/oc/admin/diagnostics" - "github.com/spf13/cobra" - - // install all APIs - _ "github.com/openshift/origin/pkg/api/install" - _ "k8s.io/kubernetes/pkg/apis/autoscaling/install" - _ "k8s.io/kubernetes/pkg/apis/batch/install" - _ "k8s.io/kubernetes/pkg/apis/core/install" - _ "k8s.io/kubernetes/pkg/apis/extensions/install" -) - -func main() { - logs.InitLogs() - defer logs.FlushLogs() - defer serviceability.BehaviorOnPanic(os.Getenv("OPENSHIFT_ON_PANIC"))() - defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop() - - rand.Seed(time.Now().UTC().UnixNano()) - if len(os.Getenv("GOMAXPROCS")) == 0 { - runtime.GOMAXPROCS(runtime.NumCPU()) - } - - cmd := &cobra.Command{ - Use: "openshift-diagnostics", - Short: "Diagnose OpenShift clusters", - } - cmd.AddCommand( - diagnostics.NewCommandPodDiagnostics("diagnostic-pod", os.Stdout), - diagnostics.NewCommandNetworkPodDiagnostics("network-diagnostic-pod", os.Stdout), - ) - - if err := cmd.Execute(); err != nil { - os.Exit(1) - } -} diff --git a/contrib/vagrant/provision-util.sh b/contrib/vagrant/provision-util.sh index 02dce2875c65..0f768e9a62a2 100755 --- a/contrib/vagrant/provision-util.sh +++ b/contrib/vagrant/provision-util.sh @@ -57,7 +57,7 @@ os::provision::install-cmds() { local deployed_root=$1 local output_path="$(os::build::get-bin-output-path "${deployed_root}")" - cp ${output_path}/{openshift,openshift-diagnostics,oc} /usr/bin + cp ${output_path}/{openshift,oc} /usr/bin } os::provision::add-to-hosts-file() { diff --git a/docs/man/man1/.files_generated_oc b/docs/man/man1/.files_generated_oc index 4b8f511abdfc..a30aeb410038 100644 --- a/docs/man/man1/.files_generated_oc +++ b/docs/man/man1/.files_generated_oc @@ -47,6 +47,8 @@ oc-adm-diagnostics-clusterrouter.1 oc-adm-diagnostics-configcontexts.1 oc-adm-diagnostics-diagnosticpod.1 oc-adm-diagnostics-etcdwritevolume.1 +oc-adm-diagnostics-inpod-networkcheck.1 +oc-adm-diagnostics-inpod-poddiagnostic.1 oc-adm-diagnostics-masterconfigcheck.1 oc-adm-diagnostics-masternode.1 oc-adm-diagnostics-metricsapiproxy.1 @@ -200,6 +202,8 @@ oc-ex-diagnostics-clusterrouter.1 oc-ex-diagnostics-configcontexts.1 oc-ex-diagnostics-diagnosticpod.1 oc-ex-diagnostics-etcdwritevolume.1 +oc-ex-diagnostics-inpod-networkcheck.1 +oc-ex-diagnostics-inpod-poddiagnostic.1 oc-ex-diagnostics-masterconfigcheck.1 oc-ex-diagnostics-masternode.1 oc-ex-diagnostics-metricsapiproxy.1 diff --git a/docs/man/man1/oc-adm-diagnostics-inpod-networkcheck.1 b/docs/man/man1/oc-adm-diagnostics-inpod-networkcheck.1 new file mode 100644 index 000000000000..b6fd7a0f9896 --- /dev/null +++ b/docs/man/man1/oc-adm-diagnostics-inpod-networkcheck.1 @@ -0,0 +1,3 @@ +This file is autogenerated, but we've stopped checking such files into the +repository to reduce the need for rebases. Please run hack/generate-docs.sh to +populate this file. diff --git a/docs/man/man1/oc-adm-diagnostics-inpod-poddiagnostic.1 b/docs/man/man1/oc-adm-diagnostics-inpod-poddiagnostic.1 new file mode 100644 index 000000000000..b6fd7a0f9896 --- /dev/null +++ b/docs/man/man1/oc-adm-diagnostics-inpod-poddiagnostic.1 @@ -0,0 +1,3 @@ +This file is autogenerated, but we've stopped checking such files into the +repository to reduce the need for rebases. Please run hack/generate-docs.sh to +populate this file. diff --git a/docs/man/man1/oc-ex-diagnostics-inpod-networkcheck.1 b/docs/man/man1/oc-ex-diagnostics-inpod-networkcheck.1 new file mode 100644 index 000000000000..b6fd7a0f9896 --- /dev/null +++ b/docs/man/man1/oc-ex-diagnostics-inpod-networkcheck.1 @@ -0,0 +1,3 @@ +This file is autogenerated, but we've stopped checking such files into the +repository to reduce the need for rebases. Please run hack/generate-docs.sh to +populate this file. diff --git a/docs/man/man1/oc-ex-diagnostics-inpod-poddiagnostic.1 b/docs/man/man1/oc-ex-diagnostics-inpod-poddiagnostic.1 new file mode 100644 index 000000000000..b6fd7a0f9896 --- /dev/null +++ b/docs/man/man1/oc-ex-diagnostics-inpod-poddiagnostic.1 @@ -0,0 +1,3 @@ +This file is autogenerated, but we've stopped checking such files into the +repository to reduce the need for rebases. Please run hack/generate-docs.sh to +populate this file. diff --git a/hack/dind-cluster.sh b/hack/dind-cluster.sh index 8868054ac54b..fde1da6c4c83 100755 --- a/hack/dind-cluster.sh +++ b/hack/dind-cluster.sh @@ -537,7 +537,6 @@ function copy-runtime() { local target=$2 cp "$(os::util::find::built_binary openshift)" "${target}" - cp "$(os::util::find::built_binary openshift-diagnostics)" "${target}" cp "$(os::util::find::built_binary oc)" "${target}" cp "$(os::util::find::built_binary host-local)" "${target}" cp "$(os::util::find::built_binary loopback)" "${target}" diff --git a/hack/lib/constants.sh b/hack/lib/constants.sh index 7d4fcf187add..57719f494fa2 100755 --- a/hack/lib/constants.sh +++ b/hack/lib/constants.sh @@ -43,7 +43,6 @@ readonly OS_CROSS_COMPILE_TARGETS=( cmd/openshift cmd/oc cmd/oadm - cmd/openshift-diagnostics cmd/template-service-broker vendor/k8s.io/kubernetes/cmd/hyperkube ) diff --git a/images/dind/node/Dockerfile b/images/dind/node/Dockerfile index 51eacfc27929..cdab705ee982 100644 --- a/images/dind/node/Dockerfile +++ b/images/dind/node/Dockerfile @@ -70,7 +70,6 @@ RUN mkdir -p /opt/cni/bin # make reloading easy. Revisit if/when dind becomes useful for more # than dev/test. RUN ln -sf /data/openshift /usr/local/bin/ && \ - ln -sf /data/openshift-diagnostics /usr/local/bin/ && \ ln -sf /data/oc /usr/local/bin/ && \ ln -sf /data/openshift /usr/local/bin/openshift-deploy && \ ln -sf /data/openshift /usr/local/bin/openshift-docker-build && \ diff --git a/pkg/oc/admin/diagnostics/diagnostics.go b/pkg/oc/admin/diagnostics/diagnostics.go index 50dc2445f314..d5c4a9141298 100644 --- a/pkg/oc/admin/diagnostics/diagnostics.go +++ b/pkg/oc/admin/diagnostics/diagnostics.go @@ -17,7 +17,9 @@ import ( "github.com/openshift/origin/pkg/client/config" "github.com/openshift/origin/pkg/cmd/flagtypes" + clientdiag "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/client" "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/log" + networkdiag "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/network" "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types" "github.com/openshift/origin/pkg/oc/admin/diagnostics/options" osclientcmd "github.com/openshift/origin/pkg/oc/cli/util/clientcmd" @@ -141,6 +143,11 @@ func NewCmdDiagnostics(name string, fullName string, out io.Writer) *cobra.Comma for _, diag := range available { cmd.AddCommand(NewCmdDiagnosticsIndividual(strings.ToLower(diag.Name()), fullName+" "+strings.ToLower(diag.Name()), out, diag)) } + // add hidden in-pod subcommands + cmd.AddCommand( + NewCommandPodDiagnostics(clientdiag.InPodDiagnosticRecommendedName, out), + NewCommandNetworkPodDiagnostics(networkdiag.InPodNetworkCheckRecommendedName, out), + ) return cmd } diff --git a/pkg/oc/admin/diagnostics/diagnostics/client/run_diagnostics_pod.go b/pkg/oc/admin/diagnostics/diagnostics/client/run_diagnostics_pod.go index 2aa41f97cc29..fdf788c8ac8e 100644 --- a/pkg/oc/admin/diagnostics/diagnostics/client/run_diagnostics_pod.go +++ b/pkg/oc/admin/diagnostics/diagnostics/client/run_diagnostics_pod.go @@ -20,9 +20,10 @@ import ( ) const ( - DiagnosticPodName = "DiagnosticPod" - ImageTemplateParam = "images" - LatestImageParam = "latest-images" + InPodDiagnosticRecommendedName = "inpod-poddiagnostic" + DiagnosticPodName = "DiagnosticPod" + ImageTemplateParam = "images" + LatestImageParam = "latest-images" ) // DiagnosticPod is a diagnostic that runs a diagnostic pod and relays the results. @@ -87,7 +88,7 @@ func (d *DiagnosticPod) runDiagnosticPod(r types.DiagnosticResult) { { Name: "pod-diagnostics", Image: imageName, - Command: []string{"openshift-diagnostics", "diagnostic-pod", "-l", strconv.Itoa(loglevel)}, + Command: []string{"oc", "adm", "diagnostics", InPodDiagnosticRecommendedName, "-l", strconv.Itoa(loglevel)}, }, }, }, diff --git a/pkg/oc/admin/diagnostics/diagnostics/network/run_pod.go b/pkg/oc/admin/diagnostics/diagnostics/network/run_pod.go index f5274afc2e66..902c9896fafe 100644 --- a/pkg/oc/admin/diagnostics/diagnostics/network/run_pod.go +++ b/pkg/oc/admin/diagnostics/diagnostics/network/run_pod.go @@ -27,12 +27,13 @@ import ( ) const ( - NetworkDiagnosticName = "NetworkCheck" - FlagNetworkDiagLogDir = "logdir" - FlagNetworkDiagPodImage = "pod-image" - FlagNetworkDiagTestPodImage = "test-pod-image" - FlagNetworkDiagTestPodProtocol = "test-pod-protocol" - FlagNetworkDiagTestPodPort = "test-pod-port" + InPodNetworkCheckRecommendedName = "inpod-networkcheck" + NetworkDiagnosticName = "NetworkCheck" + FlagNetworkDiagLogDir = "logdir" + FlagNetworkDiagPodImage = "pod-image" + FlagNetworkDiagTestPodImage = "test-pod-image" + FlagNetworkDiagTestPodProtocol = "test-pod-protocol" + FlagNetworkDiagTestPodPort = "test-pod-port" ) // NetworkDiagnostic is a diagnostic that runs a network diagnostic pod and relays the results. @@ -181,7 +182,7 @@ func (d *NetworkDiagnostic) runNetworkDiagnostic() { // In Collection phase, results from each node are moved to the user machine where the CLI cmd is executed. // TEST Phase: Run network diagnostic pod on all valid nodes in parallel - command := fmt.Sprintf("openshift-diagnostics network-diagnostic-pod -l %d", loglevel) + command := fmt.Sprintf("oc adm diagnostics %s -l %d", InPodNetworkCheckRecommendedName, loglevel) if err := d.runNetworkPod(command); err != nil { d.res.Error("DNet2006", err, err.Error()) return diff --git a/pkg/oc/admin/diagnostics/network_pod.go b/pkg/oc/admin/diagnostics/network_pod.go index 01df1f1345d1..e79d037cb2d9 100644 --- a/pkg/oc/admin/diagnostics/network_pod.go +++ b/pkg/oc/admin/diagnostics/network_pod.go @@ -52,9 +52,10 @@ func NewCommandNetworkPodDiagnostics(name string, out io.Writer) *cobra.Command } cmd := &cobra.Command{ - Use: name, - Short: "Within a privileged pod, run network diagnostics", - Long: fmt.Sprintf(longNetworkPodDiagDescription), + Use: name, + Short: "Within a privileged pod, run network diagnostics", + Long: fmt.Sprintf(longNetworkPodDiagDescription), + Hidden: true, Run: func(c *cobra.Command, args []string) { kcmdutil.CheckErr(o.Complete(args)) diff --git a/pkg/oc/admin/diagnostics/pod.go b/pkg/oc/admin/diagnostics/pod.go index d6f0cd37f774..a87223011a13 100644 --- a/pkg/oc/admin/diagnostics/pod.go +++ b/pkg/oc/admin/diagnostics/pod.go @@ -50,9 +50,10 @@ func NewCommandPodDiagnostics(name string, out io.Writer) *cobra.Command { } cmd := &cobra.Command{ - Use: name, - Short: "Within a pod, run pod diagnostics", - Long: fmt.Sprintf(longPodDiagDescription), + Use: name, + Short: "Within a pod, run pod diagnostics", + Long: fmt.Sprintf(longPodDiagDescription), + Hidden: true, Run: func(c *cobra.Command, args []string) { kcmdutil.CheckErr(o.Complete(args))