// buildPodDiagnostics builds host Diagnostic objects based on the host environment. // 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 PodDiagnosticsOptions) buildPodDiagnostics() ([]types.Diagnostic, bool, []error) { diagnostics := []types.Diagnostic{} err, requestedDiagnostics := util.DetermineRequestedDiagnostics(availablePodDiagnostics.List(), o.RequestedDiagnostics, o.Logger) if err != nil { return diagnostics, false, []error{err} // don't waste time on discovery } // TODO: check we're actually in a container for _, diagnosticName := range requestedDiagnostics { switch diagnosticName { case poddiag.PodCheckDnsName: diagnostics = append(diagnostics, poddiag.PodCheckDns{}) case poddiag.PodCheckAuthName: diagnostics = append(diagnostics, poddiag.PodCheckAuth{ MasterCaPath: StandardMasterCaPath, TokenPath: StandardTokenPath, MasterUrl: StandardMasterUrl, }) default: return diagnostics, false, []error{fmt.Errorf("unknown diagnostic: %v", diagnosticName)} } } return diagnostics, true, nil }
// buildNetworkPodDiagnostics builds network Diagnostic objects based on the host environment. // 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 NetworkPodDiagnosticsOptions) buildNetworkPodDiagnostics() ([]types.Diagnostic, bool, []error) { diagnostics := []types.Diagnostic{} err, requestedDiagnostics := util.DetermineRequestedDiagnostics(availableNetworkPodDiagnostics.List(), o.RequestedDiagnostics, o.Logger) if err != nil { return diagnostics, false, []error{err} // don't waste time on discovery } clientFlags := flag.NewFlagSet("client", flag.ContinueOnError) // hide the extensive set of client flags factory := osclientcmd.New(clientFlags) // that would otherwise be added to this command osClient, kubeClient, clientErr := factory.Clients() if clientErr != nil { return diagnostics, false, []error{clientErr} } for _, diagnosticName := range requestedDiagnostics { switch diagnosticName { case networkdiag.CheckNodeNetworkName: diagnostics = append(diagnostics, networkdiag.CheckNodeNetwork{ KubeClient: kubeClient, }) case networkdiag.CheckPodNetworkName: diagnostics = append(diagnostics, networkdiag.CheckPodNetwork{ KubeClient: kubeClient, OSClient: osClient, }) case networkdiag.CheckExternalNetworkName: diagnostics = append(diagnostics, networkdiag.CheckExternalNetwork{}) case networkdiag.CheckServiceNetworkName: diagnostics = append(diagnostics, networkdiag.CheckServiceNetwork{ KubeClient: kubeClient, OSClient: osClient, }) case networkdiag.CollectNetworkInfoName: diagnostics = append(diagnostics, networkdiag.CollectNetworkInfo{ KubeClient: kubeClient, }) default: return diagnostics, false, []error{fmt.Errorf("unknown diagnostic: %v", diagnosticName)} } } return diagnostics, true, nil }