Skip to content
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: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lint: mod-tidy vet staticcheck golangci-lint modernize govulncheck
lint-fix:
go mod tidy
golangci-lint run --fix
go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -test -fix ./...
go fix ./...
$(MAKE) lint

mod-tidy:
Expand All @@ -35,7 +35,7 @@ staticcheck:
go run honnef.co/go/tools/cmd/staticcheck@latest ./...

modernize:
go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -test ./...
go fix -diff ./... | awk '{print} /\S/ {found=1} END {if (found) exit 1}'

govulncheck:
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
Expand Down
7 changes: 3 additions & 4 deletions api/gitinfo/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
apps "github.com/ninech/apis/apps/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -95,14 +94,14 @@ func AuthSecretName(app *apps.Application) string {
// UpdateFromSecret updates the Auth object with the data from the given secret.
func (a *Auth) UpdateFromSecret(secret *corev1.Secret) {
if val, ok := secret.Data[PrivateKeySecretKey]; ok {
a.SSHPrivateKey = ptr.To(string(val))
a.SSHPrivateKey = new(string(val))
}

if val, ok := secret.Data[UsernameSecretKey]; ok {
a.Username = ptr.To(string(val))
a.Username = new(string(val))
}

if val, ok := secret.Data[PasswordSecretKey]; ok {
a.Password = ptr.To(string(val))
a.Password = new(string(val))
}
}
7 changes: 3 additions & 4 deletions api/gitinfo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/ninech/nctl/internal/test"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/utils/ptr"
)

func TestRepositoryInformation(t *testing.T) {
Expand Down Expand Up @@ -42,8 +41,8 @@ func TestRepositoryInformation(t *testing.T) {
},
token: "fake",
auth: gitinfo.Auth{
Username: ptr.To("fake"),
Password: ptr.To("fakePass"),
Username: new("fake"),
Password: new("fakePass"),
SSHPrivateKey: &dummyPrivateKey,
},
setResponse: &test.GitInformationServiceResponse{
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestRepositoryInformation(t *testing.T) {
},
setResponse: &test.GitInformationServiceResponse{
Code: http.StatusBadGateway,
Raw: ptr.To("currently unavailable"),
Raw: new("currently unavailable"),
},
errorExpected: true,
},
Expand Down
3 changes: 1 addition & 2 deletions auth/client_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"golang.org/x/oauth2/clientcredentials"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientauthenticationv1 "k8s.io/client-go/pkg/apis/clientauthentication/v1"
"k8s.io/utils/ptr"

clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
Expand Down Expand Up @@ -42,7 +41,7 @@ func (c *ClientCredentialsCmd) Run(ctx context.Context) error {
},
Status: &clientauthenticationv1.ExecCredentialStatus{
Token: token.AccessToken,
ExpirationTimestamp: ptr.To(metav1.NewTime(token.Expiry)),
ExpirationTimestamp: new(metav1.NewTime(token.Expiry)),
},
}
return json.NewEncoder(os.Stdout).Encode(execCredential)
Expand Down
7 changes: 3 additions & 4 deletions create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/utils/ptr"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -301,7 +300,7 @@ func (cmd *applicationCmd) config() apps.Config {
Command: cmd.DeployJob.Command,
},
FiniteJob: apps.FiniteJob{
Retries: ptr.To(cmd.DeployJob.Retries),
Retries: new(cmd.DeployJob.Retries),
Timeout: &metav1.Duration{Duration: cmd.DeployJob.Timeout},
},
}
Expand All @@ -320,7 +319,7 @@ func (cmd *applicationCmd) config() apps.Config {
},
}
if cmd.WorkerJob.Size != nil {
workerJob.Size = ptr.To(apps.ApplicationSize(*cmd.WorkerJob.Size))
workerJob.Size = new(apps.ApplicationSize(*cmd.WorkerJob.Size))
}
config.WorkerJobs = append(config.WorkerJobs, workerJob)
}
Expand All @@ -339,7 +338,7 @@ func (cmd *applicationCmd) config() apps.Config {
Schedule: cmd.ScheduledJob.Schedule,
}
if cmd.ScheduledJob.Size != nil {
scheduledJob.Size = ptr.To(apps.ApplicationSize(*cmd.ScheduledJob.Size))
scheduledJob.Size = new(apps.ApplicationSize(*cmd.ScheduledJob.Size))
}
config.ScheduledJobs = append(config.ScheduledJobs, scheduledJob)
}
Expand Down
53 changes: 26 additions & 27 deletions create/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
)

func createTempKeyFile(content string) (string, error) {
Expand Down Expand Up @@ -85,12 +84,12 @@ func TestCreateApplication(t *testing.T) {
SubPath: "/my/app",
Revision: "superbug",
},
Size: ptr.To("mini"),
Size: new("mini"),
Hosts: []string{"custom.example.org", "custom2.example.org"},
Port: ptr.To(int32(1337)),
Port: new(int32(1337)),
HealthProbe: healthProbe{PeriodSeconds: int32(7), Path: "/he"},
Replicas: ptr.To(int32(42)),
BasicAuth: ptr.To(false),
Replicas: new(int32(42)),
BasicAuth: new(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},
Expand Down Expand Up @@ -124,8 +123,8 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "basic-auth",
},
Size: ptr.To("mini"),
BasicAuth: ptr.To(true),
Size: new("mini"),
BasicAuth: new(true),
SkipRepoAccessCheck: true,
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
Expand All @@ -139,8 +138,8 @@ func TestCreateApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
Username: ptr.To("deploy"),
Password: ptr.To("hunter2"),
Username: new("deploy"),
Password: new("hunter2"),
},
resourceCmd: resourceCmd{
Wait: false,
Expand Down Expand Up @@ -170,7 +169,7 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "ssh-key-auth",
},
Size: ptr.To("mini"),
Size: new("mini"),
SkipRepoAccessCheck: true,
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
Expand All @@ -194,7 +193,7 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "ssh-key-auth-ed25519",
},
Size: ptr.To("mini"),
Size: new("mini"),
SkipRepoAccessCheck: true,
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
Expand All @@ -212,13 +211,13 @@ func TestCreateApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
SSHPrivateKeyFromFile: ptr.To(filenameRSAKey),
SSHPrivateKeyFromFile: new(filenameRSAKey),
},
resourceCmd: resourceCmd{
Wait: false,
Name: "ssh-key-auth-from-file",
},
Size: ptr.To("mini"),
Size: new("mini"),
SkipRepoAccessCheck: true,
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
Expand All @@ -236,13 +235,13 @@ func TestCreateApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
SSHPrivateKeyFromFile: ptr.To(filenameED25519Key),
SSHPrivateKeyFromFile: new(filenameED25519Key),
},
resourceCmd: resourceCmd{
Wait: false,
Name: "ssh-key-auth-from-file-ed25519",
},
Size: ptr.To("mini"),
Size: new("mini"),
SkipRepoAccessCheck: true,
},
checkApp: func(t *testing.T, cmd applicationCmd, app *apps.Application) {
Expand All @@ -260,13 +259,13 @@ func TestCreateApplication(t *testing.T) {
cmd: applicationCmd{
Git: gitConfig{
URL: "https://github.com/ninech/doesnotexist.git",
SSHPrivateKey: ptr.To("not valid"),
SSHPrivateKey: new("not valid"),
},
resourceCmd: resourceCmd{
Wait: false,
Name: "ssh-key-auth-non-valid",
},
Size: ptr.To("mini"),
Size: new("mini"),
SkipRepoAccessCheck: true,
},
errorExpected: true,
Expand All @@ -280,7 +279,7 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "deploy-job-empty-command",
},
Size: ptr.To("mini"),
Size: new("mini"),
DeployJob: deployJob{Command: "", Name: "print-date", Retries: 2, Timeout: time.Minute},
SkipRepoAccessCheck: true,
},
Expand All @@ -298,7 +297,7 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "deploy-job-empty-name",
},
Size: ptr.To("mini"),
Size: new("mini"),
DeployJob: deployJob{Command: "date", Name: "", Retries: 2, Timeout: time.Minute},
SkipRepoAccessCheck: true,
},
Expand All @@ -318,7 +317,7 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "git-information-happy-path",
},
Size: ptr.To("mini"),
Size: new("mini"),
},
gitInformationServiceResponse: test.GitInformationServiceResponse{
Code: 200,
Expand Down Expand Up @@ -355,7 +354,7 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "git-information-errors",
},
Size: ptr.To("mini"),
Size: new("mini"),
},
gitInformationServiceResponse: test.GitInformationServiceResponse{
Code: 200,
Expand All @@ -376,7 +375,7 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "git-information-unknown-revision",
},
Size: ptr.To("mini"),
Size: new("mini"),
},
gitInformationServiceResponse: test.GitInformationServiceResponse{
Code: 200,
Expand Down Expand Up @@ -405,11 +404,11 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "git-information-unknown-revision",
},
Size: ptr.To("mini"),
Size: new("mini"),
},
gitInformationServiceResponse: test.GitInformationServiceResponse{
Code: 501,
Raw: ptr.To("maintenance mode - we will be back soon"),
Raw: new("maintenance mode - we will be back soon"),
},
errorExpected: true,
},
Expand All @@ -424,7 +423,7 @@ func TestCreateApplication(t *testing.T) {
Wait: false,
Name: "git-information-update-url-to-https",
},
Size: ptr.To("mini"),
Size: new("mini"),
},
gitInformationServiceResponse: test.GitInformationServiceResponse{
Code: 200,
Expand Down Expand Up @@ -514,7 +513,7 @@ func TestApplicationWait(t *testing.T) {
WaitTimeout: time.Second * 5,
Name: "some-name",
},
BasicAuth: ptr.To(true),
BasicAuth: new(true),
SkipRepoAccessCheck: true,
}
project := test.DefaultProject
Expand All @@ -540,7 +539,7 @@ func TestApplicationWait(t *testing.T) {
Spec: apps.ReleaseSpec{
ForProvider: apps.ReleaseParameters{
Configuration: apps.Config{
EnableBasicAuth: ptr.To(true),
EnableBasicAuth: new(true),
}.WithOrigin(apps.ConfigOriginApplication),
},
},
Expand Down
3 changes: 1 addition & 2 deletions create/cloudvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/ninech/nctl/internal/test"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)

func TestCloudVM(t *testing.T) {
Expand Down Expand Up @@ -38,7 +37,7 @@ func TestCloudVM(t *testing.T) {
},
{
name: "bootDisk",
create: cloudVMCmd{BootDiskSize: ptr.To(resource.MustParse("1Gi"))},
create: cloudVMCmd{BootDiskSize: new(resource.MustParse("1Gi"))},
want: infrastructure.CloudVirtualMachineParameters{
BootDisk: &infrastructure.Disk{
Name: "root", Size: resource.MustParse("1Gi"),
Expand Down
Loading