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

feature(main): add udp string to []uint8 #75

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion api/network/v1beta1/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion api/network/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ spec:
properties:
data:
description: UDP test data
type: string
items:
type: integer
type: array
enable:
type: boolean
required:
Expand Down
4 changes: 3 additions & 1 deletion config/crd/sealyun.com_clusterendpoints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ spec:
properties:
data:
description: UDP test data
type: string
items:
type: integer
type: array
enable:
type: boolean
required:
Expand Down
2 changes: 1 addition & 1 deletion controllers/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func healthyCheck(host string, cep *v1beta1.ClusterEndpoint, retry int, metricsi
pro.UDPSocket = &libv1.UDPSocketAction{
Port: intstr.FromInt(int(port.TargetPort)),
Host: host,
Data: port.UDPSocket.Data,
Data: v1beta1.Int8ArrToByteArr(port.UDPSocket.Data),
}
}
if port.GRPC != nil && port.GRPC.Enable {
Expand Down
2 changes: 1 addition & 1 deletion library/api/core/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type UDPSocketAction struct {
// +optional
Host string `json:"host,omitempty" protobuf:"bytes,2,opt,name=host"`
// +optional
Data string `json:"data,omitempty" protobuf:"bytes,3,opt,name=host"`
Data []byte `json:"data,omitempty" protobuf:"bytes,3,rep,name=data"`
}

type GRPCAction struct {
Expand Down
8 changes: 4 additions & 4 deletions library/probe/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ func New() Prober {

// Prober is an interface that defines the Probe function for doing UDP readiness/liveness checks.
type Prober interface {
Probe(host string, port int, testData string, timeout time.Duration) (probe.Result, string, error)
Probe(host string, port int, testData []byte, timeout time.Duration) (probe.Result, string, error)
}

type udpProber struct{}

// Probe returns a ProbeRunner capable of running a UDP check.
func (pr udpProber) Probe(host string, port int, testData string, timeout time.Duration) (probe.Result, string, error) {
func (pr udpProber) Probe(host string, port int, testData []byte, timeout time.Duration) (probe.Result, string, error) {
return DoUDPProbe(net.JoinHostPort(host, strconv.Itoa(port)), testData, timeout)
}

// DoUDPProbe checks that a UDP socket to the address can be opened.
// If the socket can be opened, it returns Success
// If the socket fails to open, it returns Failure.
// This is exported because some other packages may want to do direct UDP probes.
func DoUDPProbe(addr string, testData string, timeout time.Duration) (probe.Result, string, error) {
func DoUDPProbe(addr string, testData []byte, timeout time.Duration) (probe.Result, string, error) {

serverAddr, err := net.ResolveUDPAddr("udp", addr)
klog.Infoln("Scan UDP Endpoint: ", addr)
Expand All @@ -61,7 +61,7 @@ func DoUDPProbe(addr string, testData string, timeout time.Duration) (probe.Resu

deadline := time.Now().Add(timeout * time.Second)
_ = conn.SetWriteDeadline(deadline)
buf := []byte(testData)
buf := testData
_, err = conn.Write(buf)
if err != nil {
return probe.Failure, err.Error(), nil
Expand Down