Skip to content

Commit

Permalink
Fix: temporarily ignore sanity checks when creating traceflow via UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangYW18 committed Aug 18, 2020
1 parent 487f19b commit 1576d8f
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions plugins/octant/cmd/antrea-octant-plugin/traceflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,53 +112,55 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error

switch actionName {
case addTfAction:
// TODO Octant v0.13.1 does not support alerts, sending alerts is supported with Octant no earlier than v0.16.0.
// TODO After upgrading Octant, send alerts when one of the sanity checks for users' input fail to pass.
srcNamespace, err := request.Payload.String(srcNamespaceCol)
if err != nil {
log.Printf("Failed to get srcNamespace as string: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get srcNamespace as string: %s", err)
}
if match := regExpMatch(namespaceStrPattern, srcNamespace); !match {
log.Printf("Failed to match namespace %s with K8s Namespace pattern %s", srcNamespace, namespaceStrPattern)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to match namespace %s with K8s Namespace pattern %s", srcNamespace, namespaceStrPattern)
}

srcPod, err := request.Payload.String(srcPodCol)
if err != nil {
log.Printf("Failed to get srcPod as string: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get srcPod as string: %s", err)
}
if match := regExpMatch(podStrPattern, srcPod); !match {
log.Printf("Failed to match pod name %s with K8s Pod pattern %s", srcPod, podStrPattern)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to match pod name %s with K8s Pod pattern %s", srcPod, podStrPattern)
}

// Judge the destination type and get destination according to the type.
dstType, err := request.Payload.StringSlice(dstTypeCol)
if err != nil || len(dstType) == 0 {
log.Printf("Failed to get dstType as string slice: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get dstType as string slice: %s", err)
}
log.Printf("dstType %+v", dstType)
dst, err := request.Payload.String(dstCol)
if err != nil {
log.Printf("Failed to get dst as string: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get dst as string: %s", err)
}
dstNamespace, err := request.Payload.OptionalString(dstNamespaceCol)
if err != nil {
log.Printf("Failed to get dstNamespace as string: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get dstNamespace as string: %s", err)
}
var destination opsv1alpha1.Destination
switch dstType[0] {
case opsv1alpha1.DstTypePod:
if match := regExpMatch(podStrPattern, dst); !match {
log.Printf("Failed to match pod name %s with K8s Pod pattern %s", dst, podStrPattern)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to match pod name %s with K8s Pod pattern %s", dst, podStrPattern)
}
if match := regExpMatch(namespaceStrPattern, dstNamespace); !match {
log.Printf("Failed to match namespace %s with K8s Namespace pattern %s", dstNamespace, namespaceStrPattern)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to match namespace %s with K8s Namespace pattern %s", dstNamespace, namespaceStrPattern)
}
destination = opsv1alpha1.Destination{
Namespace: dstNamespace,
Expand All @@ -167,20 +169,20 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error
case opsv1alpha1.DstTypeIPv4:
s := net.ParseIP(dst)
if s == nil {
log.Printf("Failed to get destination IP as a valid IPv4 IP: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get destination IP as a valid IPv4 IP: %s", err)
}
if s.To4() == nil {
log.Printf("Failed to get destination IP as a valid IPv4 IP: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get destination IP as a valid IPv4 IP: %s", err)
}
destination = opsv1alpha1.Destination{
IP: dst,
}
case opsv1alpha1.DstTypeService:
if match := regExpMatch(namespaceStrPattern, dstNamespace); !match {
log.Printf("Failed to match namespace %s with K8s Namespace pattern %s", dstNamespace, namespaceStrPattern)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to match namespace %s with K8s Namespace pattern %s", dstNamespace, namespaceStrPattern)
}
destination = opsv1alpha1.Destination{
Namespace: dstNamespace,
Expand All @@ -190,19 +192,19 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error

srcPort, err := request.Payload.Uint16(srcPortCol)
if err != nil {
log.Printf("Failed to get srcPort as int: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get srcPort as int: %s", err)
}
dstPort, err := request.Payload.Uint16(dstPortCol)
if err != nil {
log.Printf("Failed to get dstPort as int: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get dstPort as int: %s", err)
}

protocol, err := request.Payload.StringSlice(protocolCol)
if err != nil || len(protocol) == 0 {
log.Printf("Failed to get protocol as string slice: %s", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get protocol as string slice: %s", err)
}

// Judge whether the name of trace flow is duplicated.
Expand All @@ -213,7 +215,6 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error
if tfOld.Name == tfName {
log.Printf("Duplicate traceflow \"%s\": same source pod and destination pod in less than one second"+
": %+v. ", tfName, tfOld)
return nil
}

tf := &opsv1alpha1.Traceflow{
Expand Down Expand Up @@ -281,15 +282,14 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error
case showGraphAction:
name, err := request.Payload.String(traceNameCol)
if err != nil {
log.Printf("Failed to get name at string : %w", err)
return nil
log.Printf("Invalid user input, CRD creation or Traceflow request may fail: "+
"failed to get name at string : %s", err)
}
// Invoke GenGraph to show
ctx := context.Background()
tf, err := p.client.OpsV1alpha1().Traceflows().Get(ctx, name, v1.GetOptions{})
if err != nil {
log.Printf("Failed to get traceflow CRD \"%s\", err: %s ", name, err)
return nil
}
log.Printf("Get traceflow CRD \"%s\" successfully, Traceflow Results: %+v", name, tf)
p.lastTf = tf
Expand Down

0 comments on commit 1576d8f

Please sign in to comment.