/
client.go
executable file
·45 lines (37 loc) · 1.82 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package diagnostics
import (
"fmt"
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
"k8s.io/kubernetes/pkg/util/sets"
clientdiags "github.com/openshift/origin/pkg/diagnostics/client"
"github.com/openshift/origin/pkg/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)
)
// 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
// osClient, kubeClient, clientErr := o.Factory.Clients() // use with a diagnostic that needs OpenShift/Kube client
_, _, clientErr := o.Factory.Clients()
if clientErr != nil {
o.Logger.Notice("CED0001", "Failed creating client from config; client diagnostics will be limited to config testing")
available = sets.NewString(clientdiags.ConfigContextsName)
}
diagnostics := []types.Diagnostic{}
requestedDiagnostics := intersection(sets.NewString(o.RequestedDiagnostics...), available).List()
for _, diagnosticName := range requestedDiagnostics {
switch diagnosticName {
case clientdiags.ConfigContextsName:
for contextName := range rawConfig.Contexts {
diagnostics = append(diagnostics, clientdiags.ConfigContext{RawConfig: rawConfig, ContextName: contextName})
}
default:
return nil, false, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
}
}
return diagnostics, true, clientErr
}