Skip to content

Ginkgo: Added PolicyGeneration on Nightly tests#2258

Merged
tgraf merged 7 commits intocilium:masterfrom
eloycoto:policyGen
Dec 18, 2017
Merged

Ginkgo: Added PolicyGeneration on Nightly tests#2258
tgraf merged 7 commits intocilium:masterfrom
eloycoto:policyGen

Conversation

@eloycoto
Copy link
Copy Markdown
Member

@eloycoto eloycoto commented Dec 5, 2017

This issue covers a few test cases for issue #2029, not all yet, but I'll provide more test cases this week.

Summary:

  • Added a new policy generation tool under helpers/policygen folder.
  • Added exitCode on CMDRes
  • Added Kubectl.GetServiceHostPort method.
  • Added NightlyK8sPolicies test

Signed-off-by: Eloy Coto eloy.coto@gmail.com

@eloycoto eloycoto added area/CI Continuous Integration testing issue or flake kind/enhancement This would improve or streamline existing functionality. pending-review labels Dec 5, 2017
@eloycoto eloycoto requested review from a team as code owners December 5, 2017 09:52
Comment thread test/k8sT/PoliciesNightly.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should not use dot imports

Comment thread test/k8sT/PoliciesNightly.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should not use dot imports

Comment thread test/helpers/policygen/const.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

exported const HTTP should have comment (or a comment on this block) or be unexported

Comment thread test/helpers/policygen/const.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

exported var ConnTests should have comment or be unexported

@tgraf tgraf mentioned this pull request Dec 5, 2017
43 tasks
Comment thread Jenkinstest Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this file a leftover?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this file is added intentionally, it should be added to CODEOWNERS file, as this is the only change in this PR that is pulling in the requirement for Janitor's review.

If this file is here accidentally we may need to add it to .gitignore to avoid it popping up later.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry, I was testing this in my local Jenkins and I did not remove it. My fault!

Comment thread test/helpers/kubectl.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we ignoring the error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this case, we only need if the exit was success or not. The error message is not essential.(A lot of them are supposed to fail)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still, logging the errors in debug mode may be useful.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The main problem to log things that didn't work cause a lot of noise, and opens tasks like #2221

Have a lot of logs that says fail when it is supposed to fail creates a lot of confusion.

Comment thread test/helpers/kubectl.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this case, we only need if the exit was success or not. The error message is not essential.(A lot of them are supposed to fail)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still, logging the errors in debug mode may be useful.

Comment thread test/helpers/policygen/actions.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Magic numbers? Can you add a comment with the meaning of each number?

Comment thread test/helpers/policygen/policygen.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure why this is commented, but it would be good to either uncomment&fix, or open an issue and add a line above the comment that links to the GH issue so we can know why this commented code exists, and find out more.

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

exported method GetConnectivyTest returns unexported type []policygen.connTestResultType, which can be annoying to use

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

exported method GetConnectivyTest returns unexported type []policygen.connTestResultType, which can be annoying to use

Copy link
Copy Markdown
Member

@nebril nebril left a comment

Choose a reason for hiding this comment

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

Most of my comments are stylistic or nitpicks, but there are some bigger ones. Please ping me for any clarifications.

Comment thread test/helpers/kubectl.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still, logging the errors in debug mode may be useful.

Comment thread test/helpers/kubectl.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still, logging the errors in debug mode may be useful.

Comment thread test/helpers/kubectl.go
if err != nil {
return "", 0, err
}
return data.Spec.ClusterIP, int(data.Spec.Ports[0].Port), nil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will panic if data.Spec.Ports is empty. Please add a check for it and return an error accordingly.

Comment thread test/helpers/node.go Outdated
// the command in the provided buffers. Returns false if the command failed
// during its execution.
func (s *SSHMeta) Execute(cmd string, stdout io.Writer, stderr io.Writer) bool {
func (s *SSHMeta) Execute(cmd string, stdout io.Writer, stderr io.Writer) (bool, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that at this point returning bool is redundant. Can you change it so only error is returned?

Comment thread test/helpers/node.go Outdated
func (s *SSHMeta) ExecWithSudo(cmd string, stdout io.Writer, stderr io.Writer) bool {
command := fmt.Sprintf("sudo %s", cmd)
return s.Execute(command, stdout, stderr)
result, _ := s.Execute(command, stdout, stderr)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Returning only error in all Exec* methods would make sure that we don't ignore any errors.

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/connectivy/connectivity

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/connectivy/connectivity

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please change name of the variable to expectedTestResult or sth like that.

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get why do we need these two for loops. As I understand, DetermineStatus returns what result is expected from give testType? What does it matter which rules are matched first?

Copy link
Copy Markdown
Member Author

@eloycoto eloycoto Dec 6, 2017

Choose a reason for hiding this comment

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

Easy, this is an example rule:

IngressRule on pod dest:
-- allow PORT 8080 --> ResultTimeout

EgressRule on src pod:
-- only access to /private/ url to port 80:

Testcase:

So, we need to check the egress before the ingress part to determine the status of the expected result

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/matchs/match

Comment thread test/helpers/kubectl.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The error should be propagated; change log message on line 75 to be kub.logger.WithError(err).Errorf(...

Comment thread test/helpers/node.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you change this function to return an error similar to Execute on line 81 above? Would make the functions more uniform in their implementation.

Comment thread test/helpers/policygen/actions.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

comamnd --> command.

Comment thread test/helpers/policygen/actions.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

log message is a bit verbose. what about "HTTPAction returned unexpected exit code %d" ?

Comment thread test/helpers/policygen/actions.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Create a GH issue and ref it here with GH-XXXX so that we know this is tracked.

Comment thread test/helpers/policygen/actions.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will the result always be a result timeout if the result was not successful?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fmt.Errorf("%s not implemented yet", t.Kind)

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NetworkPolicyCreate --> CreateCiliumNetworkPolicy

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and --> an

Comment thread test/helpers/policygen/models.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use consistency in comments esp. when referring to types. Change resutltType and resulttype --> ResultType

Comment thread test/helpers/policygen/policygen.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

package comment should be of the form "Package policygen ..."

Comment thread test/helpers/policygen/const.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

exported var ConnTests should have comment or be unexported

Comment thread test/helpers/policygen/const.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

package comment should be of the form "Package policygen ..."

Comment thread test/helpers/policygen/actions.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

package comment should be of the form "Package policygen ..."

Comment thread test/helpers/kubectl.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

exported const KubectlCmd should have comment (or a comment on this block) or be unexported

@eloycoto eloycoto force-pushed the policyGen branch 2 times, most recently from 2a7858a to 84a782b Compare December 13, 2017 16:35
@eloycoto
Copy link
Copy Markdown
Member Author

@ianvernon @nebril this PR should be ok, all the comments are now fixed.

Regards

Copy link
Copy Markdown
Member

@ianvernon ianvernon left a comment

Choose a reason for hiding this comment

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

Comments are fixed well-enough that I think this can be merged

@eloycoto
Copy link
Copy Markdown
Member Author

@nebril any update on this please?

@eloycoto
Copy link
Copy Markdown
Member Author

test this please

@eloycoto eloycoto force-pushed the policyGen branch 2 times, most recently from 8ff10ec to c765137 Compare December 14, 2017 11:39
@eloycoto eloycoto added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Dec 15, 2017
@ianvernon
Copy link
Copy Markdown
Member

@eloycoto please rebase and fix merge conflicts.

@eloycoto eloycoto force-pushed the policyGen branch 2 times, most recently from e85f152 to 1cc2848 Compare December 18, 2017 10:23
- Added a new policy generation tool under helpers/policygen folder.
- Added exitCode on CMDRes
- Added Kubectl.GetServiceHostPort method.
- Added NightlyK8sPolicies test

Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
Fix an issue when l3 was ResultTimeout in ingress and Egress has a deny
policy. Egress rules are the first match, so it should check first the
egress part instead ingress

Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
Fix L7 isssues on egress+ingress cases
Return only the error instead of sucess, err

Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/CI Continuous Integration testing issue or flake kind/enhancement This would improve or streamline existing functionality. ready-to-merge This PR has passed all tests and received consensus from code owners to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants