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 19, 2018
1 parent 34c5e71 commit 241fd4f
Show file tree
Hide file tree
Showing 76 changed files with 3,283 additions and 412 deletions.
1,242 changes: 1,228 additions & 14 deletions contrib/completions/bash/oc

Large diffs are not rendered by default.

1,242 changes: 1,228 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-aggregatedlogging.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-all.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-analyzelogs.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-clusterregistry.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-clusterrolebindings.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-clusterroles.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-clusterrouter.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-configcontexts.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-diagnosticpod.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-etcdwritevolume.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-masterconfigcheck.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-masternode.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-metricsapiproxy.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-networkcheck.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-nodeconfigcheck.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-nodedefinitions.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-routecertificatevalidation.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-serviceexternalips.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-adm-diagnostics-unitstatus.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-aggregatedlogging.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-all.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-analyzelogs.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-clusterregistry.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-clusterrolebindings.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-clusterroles.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-clusterrouter.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-configcontexts.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-diagnosticpod.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-etcdwritevolume.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-masterconfigcheck.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-masternode.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-metricsapiproxy.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-networkcheck.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-nodeconfigcheck.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-nodedefinitions.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-routecertificatevalidation.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-serviceexternalips.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/man/man1/oc-ex-diagnostics-unitstatus.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 23 additions & 29 deletions pkg/oc/admin/diagnostics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
"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 +30,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 @@ -46,29 +46,23 @@ func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Confi
}
}
case clientdiags.DiagnosticPodName:
diagnostics = append(diagnostics, &clientdiags.DiagnosticPod{
KubeClient: kubeClient,
Namespace: rawConfig.Contexts[rawConfig.CurrentContext].Namespace,
Level: o.LogOptions.Level,
Factory: o.Factory,
PreventModification: o.PreventModification,
ImageTemplate: o.ImageTemplate,
})
dp := o.ParameterizedDiagnostics[diagnosticName].(*clientdiags.DiagnosticPod)
dp.KubeClient = kubeClient
dp.Namespace = rawConfig.Contexts[rawConfig.CurrentContext].Namespace
dp.Level = o.LogOptions.Level
dp.Factory = o.Factory
dp.PreventModification = dp.PreventModification || o.PreventModification
diagnostics = append(diagnostics, dp)
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 241fd4f

Please sign in to comment.