Skip to content

Commit a9387ba

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 45271ae commit a9387ba

File tree

76 files changed

+3238
-405
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

+3238
-405
lines changed

contrib/completions/bash/oc

+1,209-14
Large diffs are not rendered by default.

contrib/completions/zsh/oc

+1,209-14
Large diffs are not rendered by default.

docs/man/man1/.files_generated_oc

+38
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ oc-adm-create-node-config.1
3737
oc-adm-create-provider-selection-template.1
3838
oc-adm-create-server-cert.1
3939
oc-adm-create-signer-cert.1
40+
oc-adm-diagnostics-aggregatedlogging.1
41+
oc-adm-diagnostics-all.1
42+
oc-adm-diagnostics-analyzelogs.1
43+
oc-adm-diagnostics-clusterregistry.1
44+
oc-adm-diagnostics-clusterrolebindings.1
45+
oc-adm-diagnostics-clusterroles.1
46+
oc-adm-diagnostics-clusterrouter.1
47+
oc-adm-diagnostics-configcontexts.1
48+
oc-adm-diagnostics-diagnosticpod.1
49+
oc-adm-diagnostics-etcdwritevolume.1
50+
oc-adm-diagnostics-masterconfigcheck.1
51+
oc-adm-diagnostics-masternode.1
52+
oc-adm-diagnostics-metricsapiproxy.1
53+
oc-adm-diagnostics-networkcheck.1
54+
oc-adm-diagnostics-nodeconfigcheck.1
55+
oc-adm-diagnostics-nodedefinitions.1
56+
oc-adm-diagnostics-routecertificatevalidation.1
57+
oc-adm-diagnostics-serviceexternalips.1
58+
oc-adm-diagnostics-unitstatus.1
4059
oc-adm-diagnostics.1
4160
oc-adm-drain.1
4261
oc-adm-groups-add-users.1
@@ -171,6 +190,25 @@ oc-env.1
171190
oc-ex-build-chain.1
172191
oc-ex-config-patch.1
173192
oc-ex-config.1
193+
oc-ex-diagnostics-aggregatedlogging.1
194+
oc-ex-diagnostics-all.1
195+
oc-ex-diagnostics-analyzelogs.1
196+
oc-ex-diagnostics-clusterregistry.1
197+
oc-ex-diagnostics-clusterrolebindings.1
198+
oc-ex-diagnostics-clusterroles.1
199+
oc-ex-diagnostics-clusterrouter.1
200+
oc-ex-diagnostics-configcontexts.1
201+
oc-ex-diagnostics-diagnosticpod.1
202+
oc-ex-diagnostics-etcdwritevolume.1
203+
oc-ex-diagnostics-masterconfigcheck.1
204+
oc-ex-diagnostics-masternode.1
205+
oc-ex-diagnostics-metricsapiproxy.1
206+
oc-ex-diagnostics-networkcheck.1
207+
oc-ex-diagnostics-nodeconfigcheck.1
208+
oc-ex-diagnostics-nodedefinitions.1
209+
oc-ex-diagnostics-routecertificatevalidation.1
210+
oc-ex-diagnostics-serviceexternalips.1
211+
oc-ex-diagnostics-unitstatus.1
174212
oc-ex-diagnostics.1
175213
oc-ex-dockergc.1
176214
oc-ex-ipfailover.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.

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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is autogenerated, but we've stopped checking such files into the
2+
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
3+
populate this file.

pkg/oc/admin/diagnostics/client.go

+18-22
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ import (
66
"k8s.io/apimachinery/pkg/util/sets"
77
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
88

9+
"github.com/openshift/origin/pkg/cmd/util/variable"
910
clientdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/client"
1011
networkdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/network"
1112
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
1213
)
1314

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-
)
15+
// availableClientDiagnostics returns definitions 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+
func availableClientDiagnostics() types.DiagnosticList {
18+
return types.DiagnosticList{clientdiags.ConfigContext{}, &clientdiags.DiagnosticPod{}, &networkdiags.NetworkDiagnostic{}}
19+
}
1920

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

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

3233
diagnostics := []types.Diagnostic{}
33-
requestedDiagnostics := available.Intersection(sets.NewString(o.RequestedDiagnostics...)).List()
34+
requestedDiagnostics := available.Intersection(sets.NewString(o.RequestedDiagnostics.List()...)).List()
3435
for _, diagnosticName := range requestedDiagnostics {
3536
switch diagnosticName {
3637
case clientdiags.ConfigContextsName:
@@ -52,23 +53,18 @@ func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Confi
5253
Level: o.LogOptions.Level,
5354
Factory: o.Factory,
5455
PreventModification: o.PreventModification,
55-
ImageTemplate: o.ImageTemplate,
56+
ImageTemplate: variable.NewDefaultImageTemplate(),
5657
})
5758
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-
})
59+
nd := o.ParameterizedDiagnostics[diagnosticName].(*networkdiags.NetworkDiagnostic)
60+
nd.KubeClient = kubeClient
61+
nd.NetNamespacesClient = networkClient.Network()
62+
nd.ClusterNetworkClient = networkClient.Network()
63+
nd.ClientFlags = o.ClientFlags
64+
nd.Level = o.LogOptions.Level
65+
nd.Factory = o.Factory
66+
nd.PreventModification = o.PreventModification
67+
diagnostics = append(diagnostics, nd)
7268
default:
7369
return nil, false, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
7470
}

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)