Skip to content

Commit

Permalink
chore: use k8s.io/utils/ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhem committed Nov 12, 2024
1 parent 4425021 commit 7a2c106
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
14 changes: 7 additions & 7 deletions cmd/switcher/switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/danielfoehrkn/kubeswitch/pkg/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

switchconfig "github.com/danielfoehrkn/kubeswitch/pkg/config"
"github.com/danielfoehrkn/kubeswitch/pkg/config/validation"
Expand Down Expand Up @@ -340,11 +340,11 @@ func initialize() ([]store.KubeconfigStore, *types.Config, error) {
// this is optional, so don't care about errors
if !digitalOceanStoreAddedViaConfig {
doStore, _ := store.NewDigitalOceanStore(types.KubeconfigStore{
ID: pointer.String("doDefaultStore"),
ID: ptr.To("doDefaultStore"),
Kind: types.StoreKindDigitalOcean,
// for users with outdated `doctl` configs, don't show errors if they have no explicitly enabled the DO backing store
Required: pointer.Bool(false),
ShowPrefix: pointer.Bool(true),
Required: ptr.To(false),
ShowPrefix: ptr.To(true),
})
if doStore != nil {
// we found a valid `doctl` config, hence add Digital Ocean as a backing store with default configuration
Expand Down Expand Up @@ -392,11 +392,11 @@ func getStoreFromFlagAndEnv(config *types.Config) *types.KubeconfigStore {
}

return &types.KubeconfigStore{
ID: pointer.String("env-and-flag"),
ID: ptr.To("env-and-flag"),
Kind: types.StoreKind(storageBackend),
KubeconfigName: pointer.String(kubeconfigName),
KubeconfigName: ptr.To(kubeconfigName),
Paths: paths,
ShowPrefix: pointer.Bool(false),
ShowPrefix: ptr.To(false),
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/config/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package migration

import (
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/danielfoehrkn/kubeswitch/types"
)
Expand All @@ -34,13 +34,13 @@ func ConvertConfiguration(old types.ConfigOld) types.Config {
}

filesystemStore := types.KubeconfigStore{
ID: pointer.String("default"),
ID: ptr.To("default"),
Kind: types.StoreKindFilesystem,
Paths: []string{},
}

vaultStore := types.KubeconfigStore{
ID: pointer.String("default"),
ID: ptr.To("default"),
Kind: types.StoreKindVault,
Paths: []string{},
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/config/migration/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ package migration_test
import (
"time"

"k8s.io/utils/pointer"

"github.com/danielfoehrkn/kubeswitch/pkg/config/migration"
"github.com/danielfoehrkn/kubeswitch/types"
"k8s.io/utils/ptr"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -50,24 +49,24 @@ var _ = Describe("ValidateConfig", func() {
{
Name: "name",
Type: "type",
Path: pointer.String("my-path"),
Path: ptr.To("my-path"),
},
}

new := types.Config{
Kind: "SwitchConfig",
Version: "v1alpha1",
KubeconfigName: pointer.String("name"),
KubeconfigName: ptr.To("name"),
RefreshIndexAfter: &refreshIndexAfter,
Hooks: hooks,
KubeconfigStores: []types.KubeconfigStore{
{
ID: pointer.String("default"),
ID: ptr.To("default"),
Kind: types.StoreKindFilesystem,
Paths: []string{"path", "other-path"},
},
{
ID: pointer.String("default"),
ID: ptr.To("default"),
Kind: types.StoreKindVault,
Paths: []string{"path", "other-path"},
Config: types.StoreConfigVault{VaultAPIAddress: "vault-api"},
Expand Down
14 changes: 7 additions & 7 deletions pkg/config/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/danielfoehrkn/kubeswitch/pkg/config/validation"
"github.com/danielfoehrkn/kubeswitch/types"
Expand Down Expand Up @@ -176,13 +176,13 @@ var _ = Describe("ValidateConfig", func() {
Kind: types.StoreKindVault,
RefreshIndexAfter: &minute,
Paths: []string{"ab"},
ID: pointer.String("id-one"),
ID: ptr.To("id-one"),
},
{
Kind: types.StoreKindVault,
RefreshIndexAfter: &minute,
Paths: []string{"ab"},
ID: pointer.String("id-two"),
ID: ptr.To("id-two"),
},
},
}
Expand Down Expand Up @@ -220,14 +220,14 @@ var _ = Describe("ValidateConfig", func() {
Kind: types.StoreKindGardener,
Config: types.StoreConfigGardener{
GardenerAPIKubeconfigPath: "my-path-to-gardener-kubeconfig",
LandscapeName: pointer.String("dev"),
LandscapeName: ptr.To("dev"),
},
},
{
Kind: types.StoreKindGardener,
Config: types.StoreConfigGardener{
GardenerAPIKubeconfigPath: "my-path-to-gardener-kubeconfig",
LandscapeName: pointer.String("canary"),
LandscapeName: ptr.To("canary"),
},
},
},
Expand Down Expand Up @@ -355,7 +355,7 @@ var _ = Describe("ValidateConfig", func() {
Kind: types.StoreKindGardener,
Config: types.StoreConfigGardener{
GardenerAPIKubeconfigPath: "xy",
LandscapeName: pointer.String(""),
LandscapeName: ptr.To(""),
},
},
},
Expand All @@ -380,7 +380,7 @@ var _ = Describe("ValidateConfig", func() {
{
Name: "my-hooks",
Type: types.HookTypeExecutable,
Path: pointer.String("my-path"),
Path: ptr.To("my-path"),
},
},
}
Expand Down

0 comments on commit 7a2c106

Please sign in to comment.