Skip to content

Commit

Permalink
Add logic for namespace cleanup and Serial (#1087)
Browse files Browse the repository at this point in the history
* Add logic for namespace cleanup and Serial

* Update golangci-lint yaml to remove deprecation
  • Loading branch information
sebrandon1 authored Feb 24, 2025
1 parent de03725 commit cd64523
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ linters:
- rowserrcheck
- staticcheck
- stylecheck
- tenv
- usetesting
- thelper
- tparallel
- typecheck
Expand Down
5 changes: 2 additions & 3 deletions tests/accesscontrol/helper/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package helper

import (
"context"
"errors"
"testing"

Expand Down Expand Up @@ -124,7 +123,7 @@ func TestSetServiceAccountAutomountServiceAccountToken(t *testing.T) {

// Get the serviceaccount from the fake client and check if the automountServiceAccountToken is set to the test value
serviceAccount, err := client.CoreV1().
ServiceAccounts(parameters.TestAccessControlNameSpace).Get(context.TODO(), "my-service-account", metav1.GetOptions{})
ServiceAccounts(parameters.TestAccessControlNameSpace).Get(t.Context(), "my-service-account", metav1.GetOptions{})
assert.Nil(t, err)

if err == nil {
Expand Down Expand Up @@ -188,7 +187,7 @@ func TestDefineAndCreateServiceOnCluster(t *testing.T) {
assert.Nil(t, err)

// Get the service from the fake client and check if it exists
_, err = client.CoreV1().Services(parameters.TestAccessControlNameSpace).Get(context.TODO(), "service-name", metav1.GetOptions{})
_, err = client.CoreV1().Services(parameters.TestAccessControlNameSpace).Get(t.Context(), "service-name", metav1.GetOptions{})
assert.Nil(t, err)

globalhelper.UnsetTestK8sAPIClient()
Expand Down
3 changes: 1 addition & 2 deletions tests/globalhelper/clusterroles_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package globalhelper

import (
"context"
"testing"

egiClients "github.com/openshift-kni/eco-goinfra/pkg/clients"
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestDeleteClusterRole(t *testing.T) {
})
assert.Nil(t, deleteClusterRole(fakeClient, testCR.Name))

_, err := fakeClient.RbacV1Interface.ClusterRoles().Get(context.TODO(), testCR.Name, metav1.GetOptions{})
_, err := fakeClient.RbacV1Interface.ClusterRoles().Get(t.Context(), testCR.Name, metav1.GetOptions{})
assert.NotNil(t, err)
assert.True(t, k8serrors.IsNotFound(err))
}
Expand Down
5 changes: 2 additions & 3 deletions tests/globalhelper/namespaces_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package globalhelper

import (
"context"
"testing"
"time"

Expand Down Expand Up @@ -151,7 +150,7 @@ func TestCleanPVCs(t *testing.T) {

if testCase.namespaceExists {
// check if namespace has no pvcs left
pvcs, err := fakeClient.K8sClient.CoreV1().PersistentVolumeClaims(testCase.namespace).List(context.TODO(), metav1.ListOptions{})
pvcs, err := fakeClient.K8sClient.CoreV1().PersistentVolumeClaims(testCase.namespace).List(t.Context(), metav1.ListOptions{})
assert.NoError(t, err)
assert.Equal(t, 0, len(pvcs.Items))
}
Expand Down Expand Up @@ -201,7 +200,7 @@ func TestCleanPodDisruptionBudget(t *testing.T) {
if testCase.namespaceExists {
// check if namespace has no pod disruption budgets left
pdbs, err := fakeClient.K8sClient.PolicyV1beta1().
PodDisruptionBudgets(testCase.namespace).List(context.TODO(), metav1.ListOptions{})
PodDisruptionBudgets(testCase.namespace).List(t.Context(), metav1.ListOptions{})
assert.NoError(t, err)
assert.Equal(t, 0, len(pdbs.Items))
}
Expand Down
5 changes: 2 additions & 3 deletions tests/globalhelper/nodes_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package globalhelper

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -41,7 +40,7 @@ func TestAddControlPlaneTaint(t *testing.T) {
assert.Nil(t, err)

// Check that the taint was added
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := client.CoreV1().Nodes().List(t.Context(), metav1.ListOptions{})
assert.Nil(t, err)

for _, node := range nodes.Items {
Expand Down Expand Up @@ -78,7 +77,7 @@ func TestRemoveControlPlaneTaint(t *testing.T) {
assert.Nil(t, err)

// Check that the taint was added
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := client.CoreV1().Nodes().List(t.Context(), metav1.ListOptions{})
assert.Nil(t, err)

for _, node := range nodes.Items {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/redhat-best-practices-for-k8s/certsuite-qe/tests/utils/pod"
)

var _ = Describe("Operator single-or-multi-namespaced-allowed-in-tenant-namespaces", func() {
var _ = Describe("Operator single-or-multi-namespaced-allowed-in-tenant-namespaces", Serial, func() {
var randomNamespace string
var randomReportDir string
var randomCertsuiteConfigDir string
Expand Down Expand Up @@ -277,10 +277,19 @@ func installClusterWideOperator() {
openshiftLoggingNamespace = "cluster-logging"
)

By("Preemptively delete the namespace if it already exists")
err := globalhelper.DeleteNamespaceAndWait(openshiftLoggingNamespace, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred(), "Error deleting namespace "+openshiftLoggingNamespace)

By("Create openshift-logging namespace")
err := globalhelper.CreateNamespace(openshiftLoggingNamespace)
err = globalhelper.CreateNamespace(openshiftLoggingNamespace)
Expect(err).ToNot(HaveOccurred())

DeferCleanup(func() {
err := globalhelper.DeleteNamespaceAndWait(openshiftLoggingNamespace, tsparams.Timeout)
Expect(err).ToNot(HaveOccurred(), "Error deleting namespace "+openshiftLoggingNamespace)
})

By("Create fake operator group for cluster-logging operator")
err = tshelper.DeployTestOperatorGroup(openshiftLoggingNamespace, true)
Expect(err).ToNot(HaveOccurred(), "Error deploying operator group")
Expand Down
13 changes: 6 additions & 7 deletions tests/utils/nodes/nodes_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nodes

import (
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -47,7 +46,7 @@ func TestEnsureAllNodesAreLabeled(t *testing.T) {
client := k8sfake.NewSimpleClientset(runtimeObjects...)

// Get all of the nodes from the fake client and test their labels
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := client.CoreV1().Nodes().List(t.Context(), metav1.ListOptions{})
assert.Nil(t, err)
assert.Equal(t, 1, len(nodes.Items))

Expand Down Expand Up @@ -99,7 +98,7 @@ func TestAddControlPlaneTaint(t *testing.T) {
assert.Nil(t, addControlPlaneTaint(client.CoreV1().Nodes(), testNode))

// Get all of the nodes from the fake client and test their labels
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := client.CoreV1().Nodes().List(t.Context(), metav1.ListOptions{})
assert.Nil(t, err)
assert.Equal(t, 1, len(nodes.Items))

Expand Down Expand Up @@ -138,7 +137,7 @@ func TestRemoveControlPlaneTaint(t *testing.T) {
assert.Nil(t, removeControlPlaneTaint(client.CoreV1().Nodes(), testNode))

// Get all of the nodes from the fake client and test their labels
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := client.CoreV1().Nodes().List(t.Context(), metav1.ListOptions{})
assert.Nil(t, err)
assert.Equal(t, 1, len(nodes.Items))

Expand Down Expand Up @@ -279,7 +278,7 @@ func TestUnCordon(t *testing.T) {
assert.Nil(t, UnCordon(client.CoreV1().Nodes(), testNode.Name))

// Get all of the nodes from the fake client and test their labels
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := client.CoreV1().Nodes().List(t.Context(), metav1.ListOptions{})
assert.Nil(t, err)
assert.Equal(t, 1, len(nodes.Items))

Expand All @@ -300,7 +299,7 @@ func TestEnableMasterScheduling(t *testing.T) {
assert.Nil(t, EnableMasterScheduling(client.CoreV1().Nodes(), true))

// Get all of the nodes from the fake client and test their labels
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := client.CoreV1().Nodes().List(t.Context(), metav1.ListOptions{})
assert.Nil(t, err)
assert.Equal(t, 1, len(nodes.Items))

Expand All @@ -309,7 +308,7 @@ func TestEnableMasterScheduling(t *testing.T) {

// Disable master scheduling
assert.Nil(t, EnableMasterScheduling(client.CoreV1().Nodes(), false))
nodes, err = client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err = client.CoreV1().Nodes().List(t.Context(), metav1.ListOptions{})
assert.Nil(t, err)
assert.Equal(t, 1, len(nodes.Items))
assert.NotZero(t, nodes.Items[0].Spec.Taints)
Expand Down

0 comments on commit cd64523

Please sign in to comment.