-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash on startup #312
Fix crash on startup #312
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,18 @@ type TransformNetwork struct { | |
ProtocolsFile string `yaml:"protocolsFile,omitempty" json:"protocolsFile,omitempty" doc:"path to protocols file (optional, default: /etc/protocols)"` | ||
} | ||
|
||
func (tn *TransformNetwork) GetServiceFiles() (string, string) { | ||
p := tn.ProtocolsFile | ||
if p == "" { | ||
p = "/etc/protocols" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by the way, I used the previous default, as you can see here: https://github.com/netobserv/flowlogs-pipeline/pull/304/files#diff-803cd3d555b315c0ffdf0ac4905fd947085c6edf178137e7734e7af8a1218214L55 it was previously using these paths. But maybe this isn't super safe to write in /etc/protocols? maybe rather use /tmp/flp-protocols and /tmp/flp-services instead? @KalmanMeth @ronensc @mariomac ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. never mind, I thought it was a file that we would write into, I didn't know it was a standardized thingy |
||
} | ||
s := tn.ServicesFile | ||
if s == "" { | ||
s = "/etc/services" | ||
} | ||
return p, s | ||
} | ||
|
||
type TransformNetworkOperationEnum struct { | ||
AddRegExIf string `yaml:"add_regex_if" json:"add_regex_if" doc:"add output field if input field satisfies regex pattern from parameters field"` | ||
AddIf string `yaml:"add_if" json:"add_if" doc:"add output field if input field satisfies criteria from parameters field"` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package kubernetes | ||
|
||
import "github.com/stretchr/testify/mock" | ||
|
||
type KubeDataMock struct { | ||
mock.Mock | ||
kubeDataInterface | ||
} | ||
|
||
func (o *KubeDataMock) InitFromConfig(kubeConfigPath string) error { | ||
args := o.Called(kubeConfigPath) | ||
return args.Error(0) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,15 +189,16 @@ func NewTransformNetwork(params config.StageParam) (Transformer, error) { | |
|
||
var servicesDB *netdb.ServiceNames | ||
if needToInitNetworkServices { | ||
pFilename, sFilename := jsonNetworkTransform.GetServiceFiles() | ||
var err error | ||
protos, err := os.Open(jsonNetworkTransform.ProtocolsFile) | ||
protos, err := os.Open(pFilename) | ||
if err != nil { | ||
return nil, fmt.Errorf("opening %q: %w", jsonNetworkTransform.ProtocolsFile, err) | ||
return nil, fmt.Errorf("opening protocols file %q: %w", pFilename, err) | ||
} | ||
defer protos.Close() | ||
services, err := os.Open(jsonNetworkTransform.ServicesFile) | ||
services, err := os.Open(sFilename) | ||
if err != nil { | ||
return nil, fmt.Errorf("opening %q: %w", jsonNetworkTransform.ServicesFile, err) | ||
return nil, fmt.Errorf("opening services file %q: %w", sFilename, err) | ||
Comment on lines
+196
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for improving the error message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was able to find the error message in the e2e test of the PR that introduced the bug. But, despite that, the test passes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah seems like there's some improvement to bring to the e2e test too |
||
} | ||
defer services.Close() | ||
servicesDB, err = netdb.LoadServicesDB(protos, services) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is failing here with:
I wonder if using
os.Setenv
is enough...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be to remove the
add_kubernetes
rules from the test config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, Ronen's suggestion is much cleaner for a unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm rather mocking the kube client loading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(else, kube client initialization would fail without a real kube cluster available)