Skip to content

Commit

Permalink
diagnostics: enable per-diagnostic parameters
Browse files Browse the repository at this point in the history
Adds the ability to specify parameters for individual diagnostics on the
command line (without proliferating flags).

Addresses #14640
  • Loading branch information
sosiouxme committed Jan 10, 2018
1 parent 45271ae commit a9387ba
Show file tree
Hide file tree
Showing 76 changed files with 3,238 additions and 405 deletions.
1,223 changes: 1,209 additions & 14 deletions contrib/completions/bash/oc

Large diffs are not rendered by default.

1,223 changes: 1,209 additions & 14 deletions contrib/completions/zsh/oc

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions docs/man/man1/.files_generated_oc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ oc-adm-create-node-config.1
oc-adm-create-provider-selection-template.1
oc-adm-create-server-cert.1
oc-adm-create-signer-cert.1
oc-adm-diagnostics-aggregatedlogging.1
oc-adm-diagnostics-all.1
oc-adm-diagnostics-analyzelogs.1
oc-adm-diagnostics-clusterregistry.1
oc-adm-diagnostics-clusterrolebindings.1
oc-adm-diagnostics-clusterroles.1
oc-adm-diagnostics-clusterrouter.1
oc-adm-diagnostics-configcontexts.1
oc-adm-diagnostics-diagnosticpod.1
oc-adm-diagnostics-etcdwritevolume.1
oc-adm-diagnostics-masterconfigcheck.1
oc-adm-diagnostics-masternode.1
oc-adm-diagnostics-metricsapiproxy.1
oc-adm-diagnostics-networkcheck.1
oc-adm-diagnostics-nodeconfigcheck.1
oc-adm-diagnostics-nodedefinitions.1
oc-adm-diagnostics-routecertificatevalidation.1
oc-adm-diagnostics-serviceexternalips.1
oc-adm-diagnostics-unitstatus.1
oc-adm-diagnostics.1
oc-adm-drain.1
oc-adm-groups-add-users.1
Expand Down Expand Up @@ -171,6 +190,25 @@ oc-env.1
oc-ex-build-chain.1
oc-ex-config-patch.1
oc-ex-config.1
oc-ex-diagnostics-aggregatedlogging.1
oc-ex-diagnostics-all.1
oc-ex-diagnostics-analyzelogs.1
oc-ex-diagnostics-clusterregistry.1
oc-ex-diagnostics-clusterrolebindings.1
oc-ex-diagnostics-clusterroles.1
oc-ex-diagnostics-clusterrouter.1
oc-ex-diagnostics-configcontexts.1
oc-ex-diagnostics-diagnosticpod.1
oc-ex-diagnostics-etcdwritevolume.1
oc-ex-diagnostics-masterconfigcheck.1
oc-ex-diagnostics-masternode.1
oc-ex-diagnostics-metricsapiproxy.1
oc-ex-diagnostics-networkcheck.1
oc-ex-diagnostics-nodeconfigcheck.1
oc-ex-diagnostics-nodedefinitions.1
oc-ex-diagnostics-routecertificatevalidation.1
oc-ex-diagnostics-serviceexternalips.1
oc-ex-diagnostics-unitstatus.1
oc-ex-diagnostics.1
oc-ex-dockergc.1
oc-ex-ipfailover.1
Expand Down
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-aggregatedlogging.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-all.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-analyzelogs.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-clusterregistry.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-clusterrolebindings.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-clusterroles.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-clusterrouter.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-configcontexts.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-diagnosticpod.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-etcdwritevolume.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-masterconfigcheck.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-masternode.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-metricsapiproxy.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-networkcheck.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-nodeconfigcheck.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-nodedefinitions.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-routecertificatevalidation.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-serviceexternalips.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-unitstatus.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-aggregatedlogging.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-all.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-analyzelogs.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-clusterregistry.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-clusterrolebindings.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-clusterroles.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-clusterrouter.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-configcontexts.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-diagnosticpod.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-etcdwritevolume.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-masterconfigcheck.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-masternode.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-metricsapiproxy.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-networkcheck.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-nodeconfigcheck.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-nodedefinitions.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-routecertificatevalidation.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-serviceexternalips.1
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-unitstatus.1
Original file line number Diff line number Diff line change
@@ -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.
40 changes: 18 additions & 22 deletions pkg/oc/admin/diagnostics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"

"github.com/openshift/origin/pkg/cmd/util/variable"
clientdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/client"
networkdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/network"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
)

var (
// availableClientDiagnostics contains the names of client diagnostics that can be executed
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
availableClientDiagnostics = sets.NewString(clientdiags.ConfigContextsName, clientdiags.DiagnosticPodName, networkdiags.NetworkDiagnosticName)
)
// availableClientDiagnostics returns definitions of client diagnostics that can be executed
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
func availableClientDiagnostics() types.DiagnosticList {
return types.DiagnosticList{clientdiags.ConfigContext{}, &clientdiags.DiagnosticPod{}, &networkdiags.NetworkDiagnostic{}}
}

// buildClientDiagnostics builds client Diagnostic objects based on the rawConfig passed in.
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Config) ([]types.Diagnostic, bool, error) {
available := availableClientDiagnostics
available := availableClientDiagnostics().Names()

networkClient, err := o.Factory.OpenshiftInternalNetworkClient()
kubeClient, clientErr := o.Factory.ClientSet()
Expand All @@ -30,7 +31,7 @@ func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Confi
}

diagnostics := []types.Diagnostic{}
requestedDiagnostics := available.Intersection(sets.NewString(o.RequestedDiagnostics...)).List()
requestedDiagnostics := available.Intersection(sets.NewString(o.RequestedDiagnostics.List()...)).List()
for _, diagnosticName := range requestedDiagnostics {
switch diagnosticName {
case clientdiags.ConfigContextsName:
Expand All @@ -52,23 +53,18 @@ func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Confi
Level: o.LogOptions.Level,
Factory: o.Factory,
PreventModification: o.PreventModification,
ImageTemplate: o.ImageTemplate,
ImageTemplate: variable.NewDefaultImageTemplate(),
})
case networkdiags.NetworkDiagnosticName:
diagnostics = append(diagnostics, &networkdiags.NetworkDiagnostic{
KubeClient: kubeClient,
NetNamespacesClient: networkClient.Network(),
ClusterNetworkClient: networkClient.Network(),
ClientFlags: o.ClientFlags,
Level: o.LogOptions.Level,
Factory: o.Factory,
PreventModification: o.PreventModification,
LogDir: o.NetworkOptions.LogDir,
PodImage: o.NetworkOptions.PodImage,
TestPodImage: o.NetworkOptions.TestPodImage,
TestPodProtocol: o.NetworkOptions.TestPodProtocol,
TestPodPort: o.NetworkOptions.TestPodPort,
})
nd := o.ParameterizedDiagnostics[diagnosticName].(*networkdiags.NetworkDiagnostic)
nd.KubeClient = kubeClient
nd.NetNamespacesClient = networkClient.Network()
nd.ClusterNetworkClient = networkClient.Network()
nd.ClientFlags = o.ClientFlags
nd.Level = o.LogOptions.Level
nd.Factory = o.Factory
nd.PreventModification = o.PreventModification
diagnostics = append(diagnostics, nd)
default:
return nil, false, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
}
Expand Down
34 changes: 17 additions & 17 deletions pkg/oc/admin/diagnostics/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ import (
"k8s.io/kubernetes/pkg/apis/authorization"
)

var (
// availableClusterDiagnostics contains the names of cluster diagnostics that can be executed
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
availableClusterDiagnostics = sets.NewString(
agldiags.AggregatedLoggingName,
clustdiags.ClusterRegistryName,
clustdiags.ClusterRouterName,
clustdiags.ClusterRolesName,
clustdiags.ClusterRoleBindingsName,
clustdiags.MasterNodeName,
clustdiags.MetricsApiProxyName,
clustdiags.NodeDefinitionsName,
clustdiags.RouteCertificateValidationName,
clustdiags.ServiceExternalIPsName,
)
)
// availableClusterDiagnostics contains the names of cluster diagnostics that can be executed
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
func availableClusterDiagnostics() types.DiagnosticList {
return types.DiagnosticList{
&agldiags.AggregatedLogging{},
&clustdiags.ClusterRegistry{},
&clustdiags.ClusterRouter{},
&clustdiags.ClusterRoles{},
&clustdiags.ClusterRoleBindings{},
&clustdiags.MasterNode{},
&clustdiags.MetricsApiProxy{},
&clustdiags.NodeDefinitions{},
&clustdiags.RouteCertificateValidation{},
&clustdiags.ServiceExternalIPs{},
}
}

// buildClusterDiagnostics builds cluster Diagnostic objects if a cluster-admin client can be extracted from the rawConfig passed in.
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
func (o DiagnosticsOptions) buildClusterDiagnostics(rawConfig *clientcmdapi.Config) ([]types.Diagnostic, bool, error) {
requestedDiagnostics := availableClusterDiagnostics.Intersection(sets.NewString(o.RequestedDiagnostics...)).List()
requestedDiagnostics := availableClusterDiagnostics().Names().Intersection(sets.NewString(o.RequestedDiagnostics.List()...)).List()
if len(requestedDiagnostics) == 0 { // no diagnostics to run here
return nil, true, nil // don't waste time on discovery
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/oc/admin/diagnostics/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
)

// determine if we even have a client config
func (o DiagnosticsOptions) detectClientConfig() (bool, []types.DiagnosticError, []types.DiagnosticError) {
func (o DiagnosticsOptions) detectClientConfig() (bool, bool, []types.DiagnosticError, []types.DiagnosticError) {
if o.ClientFlags == nil {
return false, false, []types.DiagnosticError{}, []types.DiagnosticError{}
}
diagnostic := &clientdiagnostics.ConfigLoading{ConfFlagName: config.OpenShiftConfigFlagName, ClientFlags: o.ClientFlags}
o.Logger.Notice("CED2011", "Determining if client configuration exists for client/cluster diagnostics")
result := diagnostic.Check()
for _, entry := range result.Logs() {
o.Logger.LogEntry(entry)
}
return diagnostic.SuccessfulLoad(), result.Warnings(), result.Errors()
return true, diagnostic.SuccessfulLoad(), result.Warnings(), result.Errors()
}

// use the base factory to return a raw config (not specific to a context)
Expand Down
Loading

0 comments on commit a9387ba

Please sign in to comment.