Skip to content
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

Merged
merged 1 commit into from
Aug 1, 2023

Conversation

vipul-21
Copy link
Contributor

@vipul-21 vipul-21 commented Jul 7, 2023

Removing the predefined interfaces from validate package

Reason for Change:

Issue Fixed:

Requirements:

Notes:

@vipul-21 vipul-21 changed the title refactor: [CI-CNI] Removing the predefined interfaces from validate p… refactor: [CI-CNI] Removing the predefined interfaces from validate Jul 7, 2023
@vipul-21 vipul-21 added cni Related to CNI. ci Infra or tooling. labels Jul 7, 2023
@vipul-21 vipul-21 requested a review from rbtr July 7, 2023 18:18
@vipul-21 vipul-21 force-pushed the singhvipul/validate branch from 4ef0ff2 to b73a55e Compare July 7, 2023 18:38
@vipul-21 vipul-21 marked this pull request as ready for review July 7, 2023 19:03
@vipul-21 vipul-21 requested a review from a team as a code owner July 7, 2023 19:03
@vipul-21 vipul-21 requested review from jpayne3506 and paulyufan2 July 7, 2023 19:04
@vipul-21 vipul-21 enabled auto-merge (squash) July 7, 2023 19:04
@vipul-21 vipul-21 mentioned this pull request Jul 11, 2023
4 tasks
return nil
}

func (v *validator) validate(stateFileIps stateFileIpsFunc, cmd []string, checkType, namespace, labelSelector string) error {
Copy link
Contributor

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?

Comment on lines 143 to 155
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")
Copy link
Contributor

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.

Copy link
Member

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.

@vipul-21 vipul-21 force-pushed the singhvipul/validate branch from b73a55e to 8d343a8 Compare July 27, 2023 01:17
@vipul-21 vipul-21 force-pushed the singhvipul/validate branch from 8d343a8 to 4120a80 Compare July 27, 2023 15:06
if *osType == "windows" {
t.Log("Validating the windows state file")
windowsClient := &validate.WindowsClient{}
windowsClient = windowsClient.CreateClient(ctx, clientset, config, namespace, *cniType, *restartCase)
Copy link
Contributor

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,
        ...
    }
}

Copy link
Contributor Author

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.

} 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)
Copy link
Contributor

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

err = validator.ValidateRestartNetwork()
if err != nil {
t.Fatal(err)
err = linuxClient.Validate()
Copy link
Contributor

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.

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

type Validator struct {
type validator struct {
ctx context.Context
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased with the #2082

@vipul-21 vipul-21 disabled auto-merge July 27, 2023 19:43
@vipul-21 vipul-21 force-pushed the singhvipul/validate branch from 4120a80 to d185f2a Compare July 27, 2023 21:11
@vipul-21 vipul-21 requested a review from thatmattlong July 27, 2023 21:14
default:
t.Fatalf("unknown os type %s", *osType)
}

err = validator.ValidateStateFile(ctx)
Copy link
Contributor Author

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.

@@ -64,6 +72,10 @@ type Address struct {
Addr string `json:"ipv4"`
}

type LinuxValidator struct {
validator linuxValidator
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@vipul-21 vipul-21 force-pushed the singhvipul/validate branch 3 times, most recently from 9e24ce7 to 74cdd87 Compare July 27, 2023 23:40
@vipul-21 vipul-21 force-pushed the singhvipul/validate branch 2 times, most recently from c0e672e to 1ce7850 Compare July 28, 2023 18:03
@vipul-21 vipul-21 enabled auto-merge (squash) July 28, 2023 18:03
@paulyufan2 paulyufan2 force-pushed the singhvipul/validate branch from 1ce7850 to 3853ebe Compare August 1, 2023 15:06
paulyufan2
paulyufan2 previously approved these changes Aug 1, 2023
Copy link
Contributor

@paulyufan2 paulyufan2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@vipul-21 vipul-21 force-pushed the singhvipul/validate branch from 3853ebe to 249a02a Compare August 1, 2023 16:11
@vipul-21
Copy link
Contributor Author

vipul-21 commented Aug 1, 2023

/azp run Azure Container Networking PR

@azure-pipelines
Copy link

Command 'Azure' is not supported by Azure Pipelines.

Supported commands
  • help:
    • Get descriptions, examples and documentation about supported commands
    • Example: help "command_name"
  • list:
    • List all pipelines for this repository using a comment.
    • Example: "list"
  • run:
    • Run all pipelines or specific pipelines for this repository using a comment. Use this command by itself to trigger all related pipelines, or specify specific pipelines to run.
    • Example: "run" or "run pipeline_name, pipeline_name, pipeline_name"
  • where:
    • Report back the Azure DevOps orgs that are related to this repository and org
    • Example: "where"

See additional documentation.

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vipul-21 vipul-21 force-pushed the singhvipul/validate branch from 249a02a to 42f4e7a Compare August 1, 2023 18:13
@vipul-21 vipul-21 merged commit 0e4fbdd into master Aug 1, 2023
@vipul-21 vipul-21 deleted the singhvipul/validate branch August 1, 2023 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Infra or tooling. cni Related to CNI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants