-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add public IPs validation task #2070
Conversation
f46491b
to
2502823
Compare
Blocked on docs |
pkg/network/public/public.go
Outdated
err = ensureTestNamespace(br) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create test namespace: %w", err) | ||
} | ||
|
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.
err = ensureTestNamespace(br) | |
if err != nil { | |
return nil, fmt.Errorf("failed to create test namespace: %w", err) | |
} | |
if err := ensureTestNamespace(br); err != nil { | |
return nil, errors.Wrap(err, "failed to create test namespace") | |
} | |
pkg/perf/pubip_task.go
Outdated
log.Err(err).Send() | ||
continue | ||
} | ||
err = macvlan.Install(mv, nil, ipNet, routes, netNS) |
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 don't believe you need to pass netNS because u are already inside the namespace. it's then better to pass nil
to avoid unpredeceted errors
pkg/perf/pubip_task.go
Outdated
} | ||
unusedIPs := make(map[string]bool) | ||
err = netNS.Do(func(nn ns.NetNS) error { | ||
mv, err := macvlan.GetByName(testMacvlan) |
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 is too much code in the Do closure, i prefer u create another function that has the logic then do netNS.Do(p.logic)
this way the indentation of the code won't also be too much
pkg/perf/pubip_task.go
Outdated
for { | ||
nodeID, err = registrar.NodeID(ctx) | ||
if err == nil { | ||
break | ||
} | ||
log.Err(err).Msg("failed to get node id") | ||
time.Sleep(10 * time.Second) | ||
} |
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.
There is a package backoff
that we use you should use here instead of this.
pkg/perf/pubip_task.go
Outdated
return string(body), nil | ||
} | ||
|
||
func deleteIPAndRoutes(publicIP substrate.PublicIP, routes []*netlink.Route, macvlan netlink.Link) error { |
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 really think you should just delee all Ips and routes blindly, so u start by listing the ips on this link and ALL routes inside the namespace and delete them.
This function should also be called before the test to make sure there are no left over ips on the device because of a crash
Also, I think the directory of the tasks should not be called |
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.
Please also create a sub pkg under perf to include all your files related to this task for organization purposes
cmds/modules/noded/main.go
Outdated
pubIPTask := perf.NewPublicIPValidationTask() | ||
perfMon.AddTask(pubIPTask) |
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.
Why do u need the intermediate variable pubIPTask
?
pubIPTask := perf.NewPublicIPValidationTask() | |
perfMon.AddTask(pubIPTask) | |
perfMon.AddTask(perf.NewPublicIPValidationTask()) |
pkg/network/public/public.go
Outdated
@@ -26,6 +26,8 @@ import ( | |||
const ( | |||
toZosVeth = "tozos" // veth pair from br-pub to zos | |||
publicNsMACDerivationSuffix = "-public" | |||
testMacvlan = "pubtestmacvlan" |
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.
weird name, this can just be pub
or something. it's inside a namespace anyway so no chances of name collision.
pkg/network/public/public.go
Outdated
@@ -349,6 +355,24 @@ func EnsurePublicSetup(nodeID pkg.Identifier, inf *pkg.PublicConfig) (*netlink.B | |||
return br, netlink.LinkSetUp(br) | |||
} | |||
|
|||
func ensureTestNamespace(publicBrdige *netlink.Bridge) error { | |||
netNS, err := namespace.GetByName(testNamespace) | |||
if err != nil { |
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.
if you check GetByName
implementation you will see that it returns os.ErrNotExist if the namespace does not exist. So that's the only valid case you should try to create the namespace, then any other error type should be returned
netNS, err := GetByName(name)
if os.IsNotExist(err) {
err = Create(name)
}
if err != nil {
return err
}
pkg/perf/pubip_task.go
Outdated
return "", err | ||
} | ||
defer req.Body.Close() | ||
|
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.
You need to check the returned status from the req in case it's not 200
pkg/perf/publicip/publicip_task.go
Outdated
realIP, err := getRealPublicIP() | ||
if err != nil { | ||
p.farmIPsReport[publicIP.IP] = IPReport{ | ||
State: SkippedState, | ||
Reason: FetchRealIPFailed, | ||
} | ||
log.Err(err).Msg("failed to get node real IP") | ||
continue | ||
} |
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 is not always correct, if you failed to get the real ip this can duo to different reasons. and they all need to be handled differently:
- http.Get fail, this can be duo to name look failure, or failed to establish connection this is hugely mean that the IP is invalid (is not routable to the internet)
- http.Get succeeded but the response is not with success status (!= 200) this means that u have internet but the check service is donw, in that case we are not sure about the IP, we can mark it as skipped, for now.
- http.Get succeed but the the returned value does not match the actual IP we are testing means those IPs are natted, so they are also invalid.
the best way to do this is that getRealPublicIP need to return (wrapped) errors with more details on what happened exactly, and then based on that choose the proper state
pkg/network/public/public.go
Outdated
} | ||
if err != nil { |
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 is probably what u want. since u already check the error of the create
} | |
if err != nil { | |
} else if err != nil { |
Description
Add public IPs validation task while ensuring only runs on one node from the farm.
Steps
Issues
#2069