-
Notifications
You must be signed in to change notification settings - Fork 242
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
refactor: [CI-CNI] Removing the predefined interfaces from validate #2047
Conversation
4ef0ff2
to
b73a55e
Compare
test/validate/client.go
Outdated
return nil | ||
} | ||
|
||
func (v *validator) validate(stateFileIps stateFileIpsFunc, cmd []string, checkType, namespace, labelSelector string) 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.
Can we rename it as validateIPs?
test/integration/load/load_test.go
Outdated
t.Log("State file validated successfully") | ||
} else if *osType == "linux" { | ||
t.Log("Validating the linux state file and restart network scenario") | ||
linuxClient := &validate.LinuxClient{} | ||
linuxClient = linuxClient.CreateClient(ctx, clientset, config, namespace, *cniType, *restartCase) | ||
|
||
//We are restarting the systmemd network and checking that the connectivity works after the restart. For more details: https://github.com/cilium/cilium/issues/18706 | ||
t.Log("Validating the restart network scenario") | ||
err = validator.ValidateRestartNetwork() | ||
if err != nil { | ||
t.Fatal(err) | ||
err = linuxClient.Validate() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
t.Log("State file validated successfully") |
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.
nit: Is 155 or 143 the design pattern?
If linux passes then it will report it once, but windows will report it twice. Would prefer to have the ubiquitous log message outside of the if/if else block.
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.
@jpayne3506 You shouldn't log at all when things are successful. The status of the test will tell you the same information. testing.(*T).Log
is really a bit of a misnomer, since it's really to accumulate line-stamped log messages in a buffer that will be displayed if testing.(*T).Fail
or testing.(*T).FailNow
are called. It's not really a "logger" in the traditional sense.
b73a55e
to
8d343a8
Compare
8d343a8
to
4120a80
Compare
test/integration/load/load_test.go
Outdated
if *osType == "windows" { | ||
t.Log("Validating the windows state file") | ||
windowsClient := &validate.WindowsClient{} | ||
windowsClient = windowsClient.CreateClient(ctx, clientset, config, namespace, *cniType, *restartCase) |
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.
no need to create an empty struct to then populate later, just use a constructing function. Change this
func (*WindowsClient) CreateClient(context.Context, ...)
to construct the WindowsClient itself:
func CreateWindowsClient(context.Context, ...) (*WindowsClient) {
return &WindowsClient{
clientset: clientset,
config: 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.
Cool, updated it with the rebase from your PR.
test/integration/load/load_test.go
Outdated
} else if *osType == "linux" { | ||
t.Log("Validating the linux state file and restart network scenario") | ||
linuxClient := &validate.LinuxClient{} | ||
linuxClient = linuxClient.CreateClient(ctx, clientset, config, namespace, *cniType, *restartCase) |
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.
same as above, this func should just build a new linuxClient, don't create an empty one then populate it
test/integration/load/load_test.go
Outdated
err = validator.ValidateRestartNetwork() | ||
if err != nil { | ||
t.Fatal(err) | ||
err = linuxClient.Validate() |
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.
nit:
if err := linuxClient.Validate(); err != nil {
t.Fatal(err)
}
combining the if statement with err initialization keeps the err
variable scoped only to the if block, so it's better to do this when possible to not leak scope.
test/validate/client.go
Outdated
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type Validator struct { | ||
type validator struct { | ||
ctx context.Context |
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.
as part of this refactor, we should remove context.Context from this struct. A context should (almost) never get stored in a struct. See this PR where I started refactoring these tests to see how to remove it: #2082
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.
Rebased with the #2082
4120a80
to
d185f2a
Compare
default: | ||
t.Fatalf("unknown os type %s", *osType) | ||
} | ||
|
||
err = validator.ValidateStateFile(ctx) |
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.
Since this is linux specific, I moved it linux validate file instead of load test.
test/validate/linux_validate.go
Outdated
@@ -64,6 +72,10 @@ type Address struct { | |||
Addr string `json:"ipv4"` | |||
} | |||
|
|||
type LinuxValidator struct { | |||
validator linuxValidator |
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 have a LinuxValidator and a WindowsValidator that just hold validators? I'm guessing you are trying to implement some os-specific code. I would suggest to just remove this concept of having OS-specific validators, so just get rid of LinuxValidator and WindowsValidator, and just have one (exported) Validator. Then the os-specific branching can happen in the funcs where it needs to.
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 that made sense. Removed os specifci validator. Branching the funcs if needed based on os.
9e24ce7
to
74cdd87
Compare
c0e672e
to
1ce7850
Compare
1ce7850
to
3853ebe
Compare
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.
lgtm
3853ebe
to
249a02a
Compare
/azp run Azure Container Networking PR |
Command 'Azure' is not supported by Azure Pipelines. Supported commands
See additional documentation. |
Azure Pipelines successfully started running 1 pipeline(s). |
249a02a
to
42f4e7a
Compare
Removing the predefined interfaces from validate package
Reason for Change:
Issue Fixed:
Requirements:
Notes: