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 8, 2023
1 parent 839df8c commit 5692299
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 2 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
9 changes: 9 additions & 0 deletions pkg/controller/traceflow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,14 @@ func (c *Controller) validateTraceflow(tf *crdv1alpha1.Traceflow) error {
return fmt.Errorf("using hostNetwork Pod as source in non-live-traffic Traceflow is not supported")
}
}

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
}

0 comments on commit 5692299

Please sign in to comment.