Skip to content

Commit

Permalink
support: delete useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
kizuna-lek committed Dec 17, 2024
1 parent fa8e848 commit e1f7316
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 72 deletions.
8 changes: 4 additions & 4 deletions dcs/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func NewKubernetesStore() (*KubernetesStore, error) {

clusterName := constant.GetClusterName()
if clusterName == "" {
return nil, errors.New(fmt.Sprintf("%s must be set", constant.KBEnvClusterName))
return nil, errors.New(fmt.Sprintf("%s or %s must be set", constant.EnvClusterName, constant.KBEnvClusterName))
}

componentName := constant.GetComponentName()
if componentName == "" {
return nil, errors.New(fmt.Sprintf("%s must be set", constant.KBEnvCompName))
return nil, errors.New(fmt.Sprintf("%s or %s must be set", constant.EnvComponentName, constant.KBEnvCompName))
}

clusterCompName := constant.GetClusterCompName()
Expand All @@ -92,12 +92,12 @@ func NewKubernetesStore() (*KubernetesStore, error) {

currentMemberName := constant.GetPodName()
if currentMemberName == "" {
return nil, errors.Wrap(err, "get hostname failed")
return nil, errors.New("get hostname failed")
}

namespace := constant.GetNamespace()
if namespace == "" {
return nil, errors.New("KB_NAMESPACE must be set")
return nil, errors.New(fmt.Sprintf("%s or %s must be set", constant.EnvNamespace, constant.KBEnvNamespace))
}

isLeaderClusterWide := false
Expand Down
5 changes: 2 additions & 3 deletions engines/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/spf13/viper"

"github.com/apecloud/dbctl/constant"
"github.com/apecloud/dbctl/dcs"
Expand Down Expand Up @@ -53,8 +52,8 @@ func NewDBManagerBase(logger logr.Logger) (*DBManagerBase, error) {
mgr := DBManagerBase{
CurrentMemberName: currentMemberName,
CurrentMemberIP: constant.GetPodIP(),
ClusterCompName: viper.GetString(constant.KBEnvClusterCompName),
Namespace: viper.GetString(constant.KBEnvNamespace),
ClusterCompName: constant.GetClusterCompName(),
Namespace: constant.GetNamespace(),
Logger: logger,
}
return &mgr, nil
Expand Down
4 changes: 2 additions & 2 deletions engines/mongodb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func NewConfig(properties map[string]string) (*Config, error) {
config.Password = viper.GetString(RootPasswordEnv)
}

if viper.IsSet(constant.KBEnvClusterCompName) {
config.ReplSetName = viper.GetString(constant.KBEnvClusterCompName)
if clusterCompName := constant.GetClusterCompName(); clusterCompName != "" {
config.ReplSetName = clusterCompName
}

config.DatabaseName = adminDatabase
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ require (
github.com/IBM/sarama v1.43.2
github.com/apecloud/kubeblocks v0.9.0
github.com/cenkalti/backoff/v4 v4.2.1
github.com/deckarep/golang-set/v2 v2.6.0
github.com/dlclark/regexp2 v1.11.0
github.com/fasthttp/router v1.4.20
github.com/go-logr/logr v1.4.2
github.com/go-logr/zapr v1.3.0
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM=
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/eapache/go-resiliency v1.6.0 h1:CqGDTLtpwuWKn6Nj3uNUdflaq+/kIPsg0gfNzHton30=
Expand Down
5 changes: 2 additions & 3 deletions util/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"time"

"github.com/spf13/viper"
Expand Down Expand Up @@ -78,7 +77,7 @@ func CreateEvent(reason string, data map[string]any) (*corev1.Event, error) {
podName := constant.GetPodName()
podUID := constant.GetPodUID()
nodeName := viper.GetString(constant.KBEnvNodeName)
namespace := viper.GetString(constant.KBEnvNamespace)
namespace := constant.GetNamespace()
msg, err := json.Marshal(data)
if err != nil {
return nil, err
Expand Down Expand Up @@ -126,7 +125,7 @@ func SendEvent(ctx context.Context, event *corev1.Event) error {
logger.Info("k8s client create failed", "error", err.Error())
return err
}
namespace := os.Getenv(constant.KBEnvNamespace)
namespace := constant.GetNamespace()
for i := 0; i < 30; i++ {
_, err = clientset.CoreV1().Events(namespace).Create(ctx1, event, metav1.CreateOptions{})
if err == nil {
Expand Down
54 changes: 0 additions & 54 deletions util/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,8 @@ package util
import (
"net"
"time"

"github.com/spf13/viper"
ctlruntime "sigs.k8s.io/controller-runtime"

"github.com/apecloud/dbctl/constant"
)

var pingerLogger = ctlruntime.Log.WithName("pinger")

// IsDNSReady checks if dns and ip is ready, it can successfully resolve dns.
// Since the vast majority of container runtimes currently prohibit the NET_RAW capability,
// we can't rely on ICMP protocol to detect DNS resolution.
// Instead, we directly depend on TCP for port detection.
func IsDNSReady(dns string) (bool, error) {
// get the port where the Lorry HTTP service is listening
port := viper.GetString("port")
return IsTCPReady(dns, port)
}

func IsTCPReady(host, port string) (bool, error) {
address := net.JoinHostPort(host, port)
timeout := 2 * time.Second
Expand All @@ -54,40 +37,3 @@ func IsTCPReady(host, port string) (bool, error) {

return true, nil
}

func CheckDNSReadyWithRetry(dns string, times int) (bool, error) {
var ready bool
var err error
for i := 0; i < times; i++ {
ready, err = IsDNSReady(dns)
if err == nil && ready {
return true, nil
}
}
pingerLogger.Info("dns resolution is ready", "dns", dns)
return ready, err
}

// WaitForDNSReady checks if dns is ready
func WaitForDNSReady(dns string) {
pingerLogger.Info("Waiting for dns resolution to be ready")
isPodReady, err := IsDNSReady(dns)
for err != nil || !isPodReady {
if err != nil {
pingerLogger.Info("dns check failed", "error", err.Error())
}
time.Sleep(3 * time.Second)
isPodReady, err = IsDNSReady(dns)
}
pingerLogger.Info("dns resolution is ready", "dns", dns)
}

// WaitForPodReady checks if pod is ready
func WaitForPodReady(checkPodHeadless bool) {
domain := viper.GetString(constant.KBEnvPodFQDN)
WaitForDNSReady(domain)
if checkPodHeadless {
domain := viper.GetString(constant.KBEnvPodName)
WaitForDNSReady(domain)
}
}

0 comments on commit e1f7316

Please sign in to comment.