Skip to content

Commit

Permalink
feat(debug): add network/infraservice checker (first commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxglls committed Jun 17, 2021
1 parent d24a02a commit 73e2afa
Show file tree
Hide file tree
Showing 15 changed files with 2,582 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cmd/infra.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2021 The IOMesh Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/enescakir/emoji"
"github.com/spf13/cobra"

"github.com/iomesh/debugtool/pkg/infra/dns"
)

var infraCmd = &cobra.Command{
Use: "infra",
Short: "Verify infra service such as DNS working well",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("InfraService %v\n", emoji.Joystick)
dnsChecker := dns.NewDNSChecker()
if err := dnsChecker.Check(); err != nil {
return fmt.Errorf("Check dns fail: %v", err)
}
fmt.Println("")

return nil
},
}

func init() {
rootCmd.AddCommand(infraCmd)
}
50 changes: 50 additions & 0 deletions cmd/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2021 The IOMesh Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/enescakir/emoji"
"github.com/spf13/cobra"

"github.com/iomesh/debugtool/pkg/network/cni"
"github.com/iomesh/debugtool/pkg/network/hostnetwork"
)

// networkCmd represents the network command
var networkCmd = &cobra.Command{
Use: "network",
Short: "Verify connectivity and bandwidth of cni and hostnetwork",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("Network %v\n", emoji.ElectricPlug)
cniChecker := cni.NewCNIChecker()
if err := cniChecker.CheckConnectivity(); err != nil {
return err
}

hostNetworkChecker := hostnetwork.NewHostNetworkChecker()
if err := hostNetworkChecker.GetBandwidth(); err != nil {
return err
}
fmt.Println("")

return nil
},
}

func init() {
rootCmd.AddCommand(networkCmd)
}
61 changes: 61 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2021 The IOMesh Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/iomesh/debugtool/pkg/fixture"
)

var f = fixture.GetInstance()

var rootCmd = &cobra.Command{
Use: "debug",
Long: `IOMesh debugtool is used to detect whether the k8s environment meets
the installation conditions before installing IOMesh.`,

PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if cmd.Name() == "help" {
return nil
}
return f.EnsureBasicDsDeployed()
},
RunE: func(cmd *cobra.Command, args []string) error {
if err := networkCmd.RunE(cmd, args); err != nil {
return err
}
if err := infraCmd.RunE(cmd, args); err != nil {
return err
}
return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
if cmd.Name() == "help" {
return nil
}
return f.Cleanup()
},
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/iomesh/debugtool

go 1.15

replace k8s.io/client-go => k8s.io/client-go v0.20.2

require (
github.com/briandowns/spinner v1.15.0
github.com/enescakir/emoji v1.0.0
github.com/go-logr/logr v0.4.0
github.com/iomesh/operator v0.9.8
github.com/spf13/cobra v1.1.1
k8s.io/api v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/cli-runtime v0.20.2
k8s.io/client-go v12.0.0+incompatible
k8s.io/kubectl v0.20.2
sigs.k8s.io/controller-runtime v0.6.2
)
Loading

0 comments on commit 73e2afa

Please sign in to comment.