Skip to content

Commit

Permalink
Merge branch 'master' into ks20drptcrtype
Browse files Browse the repository at this point in the history
  • Loading branch information
fbm3307 authored Mar 6, 2024
2 parents edbe626 + 49dd75a commit ff5afbd
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 59 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set update schedule for GitHub Actions
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every day
interval: "daily"
10 changes: 5 additions & 5 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.20.x

Expand All @@ -31,7 +31,7 @@ jobs:
make test-with-coverage
- name: Upload code coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./build/_output/coverage/coverage.txt
Expand All @@ -44,7 +44,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.20.x

Expand All @@ -56,9 +56,9 @@ jobs:
make generate-assets
- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: v1.52.0
version: v1.56.2
skip-pkg-cache: true
skip-build-cache: true
args: --config=./.golangci.yml --verbose
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/operator-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ jobs:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles ('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish-operators-for-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# Is executed only for comment events - in that case the pull_request field is empty
- name: Send Github API Request to get PR data
id: request
uses: octokit/request-action@v2.0.0
uses: octokit/request-action@v2.1.9
if: ${{ github.event.pull_request == '' }}
with:
route: ${{ github.event.issue.pull_request.url }}
Expand All @@ -47,19 +47,19 @@ jobs:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles ('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

Expand Down
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ linters-settings:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: true
revive:
rules:
- name: dot-imports
disabled: true # we allow for dot-imports

20 changes: 10 additions & 10 deletions controllers/idler/idler_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestEnsureIdling(t *testing.T) {
HasConditions(memberoperatortest.Running())

assert.True(t, res.Requeue)
assert.Equal(t, int(res.RequeueAfter), 0) // pods running for too long should be killed immediately
assert.Equal(t, 0, int(res.RequeueAfter)) // pods running for too long should be killed immediately

t.Run("Second Reconcile. Delete long running pods.", func(t *testing.T) {
//when
Expand Down Expand Up @@ -314,12 +314,12 @@ func TestEnsureIdling(t *testing.T) {
res, err := reconciler.Reconcile(context.TODO(), req)
require.NoError(t, err)
assert.True(t, res.Requeue)
assert.Equal(t, int(res.RequeueAfter), 0)
assert.Equal(t, 0, int(res.RequeueAfter))

// second reconcile should delete pods and create notification
res, err = reconciler.Reconcile(context.TODO(), req)
//then
assert.NoError(t, err)
require.NoError(t, err)
memberoperatortest.AssertThatIdler(t, idler.Name, cl).
HasConditions(memberoperatortest.Running(), memberoperatortest.IdlerNotificationCreated())
//check the notification is actually created
Expand All @@ -337,7 +337,7 @@ func TestEnsureIdling(t *testing.T) {
// third reconcile should not create a notification
res, err = reconciler.Reconcile(context.TODO(), req)
//then
assert.NoError(t, err)
require.NoError(t, err)
memberoperatortest.AssertThatIdler(t, idler.Name, cl).
HasConditions(memberoperatortest.Running(), memberoperatortest.IdlerNotificationCreated())

Expand Down Expand Up @@ -519,7 +519,7 @@ func TestEnsureIdlingFailed(t *testing.T) {
res, err := reconciler.Reconcile(context.TODO(), req)

// then
assert.NoError(t, err) // 'NotFound' errors are ignored!
require.NoError(t, err) // 'NotFound' errors are ignored!
assert.Equal(t, reconcile.Result{
Requeue: true,
RequeueAfter: 60 * time.Second,
Expand Down Expand Up @@ -743,7 +743,7 @@ func TestAppNameTypeForControllers(t *testing.T) {

//then
require.NoError(t, err)
require.Equal(t, true, deletedByController)
require.True(t, deletedByController)
require.Equal(t, tc.expectedAppType, appType)
require.Equal(t, tc.expectedAppName, appName)
})
Expand Down Expand Up @@ -825,13 +825,13 @@ func TestNotificationAppNameTypeForPods(t *testing.T) {

// first reconcile to track pods
res, err := reconciler.Reconcile(context.TODO(), req)
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, res.Requeue)

// second reconcile should delete pods and create notification
res, err = reconciler.Reconcile(context.TODO(), req)
//then
assert.NoError(t, err)
require.NoError(t, err)

if tcs.expectedNotificationCreated {
memberoperatortest.AssertThatIdler(t, idler.Name, cl).
Expand Down Expand Up @@ -1054,7 +1054,7 @@ func TestGetUserEmailFromMUR(t *testing.T) {
emails, err := reconciler.getUserEmailsFromMURs(context.TODO(), hostCluster, idler)
//then
require.EqualError(t, err, "nstemplatesets.toolchain.dev.openshift.com \"alex\" not found")
require.Len(t, emails, 0)
assert.Empty(t, emails)
})

t.Run("unable to get MUR, no error but no email found", func(t *testing.T) {
Expand All @@ -1068,7 +1068,7 @@ func TestGetUserEmailFromMUR(t *testing.T) {
emails, err := reconciler.getUserEmailsFromMURs(context.TODO(), hostCluster, idler)
//then
require.Error(t, err)
require.Len(t, emails, 0)
assert.Empty(t, emails)
})
}

Expand Down
3 changes: 2 additions & 1 deletion controllers/memberoperatorconfig/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/codeready-toolchain/toolchain-common/pkg/test"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -41,7 +42,7 @@ func TestSecretToMemberOperatorConfigMapper(t *testing.T) {
req := MapSecretToMemberOperatorConfig()(pod)

// then
require.Len(t, req, 0)
assert.Empty(t, req)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ func TestHandleAutoscalerDeploy(t *testing.T) {
ctx := log.IntoContext(context.TODO(), controller.Log)

// when
cl.(*test.FakeClient).MockGet = func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
cl.(*test.FakeClient).MockGet = func(_ context.Context, _ client.ObjectKey, _ client.Object, _ ...client.GetOption) error {
return fmt.Errorf("client error")
}
err = controller.handleAutoscalerDeploy(ctx, actualConfig, test.MemberOperatorNs)

// then
require.NotNil(t, err)
require.Error(t, err)
require.Contains(t, err.Error(), "cannot deploy autoscaling buffer template: ")
})

Expand Down
3 changes: 1 addition & 2 deletions controllers/memberstatus/creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestCreateOrUpdateResources(t *testing.T) {
err = CreateOrUpdateResources(context.TODO(), cl, MemberOperatorNs, MemberStatusName)

// then
require.Error(t, err)
require.Equal(t, err.Error(), "unable to create resource of kind: , version: : creation failed")
require.EqualError(t, err, "unable to create resource of kind: , version: : creation failed")
})
}
14 changes: 7 additions & 7 deletions controllers/nstemplateset/cluster_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestClusterResourceKinds(t *testing.T) {

// then
require.NoError(t, err)
require.Len(t, existingResources, 0)
assert.Empty(t, existingResources)
})

t.Run("listExistingResourcesIfAvailable should return an error when listing resources of gvk "+clusterResourceKind.gvk.String(), func(t *testing.T) {
Expand All @@ -109,7 +109,7 @@ func TestClusterResourceKinds(t *testing.T) {

// then
require.Error(t, err)
require.Len(t, existingResources, 0)
assert.Empty(t, existingResources)
})

t.Run("listExistingResourcesIfAvailable should not return any resource when APIGroup is missing for gvk "+clusterResourceKind.gvk.String(), func(t *testing.T) {
Expand All @@ -122,7 +122,7 @@ func TestClusterResourceKinds(t *testing.T) {

// then
require.NoError(t, err)
require.Len(t, existingResources, 0)
assert.Empty(t, existingResources)
})

t.Run("listExistingResourcesIfAvailable should not return any resource when APIGroup is present but is missing the version "+clusterResourceKind.gvk.String(), func(t *testing.T) {
Expand All @@ -135,7 +135,7 @@ func TestClusterResourceKinds(t *testing.T) {

// then
require.NoError(t, err)
require.Empty(t, existingResources)
assert.Empty(t, existingResources)
})
}

Expand Down Expand Up @@ -815,7 +815,7 @@ func TestPromoteClusterResources(t *testing.T) {
assert.True(t, updated)
err = cl.List(context.TODO(), quotas, &client.ListOptions{})
require.NoError(t, err)
assert.Len(t, quotas.Items, 0)
assert.Empty(t, quotas.Items)
AssertThatCluster(t, cl).
HasResource(spacename+"-tekton-view", &rbacv1.ClusterRoleBinding{})

Expand All @@ -828,11 +828,11 @@ func TestPromoteClusterResources(t *testing.T) {
assert.True(t, updated)
err = cl.List(context.TODO(), quotas, &client.ListOptions{})
require.NoError(t, err)
assert.Len(t, quotas.Items, 0)
assert.Empty(t, quotas.Items)
roleBindings := &rbacv1.ClusterRoleBindingList{}
err = cl.List(context.TODO(), roleBindings, &client.ListOptions{})
require.NoError(t, err)
assert.Len(t, roleBindings.Items, 0)
assert.Empty(t, roleBindings.Items)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion controllers/nstemplateset/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestNextNamespaceToProvisionOrUpdate(t *testing.T) {
_, _, found, err := manager.nextNamespaceToProvisionOrUpdate(ctx, tierTemplates, userNamespaces)

// then
assert.Error(t, err, "mock List error")
require.Error(t, err, "mock List error")
require.True(t, found)
})

Expand Down
6 changes: 3 additions & 3 deletions controllers/nstemplateset/nstemplatetier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ parameters:
// then
require.NoError(t, err)
require.Len(t, obj, 1)
assert.Equal(t, obj[0].GetNamespace(), "my-member-operator-namespace")
assert.Equal(t, obj[0].GetName(), "johnsmith")
assert.Equal(t, "my-member-operator-namespace", obj[0].GetNamespace())
assert.Equal(t, "johnsmith", obj[0].GetName())
}

func TestGetTierTemplate(t *testing.T) {
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestGetTierTemplate(t *testing.T) {
retrievedTierTemplate, err := getTierTemplate(ctx, hostCluster, tierTemplate.Name)

// then
assert.NoError(t, err)
assert.NoError(t, err) // require must only be used in the goroutine running the test function (testifylint)
assertThatTierTemplateIsSameAs(t, tierTemplate, retrievedTierTemplate)
}(tierTemplate)
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/nstemplateset/space_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestEnsureSpaceRoles(t *testing.T) {
_, err := mgr.ensure(ctx, nsTmplSet)

// then
assert.EqualError(t, err, "failed to list namespaces for workspace 'oddity': mock error")
require.EqualError(t, err, "failed to list namespaces for workspace 'oddity': mock error")
// at this point, the NSTemplateSet is still in `updating` state
AssertThatNSTemplateSet(t, commontest.MemberOperatorNs, "oddity", memberClient).
HasConditions(UnableToProvision("mock error"))
Expand All @@ -242,7 +242,7 @@ func TestEnsureSpaceRoles(t *testing.T) {
_, err := mgr.ensure(ctx, nsTmplSet)

// then
assert.EqualError(t, err, "failed to retrieve space roles to apply: unable to retrieve the TierTemplate 'admin-unknown-abcde11' from 'Host' cluster: tiertemplates.toolchain.dev.openshift.com \"admin-unknown-abcde11\" not found")
require.EqualError(t, err, "failed to retrieve space roles to apply: unable to retrieve the TierTemplate 'admin-unknown-abcde11' from 'Host' cluster: tiertemplates.toolchain.dev.openshift.com \"admin-unknown-abcde11\" not found")
AssertThatNSTemplateSet(t, commontest.MemberOperatorNs, "oddity", memberClient).
HasConditions(UpdateFailed(`unable to retrieve the TierTemplate 'admin-unknown-abcde11' from 'Host' cluster: tiertemplates.toolchain.dev.openshift.com "admin-unknown-abcde11" not found`))
})
Expand Down
12 changes: 6 additions & 6 deletions pkg/autoscaler/autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func TestDeploy(t *testing.T) {
t.Run("when creation fails", func(t *testing.T) {
// given
fakeClient := test.NewFakeClient(t)
fakeClient.MockCreate = func(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
fakeClient.MockCreate = func(_ context.Context, _ client.Object, _ ...client.CreateOption) error {
return fmt.Errorf("some error")
}

// when
err := Deploy(context.TODO(), fakeClient, s, test.MemberOperatorNs, "7Gi", 3)

// then
assert.EqualError(t, err, "cannot deploy autoscaling buffer template: unable to create resource of kind: PriorityClass, version: v1: some error")
require.EqualError(t, err, "cannot deploy autoscaling buffer template: unable to create resource of kind: PriorityClass, version: v1: some error")
})
}

Expand Down Expand Up @@ -123,30 +123,30 @@ func TestDelete(t *testing.T) {
t.Run("when loading previously deployed objects fails", func(t *testing.T) {
// given
fakeClient := test.NewFakeClient(t)
fakeClient.MockGet = func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
fakeClient.MockGet = func(_ context.Context, _ client.ObjectKey, _ client.Object, _ ...client.GetOption) error {
return fmt.Errorf("some error")
}

// when
deleted, err := Delete(context.TODO(), fakeClient, s, test.MemberOperatorNs)

// then
assert.EqualError(t, err, "cannot get autoscaling buffer object: some error")
require.EqualError(t, err, "cannot get autoscaling buffer object: some error")
assert.False(t, deleted)
})

t.Run("when deleting previously deployed objects fails", func(t *testing.T) {
// given
fakeClient := test.NewFakeClient(t, namespace, prioClass, dm)
fakeClient.MockDelete = func(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error {
fakeClient.MockDelete = func(_ context.Context, _ client.Object, _ ...client.DeleteOption) error {
return fmt.Errorf("some error")
}

// when
deleted, err := Delete(context.TODO(), fakeClient, s, test.MemberOperatorNs)

// then
assert.EqualError(t, err, "cannot delete autoscaling buffer object: some error")
require.EqualError(t, err, "cannot delete autoscaling buffer object: some error")
assert.False(t, deleted)
})
}
Expand Down
Loading

0 comments on commit ff5afbd

Please sign in to comment.