Skip to content

Commit 73e2afa

Browse files
committed
feat(debug): add network/infraservice checker (first commit)
1 parent d24a02a commit 73e2afa

File tree

15 files changed

+2582
-0
lines changed

15 files changed

+2582
-0
lines changed

cmd/infra.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2021 The IOMesh Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
package cmd
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/enescakir/emoji"
21+
"github.com/spf13/cobra"
22+
23+
"github.com/iomesh/debugtool/pkg/infra/dns"
24+
)
25+
26+
var infraCmd = &cobra.Command{
27+
Use: "infra",
28+
Short: "Verify infra service such as DNS working well",
29+
RunE: func(cmd *cobra.Command, args []string) error {
30+
fmt.Printf("InfraService %v\n", emoji.Joystick)
31+
dnsChecker := dns.NewDNSChecker()
32+
if err := dnsChecker.Check(); err != nil {
33+
return fmt.Errorf("Check dns fail: %v", err)
34+
}
35+
fmt.Println("")
36+
37+
return nil
38+
},
39+
}
40+
41+
func init() {
42+
rootCmd.AddCommand(infraCmd)
43+
}

cmd/network.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2021 The IOMesh Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
package cmd
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/enescakir/emoji"
21+
"github.com/spf13/cobra"
22+
23+
"github.com/iomesh/debugtool/pkg/network/cni"
24+
"github.com/iomesh/debugtool/pkg/network/hostnetwork"
25+
)
26+
27+
// networkCmd represents the network command
28+
var networkCmd = &cobra.Command{
29+
Use: "network",
30+
Short: "Verify connectivity and bandwidth of cni and hostnetwork",
31+
RunE: func(cmd *cobra.Command, args []string) error {
32+
fmt.Printf("Network %v\n", emoji.ElectricPlug)
33+
cniChecker := cni.NewCNIChecker()
34+
if err := cniChecker.CheckConnectivity(); err != nil {
35+
return err
36+
}
37+
38+
hostNetworkChecker := hostnetwork.NewHostNetworkChecker()
39+
if err := hostNetworkChecker.GetBandwidth(); err != nil {
40+
return err
41+
}
42+
fmt.Println("")
43+
44+
return nil
45+
},
46+
}
47+
48+
func init() {
49+
rootCmd.AddCommand(networkCmd)
50+
}

cmd/root.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2021 The IOMesh Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
package cmd
16+
17+
import (
18+
"fmt"
19+
"os"
20+
21+
"github.com/spf13/cobra"
22+
23+
"github.com/iomesh/debugtool/pkg/fixture"
24+
)
25+
26+
var f = fixture.GetInstance()
27+
28+
var rootCmd = &cobra.Command{
29+
Use: "debug",
30+
Long: `IOMesh debugtool is used to detect whether the k8s environment meets
31+
the installation conditions before installing IOMesh.`,
32+
33+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
34+
if cmd.Name() == "help" {
35+
return nil
36+
}
37+
return f.EnsureBasicDsDeployed()
38+
},
39+
RunE: func(cmd *cobra.Command, args []string) error {
40+
if err := networkCmd.RunE(cmd, args); err != nil {
41+
return err
42+
}
43+
if err := infraCmd.RunE(cmd, args); err != nil {
44+
return err
45+
}
46+
return nil
47+
},
48+
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
49+
if cmd.Name() == "help" {
50+
return nil
51+
}
52+
return f.Cleanup()
53+
},
54+
}
55+
56+
func Execute() {
57+
if err := rootCmd.Execute(); err != nil {
58+
fmt.Println(err)
59+
os.Exit(1)
60+
}
61+
}

go.mod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module github.com/iomesh/debugtool
2+
3+
go 1.15
4+
5+
replace k8s.io/client-go => k8s.io/client-go v0.20.2
6+
7+
require (
8+
github.com/briandowns/spinner v1.15.0
9+
github.com/enescakir/emoji v1.0.0
10+
github.com/go-logr/logr v0.4.0
11+
github.com/iomesh/operator v0.9.8
12+
github.com/spf13/cobra v1.1.1
13+
k8s.io/api v0.20.2
14+
k8s.io/apimachinery v0.20.2
15+
k8s.io/cli-runtime v0.20.2
16+
k8s.io/client-go v12.0.0+incompatible
17+
k8s.io/kubectl v0.20.2
18+
sigs.k8s.io/controller-runtime v0.6.2
19+
)

0 commit comments

Comments
 (0)