Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagnostic reorg and NetworkCheck fix #18709

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions pkg/oc/admin/diagnostics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ import (

clientdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/client"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/client/pod"
networkdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/network"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
)

// 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{}, &pod.DiagnosticPod{}, &networkdiags.NetworkDiagnostic{}}
return types.DiagnosticList{clientdiags.ConfigContext{}, &pod.DiagnosticPod{}}
}

// buildClientDiagnostics builds client Diagnostic objects based on the rawConfig passed in.
// Returns the Diagnostics built, and any fatal errors encountered during the building of diagnostics.
func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Config) ([]types.Diagnostic, error) {
available := availableClientDiagnostics().Names()

networkClient, err := o.Factory.OpenshiftInternalNetworkClient()
kubeClient, clientErr := o.Factory.ClientSet()
if clientErr != nil || err != nil {
if clientErr != nil {
o.Logger().Notice("CED0001", "Could not configure a client, so client diagnostics are limited to testing configuration and connection")
available = sets.NewString(clientdiags.ConfigContextsName)
}
Expand Down Expand Up @@ -54,16 +52,6 @@ func (o DiagnosticsOptions) buildClientDiagnostics(rawConfig *clientcmdapi.Confi
dp.Factory = o.Factory
dp.PreventModification = dp.PreventModification || o.PreventModification
diagnostics = append(diagnostics, dp)
case networkdiags.NetworkDiagnosticName:
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, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/oc/admin/diagnostics/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (
appsclient "github.com/openshift/origin/pkg/apps/generated/internalclientset"
oauthorizationclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset"
networkclient "github.com/openshift/origin/pkg/network/generated/internalclientset"
oauthclient "github.com/openshift/origin/pkg/oauth/generated/internalclientset"
clustdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster"
agldiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/aggregated_logging"
appcreate "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/app_create"
networkdiags "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
osclientcmd "github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
projectclient "github.com/openshift/origin/pkg/project/generated/internalclientset"
Expand All @@ -41,6 +43,7 @@ func availableClusterDiagnostics() types.DiagnosticList {
&clustdiags.NodeDefinitions{},
&clustdiags.RouteCertificateValidation{},
&clustdiags.ServiceExternalIPs{},
&networkdiags.NetworkDiagnostic{},
}
}

Expand Down Expand Up @@ -90,6 +93,10 @@ func (o DiagnosticsOptions) buildClusterDiagnostics(rawConfig *clientcmdapi.Conf
if err != nil {
return nil, err
}
networkClient, err := networkclient.NewForConfig(config)
if err != nil {
return nil, err
}

diagnostics := []types.Diagnostic{}
for _, diagnosticName := range requestedDiagnostics {
Expand Down Expand Up @@ -126,6 +133,16 @@ func (o DiagnosticsOptions) buildClusterDiagnostics(rawConfig *clientcmdapi.Conf
d = &clustdiags.ServiceExternalIPs{MasterConfigFile: o.MasterConfigLocation, KclusterClient: kclusterClient}
case clustdiags.RouteCertificateValidationName:
d = &clustdiags.RouteCertificateValidation{SARClient: kclusterClient.Authorization(), RESTConfig: config}
case networkdiags.NetworkDiagnosticName:
nd := o.ParameterizedDiagnostics[diagnosticName].(*networkdiags.NetworkDiagnostic)
nd.KubeClient = kclusterClient
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could cause empty d to be added to diagnostics in this iteration.

default:
return nil, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/admin/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/openshift/origin/pkg/client/config"
"github.com/openshift/origin/pkg/cmd/flagtypes"
poddiag "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/client/pod/in_pod"
networkpoddiag "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/log"
networkdiag "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/network"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/options"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/util"
Expand Down Expand Up @@ -135,7 +135,7 @@ func NewCmdDiagnostics(name string, fullName string, out io.Writer) *cobra.Comma
// add hidden in-pod subcommands
cmd.AddCommand(
poddiag.NewCommandPodDiagnostics(poddiag.InPodDiagnosticRecommendedName, out),
NewCommandNetworkPodDiagnostics(networkdiag.InPodNetworkCheckRecommendedName, out),
networkpoddiag.NewCommandNetworkPodDiagnostics(networkpoddiag.InPodNetworkCheckRecommendedName, out),
)

return cmd
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package diagnostics
package in_pod

import (
"fmt"
Expand All @@ -12,13 +12,16 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"

"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/log"
networkdiag "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/options"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/util"
osclientcmd "github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
)

const (
InPodNetworkCheckRecommendedName = "inpod-networkcheck"
)

// NetworkPodDiagnosticsOptions holds values received from environment variables
// for the command to operate.
type NetworkPodDiagnosticsOptions struct {
Expand All @@ -38,7 +41,7 @@ log the results so that the calling diagnostic can report them.
var (
// availableNetworkPodDiagnostics contains the names of network diagnostics that can be executed
// during a single run of diagnostics. Add more diagnostics to the list as they are defined.
availableNetworkPodDiagnostics = sets.NewString(networkdiag.CheckNodeNetworkName, networkdiag.CheckPodNetworkName, networkdiag.CheckExternalNetworkName, networkdiag.CheckServiceNetworkName, networkdiag.CollectNetworkInfoName)
availableNetworkPodDiagnostics = sets.NewString(CheckNodeNetworkName, CheckPodNetworkName, CheckExternalNetworkName, CheckServiceNetworkName, CollectNetworkInfoName)
)

// NewCommandNetworkPodDiagnostics is the command for running network diagnostics.
Expand Down Expand Up @@ -128,30 +131,30 @@ func (o NetworkPodDiagnosticsOptions) buildNetworkPodDiagnostics() ([]types.Diag
for _, diagnosticName := range requestedDiagnostics {
switch diagnosticName {

case networkdiag.CheckNodeNetworkName:
diagnostics = append(diagnostics, networkdiag.CheckNodeNetwork{
case CheckNodeNetworkName:
diagnostics = append(diagnostics, CheckNodeNetwork{
KubeClient: kubeClient,
})

case networkdiag.CheckPodNetworkName:
diagnostics = append(diagnostics, networkdiag.CheckPodNetwork{
case CheckPodNetworkName:
diagnostics = append(diagnostics, CheckPodNetwork{
KubeClient: kubeClient,
NetNamespacesClient: networkClient.Network(),
ClusterNetworkClient: networkClient.Network(),
})

case networkdiag.CheckExternalNetworkName:
diagnostics = append(diagnostics, networkdiag.CheckExternalNetwork{})
case CheckExternalNetworkName:
diagnostics = append(diagnostics, CheckExternalNetwork{})

case networkdiag.CheckServiceNetworkName:
diagnostics = append(diagnostics, networkdiag.CheckServiceNetwork{
case CheckServiceNetworkName:
diagnostics = append(diagnostics, CheckServiceNetwork{
KubeClient: kubeClient,
NetNamespacesClient: networkClient.Network(),
ClusterNetworkClient: networkClient.Network(),
})

case networkdiag.CollectNetworkInfoName:
diagnostics = append(diagnostics, networkdiag.CollectNetworkInfo{
case CollectNetworkInfoName:
diagnostics = append(diagnostics, CollectNetworkInfo{
KubeClient: kubeClient,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package in_pod

import (
"errors"
Expand All @@ -7,7 +7,7 @@ import (

kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"

"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package in_pod

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package in_pod

import (
"errors"
Expand All @@ -10,7 +10,7 @@ import (
kcontainer "k8s.io/kubernetes/pkg/kubelet/container"
kexec "k8s.io/utils/exec"

"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package in_pod

import (
"errors"
Expand All @@ -13,7 +13,7 @@ import (

"github.com/openshift/origin/pkg/network"
networktypedclient "github.com/openshift/origin/pkg/network/generated/internalclientset/typed/network/internalversion"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package in_pod

import (
"errors"
Expand All @@ -13,7 +13,7 @@ import (

"github.com/openshift/origin/pkg/network"
networktypedclient "github.com/openshift/origin/pkg/network/generated/internalclientset/typed/network/internalversion"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
kclientcmd "k8s.io/client-go/tools/clientcmd"
kapi "k8s.io/kubernetes/pkg/apis/core"

"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/util"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
kerrs "k8s.io/apimachinery/pkg/util/errors"
kapi "k8s.io/kubernetes/pkg/apis/core"

"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/util"
)

func (d *NetworkDiagnostic) CollectNetworkPodLogs() error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ import (
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"

networktypedclient "github.com/openshift/origin/pkg/network/generated/internalclientset/typed/network/internalversion"
networkpoddiag "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/log"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
osclientcmd "github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
)

const (
InPodNetworkCheckRecommendedName = "inpod-networkcheck"
NetworkDiagnosticName = "NetworkCheck"
FlagNetworkDiagLogDir = "logdir"
FlagNetworkDiagPodImage = "pod-image"
FlagNetworkDiagTestPodImage = "test-pod-image"
FlagNetworkDiagTestPodProtocol = "test-pod-protocol"
FlagNetworkDiagTestPodPort = "test-pod-port"
NetworkDiagnosticName = "NetworkCheck"
FlagNetworkDiagLogDir = "logdir"
FlagNetworkDiagPodImage = "pod-image"
FlagNetworkDiagTestPodImage = "test-pod-image"
FlagNetworkDiagTestPodProtocol = "test-pod-protocol"
FlagNetworkDiagTestPodPort = "test-pod-port"
)

// NetworkDiagnostic is a diagnostic that runs a network diagnostic pod and relays the results.
Expand Down Expand Up @@ -182,7 +182,7 @@ func (d *NetworkDiagnostic) runNetworkDiagnostic() {
// In Collection phase, results from each node are moved to the user machine where the CLI cmd is executed.

// TEST Phase: Run network diagnostic pod on all valid nodes in parallel
command := fmt.Sprintf("oc adm diagnostics %s -l %d", InPodNetworkCheckRecommendedName, loglevel)
command := fmt.Sprintf("oc adm diagnostics %s -l %d", networkpoddiag.InPodNetworkCheckRecommendedName, loglevel)
if err := d.runNetworkPod(command); err != nil {
d.res.Error("DNet2006", err, err.Error())
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/openshift/origin/pkg/client/config"
"github.com/openshift/origin/pkg/network"
networkapi "github.com/openshift/origin/pkg/network/apis/network"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/networkpod/util"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/util"
diagutil "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/util"
)

Expand Down