diff --git a/api/network/v1beta1/types.go b/api/network/v1beta1/types.go index 1efac20..b320831 100644 --- a/api/network/v1beta1/types.go +++ b/api/network/v1beta1/types.go @@ -74,7 +74,15 @@ type UDPSocketAction struct { Enable bool `json:"enable" protobuf:"bytes,1,opt,name=enable"` // UDP test data // +optional - Data string `json:"data" protobuf:"bytes,2,opt,name=data"` + Data []uint8 `json:"data,omitempty" protobuf:"varint,2,rep,name=data"` +} + +func Int8ArrToByteArr(data []uint8) []byte { + r := make([]byte, len(data)) + for i, d := range data { + r[i] = d + } + return r } // HTTPGetAction describes an action based on HTTP Get requests. diff --git a/api/network/v1beta1/zz_generated.deepcopy.go b/api/network/v1beta1/zz_generated.deepcopy.go index e7cbef7..205c483 100644 --- a/api/network/v1beta1/zz_generated.deepcopy.go +++ b/api/network/v1beta1/zz_generated.deepcopy.go @@ -213,7 +213,7 @@ func (in *Handler) DeepCopyInto(out *Handler) { if in.UDPSocket != nil { in, out := &in.UDPSocket, &out.UDPSocket *out = new(UDPSocketAction) - **out = **in + (*in).DeepCopyInto(*out) } if in.GRPC != nil { in, out := &in.GRPC, &out.GRPC @@ -269,6 +269,11 @@ func (in *TCPSocketAction) DeepCopy() *TCPSocketAction { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *UDPSocketAction) DeepCopyInto(out *UDPSocketAction) { *out = *in + if in.Data != nil { + in, out := &in.Data, &out.Data + *out = make([]byte, len(*in)) + copy(*out, *in) + } return } diff --git a/config/charts/endpoints-operator/crds/sealyun.com_clusterendpoints.yaml b/config/charts/endpoints-operator/crds/sealyun.com_clusterendpoints.yaml index e0a7190..0e983af 100644 --- a/config/charts/endpoints-operator/crds/sealyun.com_clusterendpoints.yaml +++ b/config/charts/endpoints-operator/crds/sealyun.com_clusterendpoints.yaml @@ -178,7 +178,9 @@ spec: properties: data: description: UDP test data - type: string + items: + type: integer + type: array enable: type: boolean required: diff --git a/config/crd/sealyun.com_clusterendpoints.yaml b/config/crd/sealyun.com_clusterendpoints.yaml index e0a7190..0e983af 100644 --- a/config/crd/sealyun.com_clusterendpoints.yaml +++ b/config/crd/sealyun.com_clusterendpoints.yaml @@ -178,7 +178,9 @@ spec: properties: data: description: UDP test data - type: string + items: + type: integer + type: array enable: type: boolean required: diff --git a/controllers/sync.go b/controllers/sync.go index a360b39..6942d01 100644 --- a/controllers/sync.go +++ b/controllers/sync.go @@ -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 { diff --git a/library/api/core/v1/types.go b/library/api/core/v1/types.go index b093107..f7a76f1 100644 --- a/library/api/core/v1/types.go +++ b/library/api/core/v1/types.go @@ -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 { diff --git a/library/probe/udp/udp.go b/library/probe/udp/udp.go index 6045da0..907b558 100644 --- a/library/probe/udp/udp.go +++ b/library/probe/udp/udp.go @@ -31,13 +31,13 @@ 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) } @@ -45,7 +45,7 @@ func (pr udpProber) Probe(host string, port int, testData string, timeout time.D // 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) @@ -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