Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
Signed-off-by: Hang Yan <[email protected]>
  • Loading branch information
hangyan committed Apr 10, 2024
1 parent 9ab86ce commit 2709cd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
1 change: 1 addition & 0 deletions pkg/agent/controller/packetsampling/packetin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/google/gopacket/pcapgo"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/ssh"
"golang.org/x/time/rate"
v1 "k8s.io/api/core/v1"
Expand Down
33 changes: 10 additions & 23 deletions pkg/agent/controller/packetsampling/packetsampling_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,18 @@ func (c *Controller) startPacketSampling(ps *crdv1alpha1.PacketSampling, psState

c.runningPacketSamplingsMutex.Lock()
psState.maxNumCapturedPackets = ps.Spec.FirstNSamplingConfig.Number
var file afero.File
var file afero.File
filePath := uidToPath(string(ps.UID))
if _, err := os.Stat(filePath); err == nil {
return fmt.Errorf("packet file already exists. this may be due to an unexpected termination")
} else if os.IsNotExist(err) {
file, err = defaultFS.Create(filePath)
if err != nil {
return fmt.Errorf("failed to create pcapng file: %w", err)
}
} else {
return fmt.Errorf("couldn't check if the file exists: %w", err)
}
return fmt.Errorf("packet file already exists. this may be due to an unexpected termination")
} else if os.IsNotExist(err) {
file, err = defaultFS.Create(filePath)
if err != nil {
return fmt.Errorf("failed to create pcapng file: %w", err)
}
} else {
return fmt.Errorf("couldn't check if the file exists: %w", err)
}
writer, err := pcapgo.NewNgWriter(file, layers.LinkTypeEthernet)
if err != nil {
return fmt.Errorf("couldn't init pcap writer: %w", err)
Expand All @@ -383,19 +383,6 @@ func (c *Controller) startPacketSampling(ps *crdv1alpha1.PacketSampling, psState
return err
}

func fileExists(path string) (bool, error) {
_, err := defaultFS.Stat(path)
if err == nil {
return true, nil
} else {
if os.IsNotExist(err) {
return false, nil
} else {
return false, err
}
}
}

// genEndpointMatchPackets generates match packets (with destination Endpoint's IP/port info) besides the normal match packet.
// these match packets will help the pipeline to capture the pod -> svc traffic.
// TODO: 1. support name based port name 2. dual-stack support
Expand Down

0 comments on commit 2709cd1

Please sign in to comment.