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

End2End - Pod Security Admission fixes #368

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions test/util/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ func All() error {
return fmt.Errorf("failed to restore node drain state %v", err)
}
}
if !namespaces.Exists(namespaces.Test, clients) {
return nil
}

err := namespaces.DeleteAndWait(clients, namespaces.Test, 5*time.Minute)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused by this change and the commit message: will it remove sriov resources from all namespaces or just from the specified one?

Copy link
Collaborator

Choose a reason for hiding this comment

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

this function delete the namespace and all the objects in that namespace. it's for a test namespace we don't run this function on the operator namespace.

There is also a clean sriov function to remove all the sriov related objects like sriovNetwork and sriovNetworkNodePolicy

if err != nil {
return fmt.Errorf("failed to delete sriov tests namespace %v", err)
Expand Down
19 changes: 16 additions & 3 deletions test/util/namespaces/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import (
// Test is the namespace to be use for testing
const Test = "sriov-conformance-testing"

var inhibitSecurityAdmissionLabels = map[string]string{
"pod-security.kubernetes.io/audit": "privileged",
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to align this with what we have for #371

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I see the labels have a delta.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@wizhaoredhat this is fine for the test-pods we have this in other places where we run tests like openshift-kni/cnf-features-deploy#1238

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, got it. Thanks!

"pod-security.kubernetes.io/enforce": "privileged",
"pod-security.kubernetes.io/warn": "privileged",
"security.openshift.io/scc.podSecurityLabelSync": "false",
}

// WaitForDeletion waits until the namespace will be removed from the cluster
func WaitForDeletion(cs *testclient.ClientSet, nsName string, timeout time.Duration) error {
return wait.PollImmediate(time.Second, timeout, func() (bool, error) {
Expand All @@ -36,7 +43,8 @@ func WaitForDeletion(cs *testclient.ClientSet, nsName string, timeout time.Durat
func Create(namespace string, cs *testclient.ClientSet) error {
_, err := cs.Namespaces().Create(context.Background(), &k8sv1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
Name: namespace,
Labels: inhibitSecurityAdmissionLabels,
}}, metav1.CreateOptions{})

if k8serrors.IsAlreadyExists(err) {
Expand All @@ -45,12 +53,17 @@ func Create(namespace string, cs *testclient.ClientSet) error {
return err
}

// DeleteAndWait deletes a namespace and waits until delete
// DeleteAndWait deletes a namespace and waits until it is deleted
func DeleteAndWait(cs *testclient.ClientSet, namespace string, timeout time.Duration) error {
err := cs.Namespaces().Delete(context.Background(), namespace, metav1.DeleteOptions{})
if k8serrors.IsNotFound(err) {
return nil
}

if err != nil {
return err
return fmt.Errorf("failed to delete namespace [%s]: %w", namespace, err)
}

return WaitForDeletion(cs, namespace, timeout)
}

Expand Down