Skip to content

Commit

Permalink
feat: add network check (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangSetSail authored Sep 6, 2022
1 parent 017f0c0 commit ec3cdfb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion controllers/rainbondcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"os"
"os/exec"
"strings"
"time"

Expand Down Expand Up @@ -51,7 +52,13 @@ type RainbondClusterReconciler struct {
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
func (r *RainbondClusterReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
reqLogger := r.Log.WithValues("rainbondcluster", request.NamespacedName)

cmdOne := exec.Command("ping", "registry.cn-hangzhou.aliyuncs.com", "-c", "1", "-W", "5")
errOne := cmdOne.Run()
cmdTwo := exec.Command("curl", "--connect-timeout", "1", "docker.io")
errTwo := cmdTwo.Run()
if errOne != nil && errTwo != nil {
return reconcile.Result{}, fmt.Errorf("外部网络不可用")
}
// Fetch the RainbondCluster instance
rainbondcluster := &rainbondv1alpha1.RainbondCluster{}
err := r.Get(ctx, request.NamespacedName, rainbondcluster)
Expand Down

0 comments on commit ec3cdfb

Please sign in to comment.