From 7d750d3922114bfa649498ce7d1e41f97402530b Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Wed, 10 Jan 2024 15:19:28 +0100 Subject: [PATCH] chore: replace deprecated pointer package with ptr --- create/application.go | 4 +- create/application_test.go | 48 +++++++++---------- create/project_config.go | 4 +- create/project_config_test.go | 10 ++-- get/project_config_test.go | 6 +-- get/releases_test.go | 6 +-- update/application_test.go | 86 +++++++++++++++++------------------ update/project_config_test.go | 26 +++++------ 8 files changed, 95 insertions(+), 95 deletions(-) diff --git a/create/application.go b/create/application.go index 9c6a8e1..e883eb4 100644 --- a/create/application.go +++ b/create/application.go @@ -22,7 +22,7 @@ import ( kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -208,7 +208,7 @@ func (app *applicationCmd) config() apps.Config { Command: app.DeployJob.Command, }, FiniteJob: apps.FiniteJob{ - Retries: pointer.Int32(app.DeployJob.Retries), + Retries: ptr.To(app.DeployJob.Retries), Timeout: &metav1.Duration{Duration: app.DeployJob.Timeout}, }, } diff --git a/create/application_test.go b/create/application_test.go index d91a60b..1cd3568 100644 --- a/create/application_test.go +++ b/create/application_test.go @@ -22,7 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) const ( @@ -120,11 +120,11 @@ func TestApplication(t *testing.T) { }, Wait: false, Name: "custom-name", - Size: pointer.String("mini"), + Size: ptr.To("mini"), Hosts: []string{"custom.example.org", "custom2.example.org"}, - Port: pointer.Int32(1337), - Replicas: pointer.Int32(42), - BasicAuth: pointer.Bool(false), + Port: ptr.To(int32(1337)), + Replicas: ptr.To(int32(42)), + BasicAuth: ptr.To(false), Env: map[string]string{"hello": "world"}, BuildEnv: map[string]string{"BP_GO_TARGETS": "./cmd/web-server"}, DeployJob: deployJob{Command: "date", Name: "print-date", Retries: 2, Timeout: time.Minute}, @@ -152,8 +152,8 @@ func TestApplication(t *testing.T) { cmd: applicationCmd{ Wait: false, Name: "basic-auth", - Size: pointer.String("mini"), - BasicAuth: pointer.Bool(true), + Size: ptr.To("mini"), + BasicAuth: ptr.To(true), }, checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) { assert.Equal(t, cmd.Name, app.Name) @@ -165,8 +165,8 @@ func TestApplication(t *testing.T) { cmd: applicationCmd{ Git: gitConfig{ URL: "https://github.com/ninech/doesnotexist.git", - Username: pointer.String("deploy"), - Password: pointer.String("hunter2"), + Username: ptr.To("deploy"), + Password: ptr.To("hunter2"), }, Wait: false, Name: "user-pass-auth", @@ -187,11 +187,11 @@ func TestApplication(t *testing.T) { cmd: applicationCmd{ Git: gitConfig{ URL: "https://github.com/ninech/doesnotexist.git", - SSHPrivateKey: pointer.String(dummySSHRSAPrivateKey), + SSHPrivateKey: ptr.To(dummySSHRSAPrivateKey), }, Wait: false, Name: "ssh-key-auth", - Size: pointer.String("mini"), + Size: ptr.To("mini"), }, checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) { auth := util.GitAuth{SSHPrivateKey: cmd.Git.SSHPrivateKey} @@ -208,11 +208,11 @@ func TestApplication(t *testing.T) { cmd: applicationCmd{ Git: gitConfig{ URL: "https://github.com/ninech/doesnotexist.git", - SSHPrivateKey: pointer.String(dummySSHED25519PrivateKey), + SSHPrivateKey: ptr.To(dummySSHED25519PrivateKey), }, Wait: false, Name: "ssh-key-auth-ed25519", - Size: pointer.String("mini"), + Size: ptr.To("mini"), }, checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) { auth := util.GitAuth{SSHPrivateKey: cmd.Git.SSHPrivateKey} @@ -229,14 +229,14 @@ func TestApplication(t *testing.T) { cmd: applicationCmd{ Git: gitConfig{ URL: "https://github.com/ninech/doesnotexist.git", - SSHPrivateKeyFromFile: pointer.String(filenameRSAKey), + SSHPrivateKeyFromFile: ptr.To(filenameRSAKey), }, Wait: false, Name: "ssh-key-auth-from-file", - Size: pointer.String("mini"), + Size: ptr.To("mini"), }, checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) { - auth := util.GitAuth{SSHPrivateKey: pointer.String("notused")} + auth := util.GitAuth{SSHPrivateKey: ptr.To("notused")} authSecret := auth.Secret(app) if err := apiClient.Get(ctx, api.ObjectName(authSecret), authSecret); err != nil { t.Fatal(err) @@ -250,14 +250,14 @@ func TestApplication(t *testing.T) { cmd: applicationCmd{ Git: gitConfig{ URL: "https://github.com/ninech/doesnotexist.git", - SSHPrivateKeyFromFile: pointer.String(filenameED25519Key), + SSHPrivateKeyFromFile: ptr.To(filenameED25519Key), }, Wait: false, Name: "ssh-key-auth-from-file-ed25519", - Size: pointer.String("mini"), + Size: ptr.To("mini"), }, checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) { - auth := util.GitAuth{SSHPrivateKey: pointer.String("notused")} + auth := util.GitAuth{SSHPrivateKey: ptr.To("notused")} authSecret := auth.Secret(app) if err := apiClient.Get(ctx, api.ObjectName(authSecret), authSecret); err != nil { t.Fatal(err) @@ -271,11 +271,11 @@ func TestApplication(t *testing.T) { cmd: applicationCmd{ Git: gitConfig{ URL: "https://github.com/ninech/doesnotexist.git", - SSHPrivateKey: pointer.String("not valid"), + SSHPrivateKey: ptr.To("not valid"), }, Wait: false, Name: "ssh-key-auth-non-valid", - Size: pointer.String("mini"), + Size: ptr.To("mini"), }, errorExpected: true, }, @@ -286,7 +286,7 @@ func TestApplication(t *testing.T) { }, Wait: false, Name: "deploy-job-empty-command", - Size: pointer.String("mini"), + Size: ptr.To("mini"), DeployJob: deployJob{Command: "", Name: "print-date", Retries: 2, Timeout: time.Minute}, }, checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) { @@ -300,7 +300,7 @@ func TestApplication(t *testing.T) { }, Wait: false, Name: "deploy-job-empty-name", - Size: pointer.String("mini"), + Size: ptr.To("mini"), DeployJob: deployJob{Command: "date", Name: "", Retries: 2, Timeout: time.Minute}, }, checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) { @@ -334,7 +334,7 @@ func TestApplicationWait(t *testing.T) { Wait: true, WaitTimeout: time.Second * 5, Name: "some-name", - BasicAuth: pointer.Bool(true), + BasicAuth: ptr.To(true), } project := "default" diff --git a/create/project_config.go b/create/project_config.go index 9e276b8..ec01f89 100644 --- a/create/project_config.go +++ b/create/project_config.go @@ -7,7 +7,7 @@ import ( "github.com/ninech/nctl/api" "github.com/ninech/nctl/api/util" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // all fields need to be pointers so we can detect if they have been set by @@ -41,7 +41,7 @@ func (cmd *configCmd) newProjectConfig(namespace string) *apps.ProjectConfig { Command: cmd.DeployJob.Command, }, FiniteJob: apps.FiniteJob{ - Retries: pointer.Int32(cmd.DeployJob.Retries), + Retries: ptr.To(cmd.DeployJob.Retries), Timeout: &metav1.Duration{Duration: cmd.DeployJob.Timeout}, }, } diff --git a/create/project_config_test.go b/create/project_config_test.go index 988b723..2d33812 100644 --- a/create/project_config_test.go +++ b/create/project_config_test.go @@ -10,7 +10,7 @@ import ( "github.com/ninech/nctl/api/util" "github.com/ninech/nctl/internal/test" "github.com/stretchr/testify/assert" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) func TestProjectConfig(t *testing.T) { @@ -29,10 +29,10 @@ func TestProjectConfig(t *testing.T) { "all fields set": { cmd: configCmd{ Size: string(test.AppMini), - Port: pointer.Int32(1337), - Replicas: pointer.Int32(42), + Port: ptr.To(int32(1337)), + Replicas: ptr.To(int32(42)), Env: &map[string]string{"key1": "val1"}, - BasicAuth: pointer.Bool(true), + BasicAuth: ptr.To(true), DeployJob: deployJob{ Command: "exit 0", Name: "exit", Retries: 1, Timeout: time.Minute * 5, @@ -55,7 +55,7 @@ func TestProjectConfig(t *testing.T) { "some fields not set": { cmd: configCmd{ Size: string(test.AppMicro), - Replicas: pointer.Int32(1), + Replicas: ptr.To(int32(1)), }, project: "namespace-2", checkConfig: func(t *testing.T, cmd configCmd, cfg *apps.ProjectConfig) { diff --git a/get/project_config_test.go b/get/project_config_test.go index 86d821e..0850f13 100644 --- a/get/project_config_test.go +++ b/get/project_config_test.go @@ -13,7 +13,7 @@ import ( "github.com/ninech/nctl/internal/test" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" ) @@ -182,8 +182,8 @@ func fakeProjectConfig( ForProvider: apps.ProjectConfigParameters{ Config: apps.Config{ Size: test.AppMicro, - Replicas: pointer.Int32(1), - Port: pointer.Int32(9000), + Replicas: ptr.To(int32(1)), + Port: ptr.To(int32(9000)), Env: util.EnvVarsFromMap(map[string]string{"key1": "val1"}), }, }, diff --git a/get/releases_test.go b/get/releases_test.go index 85d178f..cec6aa5 100644 --- a/get/releases_test.go +++ b/get/releases_test.go @@ -15,7 +15,7 @@ import ( "github.com/ninech/nctl/internal/test" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" ) @@ -23,8 +23,8 @@ import ( var ( defaultConfig = apps.Config{ Size: test.AppMicro, - Replicas: pointer.Int32(1), - Port: pointer.Int32(8080), + Replicas: ptr.To(int32(1)), + Port: ptr.To(int32(8080)), } defaultCreationTime = metav1.NewTime(test.MustParseTime(time.RFC3339, "2023-03-13T14:00:00Z")) diff --git a/update/application_test.go b/update/application_test.go index 57f3d06..0f28091 100644 --- a/update/application_test.go +++ b/update/application_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" ) @@ -42,17 +42,17 @@ func TestApplication(t *testing.T) { Hosts: []string{"one.example.org"}, Config: apps.Config{ Size: initialSize, - Replicas: pointer.Int32(1), - Port: pointer.Int32(1337), + Replicas: ptr.To(int32(1)), + Port: ptr.To(int32(1337)), Env: util.EnvVarsFromMap(map[string]string{"foo": "bar"}), - EnableBasicAuth: pointer.Bool(false), + EnableBasicAuth: ptr.To(false), DeployJob: &apps.DeployJob{ Job: apps.Job{ Command: "date", Name: "print-date", }, FiniteJob: apps.FiniteJob{ - Retries: pointer.Int32(2), + Retries: ptr.To(int32(2)), Timeout: &metav1.Duration{Duration: time.Minute}, }, }, @@ -72,8 +72,8 @@ func TestApplication(t *testing.T) { "change port": { orig: existingApp, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), - Port: pointer.Int32(1234), + Name: ptr.To(existingApp.Name), + Port: ptr.To(int32(1234)), }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { assert.Equal(t, *cmd.Port, *updated.Spec.ForProvider.Config.Port) @@ -82,8 +82,8 @@ func TestApplication(t *testing.T) { "port is unchanged when updating unrelated field": { orig: existingApp, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), - Size: pointer.String("newsize"), + Name: ptr.To(existingApp.Name), + Size: ptr.To("newsize"), }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { assert.Equal(t, *orig.Spec.ForProvider.Config.Port, *updated.Spec.ForProvider.Config.Port) @@ -93,22 +93,22 @@ func TestApplication(t *testing.T) { "all field updates": { orig: existingApp, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), + Name: ptr.To(existingApp.Name), Git: &gitConfig{ - URL: pointer.String("https://newgit.example.org"), - SubPath: pointer.String("new/path"), - Revision: pointer.String("some-change"), + URL: ptr.To("https://newgit.example.org"), + SubPath: ptr.To("new/path"), + Revision: ptr.To("some-change"), }, - Size: pointer.String("newsize"), - Port: pointer.Int32(1234), - Replicas: pointer.Int32(999), + Size: ptr.To("newsize"), + Port: ptr.To(int32(1234)), + Replicas: ptr.To(int32(999)), Hosts: &[]string{"one.example.org", "two.example.org"}, Env: &map[string]string{"bar": "zoo"}, BuildEnv: &map[string]string{"BP_GO_TARGETS": "./cmd/web-server"}, - BasicAuth: pointer.Bool(true), + BasicAuth: ptr.To(true), DeployJob: &deployJob{ - Command: pointer.String("exit 0"), Name: pointer.String("exit"), - Retries: pointer.Int32(1), Timeout: pointer.Duration(time.Minute * 5), + Command: ptr.To("exit 0"), Name: ptr.To("exit"), + Retries: ptr.To(int32(1)), Timeout: ptr.To(time.Minute * 5), }, }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { @@ -133,7 +133,7 @@ func TestApplication(t *testing.T) { "reset env variable": { orig: existingApp, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), + Name: ptr.To(existingApp.Name), DeleteEnv: &[]string{"foo"}, }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { @@ -144,7 +144,7 @@ func TestApplication(t *testing.T) { "reset build env variable": { orig: existingApp, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), + Name: ptr.To(existingApp.Name), DeleteBuildEnv: &[]string{"BP_ENVIRONMENT_VARIABLE"}, }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { @@ -155,14 +155,14 @@ func TestApplication(t *testing.T) { "git auth update user/pass": { orig: existingApp, gitAuth: &util.GitAuth{ - Username: pointer.String("some-user"), - Password: pointer.String("some-password"), + Username: ptr.To("some-user"), + Password: ptr.To("some-password"), }, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), + Name: ptr.To(existingApp.Name), Git: &gitConfig{ - Username: pointer.String("new-user"), - Password: pointer.String("new-pass"), + Username: ptr.To("new-user"), + Password: ptr.To("new-pass"), }, }, checkSecret: func(t *testing.T, cmd applicationCmd, authSecret *corev1.Secret) { @@ -174,12 +174,12 @@ func TestApplication(t *testing.T) { "git auth update ssh key": { orig: existingApp, gitAuth: &util.GitAuth{ - SSHPrivateKey: pointer.String("fakekey"), + SSHPrivateKey: ptr.To("fakekey"), }, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), + Name: ptr.To(existingApp.Name), Git: &gitConfig{ - SSHPrivateKey: pointer.String("newfakekey"), + SSHPrivateKey: ptr.To("newfakekey"), }, }, checkSecret: func(t *testing.T, cmd applicationCmd, authSecret *corev1.Secret) { @@ -191,10 +191,10 @@ func TestApplication(t *testing.T) { orig: existingApp, gitAuth: nil, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), + Name: ptr.To(existingApp.Name), Git: &gitConfig{ - Username: pointer.String("new-user"), - Password: pointer.String("new-pass"), + Username: ptr.To("new-user"), + Password: ptr.To("new-pass"), }, }, checkSecret: func(t *testing.T, cmd applicationCmd, authSecret *corev1.Secret) { @@ -206,12 +206,12 @@ func TestApplication(t *testing.T) { "git auth is unchanged on normal field update": { orig: existingApp, gitAuth: &util.GitAuth{ - SSHPrivateKey: pointer.String("fakekey"), + SSHPrivateKey: ptr.To("fakekey"), }, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), + Name: ptr.To(existingApp.Name), Git: &gitConfig{ - URL: pointer.String("https://newgit.example.org"), + URL: ptr.To("https://newgit.example.org"), }, }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { @@ -225,14 +225,14 @@ func TestApplication(t *testing.T) { "disable deploy job": { orig: existingApp, gitAuth: &util.GitAuth{ - SSHPrivateKey: pointer.String("fakekey"), + SSHPrivateKey: ptr.To("fakekey"), }, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), + Name: ptr.To(existingApp.Name), Git: &gitConfig{ - URL: pointer.String("https://newgit.example.org"), + URL: ptr.To("https://newgit.example.org"), }, - DeployJob: &deployJob{Enabled: pointer.Bool(false)}, + DeployJob: &deployJob{Enabled: ptr.To(false)}, }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { assert.Nil(t, updated.Spec.ForProvider.Config.DeployJob) @@ -241,8 +241,8 @@ func TestApplication(t *testing.T) { "retry build": { orig: existingApp, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), - RetryBuild: pointer.Bool(true), + Name: ptr.To(existingApp.Name), + RetryBuild: ptr.To(true), }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { assert.NotNil(t, util.EnvVarByName(updated.Spec.ForProvider.BuildEnv, BuildTrigger)) @@ -251,8 +251,8 @@ func TestApplication(t *testing.T) { "do not retry build": { orig: existingApp, cmd: applicationCmd{ - Name: pointer.String(existingApp.Name), - RetryBuild: pointer.Bool(false), + Name: ptr.To(existingApp.Name), + RetryBuild: ptr.To(false), }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { assert.Nil(t, util.EnvVarByName(updated.Spec.ForProvider.BuildEnv, BuildTrigger)) diff --git a/update/project_config_test.go b/update/project_config_test.go index 9852d94..84a61d9 100644 --- a/update/project_config_test.go +++ b/update/project_config_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) func TestConfig(t *testing.T) { @@ -29,10 +29,10 @@ func TestConfig(t *testing.T) { ForProvider: apps.ProjectConfigParameters{ Config: apps.Config{ Size: initialSize, - Replicas: pointer.Int32(1), - Port: pointer.Int32(1337), + Replicas: ptr.To(int32(1)), + Port: ptr.To(int32(1337)), Env: util.EnvVarsFromMap(map[string]string{"foo": "bar"}), - EnableBasicAuth: pointer.Bool(false), + EnableBasicAuth: ptr.To(false), }, }, }, @@ -48,7 +48,7 @@ func TestConfig(t *testing.T) { orig: existingConfig, project: project, cmd: configCmd{ - Port: pointer.Int32(1234), + Port: ptr.To(int32(1234)), }, checkConfig: func(t *testing.T, cmd configCmd, orig, updated *apps.ProjectConfig) { assert.Equal(t, *cmd.Port, *updated.Spec.ForProvider.Config.Port) @@ -58,7 +58,7 @@ func TestConfig(t *testing.T) { orig: existingConfig, project: project, cmd: configCmd{ - Size: pointer.String("newsize"), + Size: ptr.To("newsize"), }, checkConfig: func(t *testing.T, cmd configCmd, orig, updated *apps.ProjectConfig) { assert.Equal(t, *orig.Spec.ForProvider.Config.Port, *updated.Spec.ForProvider.Config.Port) @@ -69,7 +69,7 @@ func TestConfig(t *testing.T) { orig: existingConfig, project: project, cmd: configCmd{ - BasicAuth: pointer.Bool(true), + BasicAuth: ptr.To(true), }, checkConfig: func(t *testing.T, cmd configCmd, orig, updated *apps.ProjectConfig) { assert.True(t, *updated.Spec.ForProvider.Config.EnableBasicAuth) @@ -79,14 +79,14 @@ func TestConfig(t *testing.T) { orig: existingConfig, project: project, cmd: configCmd{ - Size: pointer.String("newsize"), - Port: pointer.Int32(1000), - Replicas: pointer.Int32(2), + Size: ptr.To("newsize"), + Port: ptr.To(int32(1000)), + Replicas: ptr.To(int32(2)), Env: &map[string]string{"zoo": "bar"}, - BasicAuth: pointer.Bool(true), + BasicAuth: ptr.To(true), DeployJob: &deployJob{ - Command: pointer.String("exit 0"), Name: pointer.String("exit"), - Retries: pointer.Int32(1), Timeout: pointer.Duration(time.Minute * 5), + Command: ptr.To("exit 0"), Name: ptr.To("exit"), + Retries: ptr.To(int32(1)), Timeout: ptr.To(time.Minute * 5), }, }, checkConfig: func(t *testing.T, cmd configCmd, orig, updated *apps.ProjectConfig) {