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

test: Do not require netpols in 'waitNextPolicyRevisions()' #17769

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 14 additions & 34 deletions test/helpers/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2917,44 +2917,24 @@ func (kub *Kubectl) getPodRevisions() (map[string]int, error) {
return revisions, nil
}

func (kub *Kubectl) waitNextPolicyRevisions(podRevisions map[string]int, mustHavePolicy bool, timeout time.Duration) error {
npFilter := fmt.Sprintf(
`{range .items[*]}{"%s="}{.metadata.name}{" %s="}{.metadata.namespace}{"\n"}{end}`,
KubectlPolicyNameLabel, KubectlPolicyNameSpaceLabel)

knpBody := func() bool {
knp := kub.ExecShort(fmt.Sprintf("%s get --all-namespaces netpol -o jsonpath='%s'",
KubectlCmd, npFilter))
result := knp.ByLines()
if len(result) == 0 {
return true
}

for _, item := range result {
for ciliumPod, revision := range podRevisions {
if mustHavePolicy {
tklauser marked this conversation as resolved.
Show resolved Hide resolved
if !kub.CiliumIsPolicyLoaded(ciliumPod, item) {
kub.Logger().Infof("Policy '%s' is not ready on Cilium pod '%s'", item, ciliumPod)
return false
}
}

ctx, cancel := context.WithTimeout(context.Background(), ShortCommandTimeout)
defer cancel()
desiredRevision := revision + 1
res := kub.CiliumExecContext(ctx, ciliumPod, fmt.Sprintf("cilium policy wait %d --max-wait-time %d", desiredRevision, int(ShortCommandTimeout.Seconds())))
if res.GetExitCode() != 0 {
kub.Logger().Infof("Failed to wait for policy revision %d on pod %s", desiredRevision, ciliumPod)
return false
}
func (kub *Kubectl) waitNextPolicyRevisions(podRevisions map[string]int, timeout time.Duration) error {
body := func() bool {
for ciliumPod, revision := range podRevisions {
ctx, cancel := context.WithTimeout(context.Background(), ShortCommandTimeout)
defer cancel()
desiredRevision := revision + 1
res := kub.CiliumExecContext(ctx, ciliumPod, fmt.Sprintf("cilium policy wait %d --max-wait-time %d", desiredRevision, int(ShortCommandTimeout.Seconds())))
if res.GetExitCode() != 0 {
kub.Logger().Infof("Failed to wait for policy revision %d on pod %s", desiredRevision, ciliumPod)
return false
}
}
return true
}

err := WithTimeout(
knpBody,
"Timed out while waiting for CNP to be applied on all PODs",
body,
"Timed out while waiting for policy revisions to be increased on all Cilium PODs",
&TimeoutConfig{Timeout: timeout})
return err
}
Expand Down Expand Up @@ -3036,7 +3016,7 @@ func (kub *Kubectl) CiliumPolicyAction(namespace, filepath string, action Resour
return "", nil
}

return "", kub.waitNextPolicyRevisions(podRevisions, action != KubectlDelete, timeout)
return "", kub.waitNextPolicyRevisions(podRevisions, timeout)
}

// CiliumClusterwidePolicyAction applies a clusterwide policy action as described in action argument. It
Expand Down Expand Up @@ -3100,7 +3080,7 @@ func (kub *Kubectl) CiliumClusterwidePolicyAction(filepath string, action Resour
return "", nil
}

return "", kub.waitNextPolicyRevisions(podRevisions, action != KubectlDelete, timeout)
return "", kub.waitNextPolicyRevisions(podRevisions, timeout)
}

// CiliumReport report the cilium pod to the log and appends the logs for the
Expand Down