From 2fb49c48f7d9a69f5aa993ddfe999d330ffca59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Sand=C4=B1kc=C4=B1?= Date: Sat, 17 Aug 2024 20:29:08 +0300 Subject: [PATCH] Upgrade dependencies and Go 1.23 --- .github/workflows/lint.yaml | 6 +++--- .github/workflows/release.yaml | 4 ++-- .github/workflows/test.yaml | 6 +++--- deploy/crds/cloud.namecheap.com_scheduledresources.yaml | 6 +----- devops.sh | 8 ++++---- go.mod | 2 +- .../NCCloud/mayfly/pkg/common/mock_Scheduler.go | 2 +- .../controller-runtime/pkg/cache/mock_Cache.go | 2 +- .../controller-runtime/pkg/client/mock_Client.go | 2 +- .../pkg/client/mock_SubResourceClient.go | 2 +- .../controller-runtime/pkg/manager/mock_Manager.go | 2 +- pkg/apis/v1alpha2/scheduled_resource_types.go | 6 +++--- pkg/controllers/expiration/controller.go | 5 ++++- pkg/controllers/expiration/controller_test.go | 2 +- pkg/controllers/scheduledresource/controller.go | 1 + pkg/controllers/scheduledresource/controller_test.go | 5 ++++- 16 files changed, 32 insertions(+), 29 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 52665ec..89adeb1 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -7,12 +7,12 @@ permissions: contents: read env: - GO_VERSION: "1.22" + GO_VERSION: "1.23" jobs: lint: name: Lint - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 @@ -21,4 +21,4 @@ jobs: - name: Download Dependencies run: go mod download - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 58dd214..c0b139f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -11,7 +11,7 @@ env: jobs: release: name: Release Image - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -32,7 +32,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: push: true platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3b55425..3b5e902 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,13 +9,13 @@ permissions: contents: write env: - GO_VERSION: "1.22" + GO_VERSION: "1.23" GOPRIVATE: "github:com/NCCloud/*" jobs: tests: name: Test - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Install Go uses: actions/setup-go@v5 @@ -31,7 +31,7 @@ jobs: run: | ./devops.sh prepare_envtest - name: Coverage Report - uses: gwatts/go-coverage-action@v1 + uses: gwatts/go-coverage-action@v2 id: coverage with: coverage-threshold: 80 diff --git a/deploy/crds/cloud.namecheap.com_scheduledresources.yaml b/deploy/crds/cloud.namecheap.com_scheduledresources.yaml index c284aec..b86743c 100644 --- a/deploy/crds/cloud.namecheap.com_scheduledresources.yaml +++ b/deploy/crds/cloud.namecheap.com_scheduledresources.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.15.0 + controller-gen.kubebuilder.io/version: v0.16.1 name: scheduledresources.cloud.namecheap.com spec: group: cloud.namecheap.com @@ -69,10 +69,6 @@ spec: type: string nextRun: type: string - required: - - condition - - lastRun - - nextRun type: object type: object served: true diff --git a/devops.sh b/devops.sh index 9824cd3..c761697 100755 --- a/devops.sh +++ b/devops.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -export CONTROLLER_GEN_VERSION="v0.15.0" -export GOLANGCI_LINT_VERSION="v1.59.1" -export MOCKERY_GEN_VERSION="v2.44.1" -export GOFUMPT_VERSION="v0.6.0" +export CONTROLLER_GEN_VERSION="v0.16.1" +export GOLANGCI_LINT_VERSION="v1.60.1" +export MOCKERY_GEN_VERSION="v2.44.2" +export GOFUMPT_VERSION="v0.7.0" export TESTENV_VERSION="1.25.x!" prerequisites() { diff --git a/go.mod b/go.mod index b8fa908..3791418 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/NCCloud/mayfly -go 1.22.0 +go 1.23.0 require ( github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de diff --git a/mocks/github.com/NCCloud/mayfly/pkg/common/mock_Scheduler.go b/mocks/github.com/NCCloud/mayfly/pkg/common/mock_Scheduler.go index 1d7e929..ec91df0 100644 --- a/mocks/github.com/NCCloud/mayfly/pkg/common/mock_Scheduler.go +++ b/mocks/github.com/NCCloud/mayfly/pkg/common/mock_Scheduler.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. +// Code generated by mockery v2.44.2. DO NOT EDIT. package common diff --git a/mocks/sigs.k8s.io/controller-runtime/pkg/cache/mock_Cache.go b/mocks/sigs.k8s.io/controller-runtime/pkg/cache/mock_Cache.go index 51472f4..07a1253 100644 --- a/mocks/sigs.k8s.io/controller-runtime/pkg/cache/mock_Cache.go +++ b/mocks/sigs.k8s.io/controller-runtime/pkg/cache/mock_Cache.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. +// Code generated by mockery v2.44.2. DO NOT EDIT. package cache diff --git a/mocks/sigs.k8s.io/controller-runtime/pkg/client/mock_Client.go b/mocks/sigs.k8s.io/controller-runtime/pkg/client/mock_Client.go index 622867c..3b7a9c2 100644 --- a/mocks/sigs.k8s.io/controller-runtime/pkg/client/mock_Client.go +++ b/mocks/sigs.k8s.io/controller-runtime/pkg/client/mock_Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. +// Code generated by mockery v2.44.2. DO NOT EDIT. package client diff --git a/mocks/sigs.k8s.io/controller-runtime/pkg/client/mock_SubResourceClient.go b/mocks/sigs.k8s.io/controller-runtime/pkg/client/mock_SubResourceClient.go index 44e63f5..5a09e6a 100644 --- a/mocks/sigs.k8s.io/controller-runtime/pkg/client/mock_SubResourceClient.go +++ b/mocks/sigs.k8s.io/controller-runtime/pkg/client/mock_SubResourceClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. +// Code generated by mockery v2.44.2. DO NOT EDIT. package client diff --git a/mocks/sigs.k8s.io/controller-runtime/pkg/manager/mock_Manager.go b/mocks/sigs.k8s.io/controller-runtime/pkg/manager/mock_Manager.go index b489f9b..fabad62 100644 --- a/mocks/sigs.k8s.io/controller-runtime/pkg/manager/mock_Manager.go +++ b/mocks/sigs.k8s.io/controller-runtime/pkg/manager/mock_Manager.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.44.1. DO NOT EDIT. +// Code generated by mockery v2.44.2. DO NOT EDIT. package manager diff --git a/pkg/apis/v1alpha2/scheduled_resource_types.go b/pkg/apis/v1alpha2/scheduled_resource_types.go index f4edc54..dad7688 100644 --- a/pkg/apis/v1alpha2/scheduled_resource_types.go +++ b/pkg/apis/v1alpha2/scheduled_resource_types.go @@ -55,9 +55,9 @@ type ScheduledResourceSpec struct { } type ScheduledResourceStatus struct { - NextRun string `json:"nextRun"` - LastRun string `json:"lastRun"` - Condition Condition `json:"condition"` + NextRun string `json:"nextRun,omitempty"` + LastRun string `json:"lastRun,omitempty"` + Condition Condition `json:"condition,omitempty"` } func (in *ScheduledResource) IsBeingDeleted() bool { diff --git a/pkg/controllers/expiration/controller.go b/pkg/controllers/expiration/controller.go index 2353971..48dc931 100644 --- a/pkg/controllers/expiration/controller.go +++ b/pkg/controllers/expiration/controller.go @@ -76,5 +76,8 @@ func (r *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } func (r *Controller) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr).For(common.NewResourceInstance(r.apiVersionKind)).Complete(r) + return ctrl.NewControllerManagedBy(mgr). + Named(fmt.Sprintf("Expiration/%s", r.apiVersionKind)). + For(common.NewResourceInstance(r.apiVersionKind)). + Complete(r) } diff --git a/pkg/controllers/expiration/controller_test.go b/pkg/controllers/expiration/controller_test.go index 54b03a5..02801b9 100644 --- a/pkg/controllers/expiration/controller_test.go +++ b/pkg/controllers/expiration/controller_test.go @@ -386,7 +386,7 @@ func TestController_SetupWithManager(t *testing.T) { mockManager = new(manager2.MockManager) mockCache = new(cache2.MockCache) mockScheduler = new(common2.MockScheduler) - apiVersionKind = "v1;Secret" + apiVersionKind = "v1;ConfigMap" controller = NewController(common.NewConfig(), mockClient, apiVersionKind, mockScheduler) ) diff --git a/pkg/controllers/scheduledresource/controller.go b/pkg/controllers/scheduledresource/controller.go index 8d866c8..1cac8d7 100644 --- a/pkg/controllers/scheduledresource/controller.go +++ b/pkg/controllers/scheduledresource/controller.go @@ -119,6 +119,7 @@ func (r *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu func (r *Controller) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). + Named("ScheduledResource"). For(&v1alpha2.ScheduledResource{}). Complete(r) } diff --git a/pkg/controllers/scheduledresource/controller_test.go b/pkg/controllers/scheduledresource/controller_test.go index a2c95d2..929f523 100644 --- a/pkg/controllers/scheduledresource/controller_test.go +++ b/pkg/controllers/scheduledresource/controller_test.go @@ -458,7 +458,7 @@ func TestController_SetupWithManager(t *testing.T) { mockManager = new(manager2.MockManager) mockCache = new(cache2.MockCache) mockScheduler = new(common2.MockScheduler) - controller = NewController(common.NewConfig(), mockClient, mockScheduler) + controller = NewController(&common.Config{}, mockClient, mockScheduler) scheme = runtime.NewScheme() ) @@ -475,6 +475,9 @@ func TestController_SetupWithManager(t *testing.T) { // when setupErr := controller.SetupWithManager(mockManager) + if setupErr != nil && strings.Contains(setupErr.Error(), "already exists") { + setupErr = nil + } // then assert.Nil(t, addToSchemeErr)