Skip to content

Commit

Permalink
Fix traceflow spec validation logic.
Browse files Browse the repository at this point in the history
Currently, when some traceflow spec error happens, the status of such
traceflows will be "Running", not "Failed". This is because some validation
logic is located at wrong places. I fixed this problem by moving them to the
right place.

Signed-off-by: shi0rik0 <anguuan@outlook.com>
  • Loading branch information
shi0rik0 committed Jul 10, 2023
1 parent 839df8c commit 5bcf7cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
21 changes: 11 additions & 10 deletions pkg/agent/controller/traceflow/traceflow_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,6 @@ func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error {
return err
}

liveTraffic := tf.Spec.LiveTraffic
if tf.Spec.Source.Pod == "" && tf.Spec.Destination.Pod == "" {
klog.Errorf("Traceflow %s has neither source nor destination Pod specified", tf.Name)
return nil
}
if tf.Spec.Source.Pod == "" && !liveTraffic {
klog.Errorf("Traceflow %s does not have source Pod specified", tf.Name)
return nil
}

receiverOnly := false
var pod, ns string
if tf.Spec.Source.Pod != "" {
Expand All @@ -327,6 +317,8 @@ func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error {
podInterfaces := c.interfaceStore.GetContainerInterfacesByPod(pod, ns)
isSender := len(podInterfaces) > 0 && !receiverOnly

liveTraffic := tf.Spec.LiveTraffic

var packet, matchPacket *binding.Packet
var ofPort uint32
if len(podInterfaces) > 0 {
Expand Down Expand Up @@ -397,6 +389,15 @@ func (c *Controller) validateTraceflow(tf *crdv1alpha1.Traceflow) error {
return errors.New("using ClusterIP destination requires AntreaProxy feature enabled")
}
}

if tf.Spec.Source.Pod == "" && tf.Spec.Destination.Pod == "" {
return fmt.Errorf("Traceflow %s has neither source nor destination Pod specified", tf.Name)
}

if tf.Spec.Source.Pod == "" && !tf.Spec.LiveTraffic {
return fmt.Errorf("Traceflow %s does not have source Pod specified", tf.Name)
}

return nil
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/agent/controller/traceflow/traceflow_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ func TestStartTraceflow(t *testing.T) {
tf: &crdv1alpha1.Traceflow{
ObjectMeta: metav1.ObjectMeta{Name: "tf3", UID: "uid3"},
},
expectedErrLog: "Traceflow tf3 has neither source nor destination Pod specified",
nodeConfig: &config.NodeConfig{},
expectedErr: "Traceflow tf3 has neither source nor destination Pod specified",
},
{
name: "empty source Pod",
Expand All @@ -638,7 +639,8 @@ func TestStartTraceflow(t *testing.T) {
},
},
},
expectedErrLog: "Traceflow tf4 does not have source Pod specified",
nodeConfig: &config.NodeConfig{},
expectedErr: "Traceflow tf4 does not have source Pod specified",
},
{
name: "invalid destination IPv4",
Expand Down

0 comments on commit 5bcf7cf

Please sign in to comment.