Skip to content

Commit 241fd4f

Browse files
committed
diagnostics: enable per-diagnostic parameters
Adds the ability to specify parameters for individual diagnostics on the command line (without proliferating flags). Addresses #14640
1 parent 34c5e71 commit 241fd4f

File tree

76 files changed

+3283
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3283
-412
lines changed

contrib/completions/bash/oc

+1,228-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zsh/oc

+1,228-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/.files_generated_oc

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-aggregatedlogging.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-all.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-analyzelogs.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-clusterregistry.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-clusterrolebindings.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-clusterroles.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-clusterrouter.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-configcontexts.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-diagnosticpod.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-etcdwritevolume.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-masterconfigcheck.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-masternode.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-metricsapiproxy.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-networkcheck.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-nodeconfigcheck.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-nodedefinitions.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-routecertificatevalidation.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-serviceexternalips.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-adm-diagnostics-unitstatus.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-aggregatedlogging.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-all.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-analyzelogs.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-clusterregistry.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-clusterrolebindings.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-clusterroles.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-clusterrouter.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-configcontexts.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-diagnosticpod.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-etcdwritevolume.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-masterconfigcheck.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-masternode.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-metricsapiproxy.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-networkcheck.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-nodeconfigcheck.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-nodedefinitions.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-routecertificatevalidation.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-serviceexternalips.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-ex-diagnostics-unitstatus.1

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oc/admin/diagnostics/client.go

+23-29
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import (
1111
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
1212
)
1313

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

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

2525
networkClient, err := o.Factory.OpenshiftInternalNetworkClient()
2626
kubeClient, clientErr := o.Factory.ClientSet()
@@ -30,7 +30,7 @@ func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Confi
3030
}
3131

3232
diagnostics := []types.Diagnostic{}
33-
requestedDiagnostics := available.Intersection(sets.NewString(o.RequestedDiagnostics...)).List()
33+
requestedDiagnostics := available.Intersection(sets.NewString(o.RequestedDiagnostics.List()...)).List()
3434
for _, diagnosticName := range requestedDiagnostics {
3535
switch diagnosticName {
3636
case clientdiags.ConfigContextsName:
@@ -46,29 +46,23 @@ func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Confi
4646
}
4747
}
4848
case clientdiags.DiagnosticPodName:
49-
diagnostics = append(diagnostics, &clientdiags.DiagnosticPod{
50-
KubeClient: kubeClient,
51-
Namespace: rawConfig.Contexts[rawConfig.CurrentContext].Namespace,
52-
Level: o.LogOptions.Level,
53-
Factory: o.Factory,
54-
PreventModification: o.PreventModification,
55-
ImageTemplate: o.ImageTemplate,
56-
})
49+
dp := o.ParameterizedDiagnostics[diagnosticName].(*clientdiags.DiagnosticPod)
50+
dp.KubeClient = kubeClient
51+
dp.Namespace = rawConfig.Contexts[rawConfig.CurrentContext].Namespace
52+
dp.Level = o.LogOptions.Level
53+
dp.Factory = o.Factory
54+
dp.PreventModification = dp.PreventModification || o.PreventModification
55+
diagnostics = append(diagnostics, dp)
5756
case networkdiags.NetworkDiagnosticName:
58-
diagnostics = append(diagnostics, &networkdiags.NetworkDiagnostic{
59-
KubeClient: kubeClient,
60-
NetNamespacesClient: networkClient.Network(),
61-
ClusterNetworkClient: networkClient.Network(),
62-
ClientFlags: o.ClientFlags,
63-
Level: o.LogOptions.Level,
64-
Factory: o.Factory,
65-
PreventModification: o.PreventModification,
66-
LogDir: o.NetworkOptions.LogDir,
67-
PodImage: o.NetworkOptions.PodImage,
68-
TestPodImage: o.NetworkOptions.TestPodImage,
69-
TestPodProtocol: o.NetworkOptions.TestPodProtocol,
70-
TestPodPort: o.NetworkOptions.TestPodPort,
71-
})
57+
nd := o.ParameterizedDiagnostics[diagnosticName].(*networkdiags.NetworkDiagnostic)
58+
nd.KubeClient = kubeClient
59+
nd.NetNamespacesClient = networkClient.Network()
60+
nd.ClusterNetworkClient = networkClient.Network()
61+
nd.ClientFlags = o.ClientFlags
62+
nd.Level = o.LogOptions.Level
63+
nd.Factory = o.Factory
64+
nd.PreventModification = o.PreventModification
65+
diagnostics = append(diagnostics, nd)
7266
default:
7367
return nil, false, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
7468
}

pkg/oc/admin/diagnostics/cluster.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ import (
2525
"k8s.io/kubernetes/pkg/apis/authorization"
2626
)
2727

28-
var (
29-
// availableClusterDiagnostics contains the names of cluster diagnostics that can be executed
30-
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
31-
availableClusterDiagnostics = sets.NewString(
32-
agldiags.AggregatedLoggingName,
33-
clustdiags.ClusterRegistryName,
34-
clustdiags.ClusterRouterName,
35-
clustdiags.ClusterRolesName,
36-
clustdiags.ClusterRoleBindingsName,
37-
clustdiags.MasterNodeName,
38-
clustdiags.MetricsApiProxyName,
39-
clustdiags.NodeDefinitionsName,
40-
clustdiags.RouteCertificateValidationName,
41-
clustdiags.ServiceExternalIPsName,
42-
)
43-
)
28+
// availableClusterDiagnostics contains the names of cluster diagnostics that can be executed
29+
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
30+
func availableClusterDiagnostics() types.DiagnosticList {
31+
return types.DiagnosticList{
32+
&agldiags.AggregatedLogging{},
33+
&clustdiags.ClusterRegistry{},
34+
&clustdiags.ClusterRouter{},
35+
&clustdiags.ClusterRoles{},
36+
&clustdiags.ClusterRoleBindings{},
37+
&clustdiags.MasterNode{},
38+
&clustdiags.MetricsApiProxy{},
39+
&clustdiags.NodeDefinitions{},
40+
&clustdiags.RouteCertificateValidation{},
41+
&clustdiags.ServiceExternalIPs{},
42+
}
43+
}
4444

4545
// buildClusterDiagnostics builds cluster Diagnostic objects if a cluster-admin client can be extracted from the rawConfig passed in.
4646
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
4747
func (o DiagnosticsOptions) buildClusterDiagnostics(rawConfig *clientcmdapi.Config) ([]types.Diagnostic, bool, error) {
48-
requestedDiagnostics := availableClusterDiagnostics.Intersection(sets.NewString(o.RequestedDiagnostics...)).List()
48+
requestedDiagnostics := availableClusterDiagnostics().Names().Intersection(sets.NewString(o.RequestedDiagnostics.List()...)).List()
4949
if len(requestedDiagnostics) == 0 { // no diagnostics to run here
5050
return nil, true, nil // don't waste time on discovery
5151
}

pkg/oc/admin/diagnostics/config.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import (
1111
)
1212

1313
// determine if we even have a client config
14-
func (o DiagnosticsOptions) detectClientConfig() (bool, []types.DiagnosticError, []types.DiagnosticError) {
14+
func (o DiagnosticsOptions) detectClientConfig() (bool, bool, []types.DiagnosticError, []types.DiagnosticError) {
15+
if o.ClientFlags == nil {
16+
return false, false, []types.DiagnosticError{}, []types.DiagnosticError{}
17+
}
1518
diagnostic := &clientdiagnostics.ConfigLoading{ConfFlagName: config.OpenShiftConfigFlagName, ClientFlags: o.ClientFlags}
1619
o.Logger.Notice("CED2011", "Determining if client configuration exists for client/cluster diagnostics")
1720
result := diagnostic.Check()
1821
for _, entry := range result.Logs() {
1922
o.Logger.LogEntry(entry)
2023
}
21-
return diagnostic.SuccessfulLoad(), result.Warnings(), result.Errors()
24+
return true, diagnostic.SuccessfulLoad(), result.Warnings(), result.Errors()
2225
}
2326

2427
// use the base factory to return a raw config (not specific to a context)

0 commit comments

Comments
 (0)