From 14f54d0b26a792e39f435ba295058694b5d5b723 Mon Sep 17 00:00:00 2001 From: Derek Nola Date: Thu, 28 Mar 2024 10:07:02 -0700 Subject: [PATCH] Transition from deprecated pointer library to ptr (#9801) Signed-off-by: Derek Nola --- go.mod | 2 +- go.sum | 3 ++- pkg/agent/run.go | 6 +++--- pkg/agent/run_test.go | 4 ++-- pkg/cli/secretsencrypt/secrets_encrypt.go | 14 +++++++------- pkg/cli/token/token.go | 4 ++-- pkg/cloudprovider/servicelb.go | 4 ++-- pkg/etcd/snapshot.go | 4 ++-- pkg/nodepassword/nodepassword.go | 4 ++-- pkg/server/secrets-encrypt.go | 6 +++--- pkg/spegel/spegel.go | 4 ++-- 11 files changed, 28 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index 66c61d75df..5a90c5ae59 100644 --- a/go.mod +++ b/go.mod @@ -179,7 +179,7 @@ require ( k8s.io/kube-proxy v0.0.0 k8s.io/kubectl v0.25.0 k8s.io/kubernetes v1.29.3 - k8s.io/utils v0.0.0-20230726121419-3b25d923346b + k8s.io/utils v0.0.0-20240310230437-4693a0247e57 sigs.k8s.io/yaml v1.4.0 ) diff --git a/go.sum b/go.sum index 1483bfb89b..ddaa1e7699 100644 --- a/go.sum +++ b/go.sum @@ -2172,8 +2172,9 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20240310230437-4693a0247e57 h1:gbqbevonBh57eILzModw6mrkbwM0gQBEuevE/AaBsHY= +k8s.io/utils v0.0.0-20240310230437-4693a0247e57/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= diff --git a/pkg/agent/run.go b/pkg/agent/run.go index 19bd38ab51..c5b3954c21 100644 --- a/pkg/agent/run.go +++ b/pkg/agent/run.go @@ -48,7 +48,7 @@ import ( app2 "k8s.io/kubernetes/cmd/kube-proxy/app" kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config" utilsnet "k8s.io/utils/net" - utilpointer "k8s.io/utils/pointer" + utilsptr "k8s.io/utils/ptr" ) func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error { @@ -201,8 +201,8 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error { // When running rootless, we do not attempt to set conntrack sysctls - this behavior is copied from kubeadm. func getConntrackConfig(nodeConfig *daemonconfig.Node) (*kubeproxyconfig.KubeProxyConntrackConfiguration, error) { ctConfig := &kubeproxyconfig.KubeProxyConntrackConfiguration{ - MaxPerCore: utilpointer.Int32Ptr(0), - Min: utilpointer.Int32Ptr(0), + MaxPerCore: utilsptr.To(int32(0)), + Min: utilsptr.To(int32(0)), TCPEstablishedTimeout: &metav1.Duration{}, TCPCloseWaitTimeout: &metav1.Duration{}, } diff --git a/pkg/agent/run_test.go b/pkg/agent/run_test.go index 893f3ceabe..73c95bd2e2 100644 --- a/pkg/agent/run_test.go +++ b/pkg/agent/run_test.go @@ -9,7 +9,7 @@ import ( v1alpha1 "k8s.io/kube-proxy/config/v1alpha1" kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config" kubeproxyconfigv1alpha1 "k8s.io/kubernetes/pkg/proxy/apis/config/v1alpha1" - utilpointer "k8s.io/utils/pointer" + utilsptr "k8s.io/utils/ptr" ) func Test_UnitGetConntrackConfig(t *testing.T) { @@ -23,7 +23,7 @@ func Test_UnitGetConntrackConfig(t *testing.T) { } customConfig := defaultConfig.DeepCopy() - customConfig.Conntrack.Min = utilpointer.Int32Ptr(100) + customConfig.Conntrack.Min = utilsptr.To(int32(100)) customConfig.Conntrack.TCPCloseWaitTimeout.Duration = 42 * time.Second type args struct { diff --git a/pkg/cli/secretsencrypt/secrets_encrypt.go b/pkg/cli/secretsencrypt/secrets_encrypt.go index 04579edae8..d43271b1fe 100644 --- a/pkg/cli/secretsencrypt/secrets_encrypt.go +++ b/pkg/cli/secretsencrypt/secrets_encrypt.go @@ -18,7 +18,7 @@ import ( "github.com/k3s-io/k3s/pkg/version" "github.com/pkg/errors" "github.com/urfave/cli" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) func commandPrep(cfg *cmds.Server) (*clientaccess.Info, error) { @@ -54,7 +54,7 @@ func Enable(app *cli.Context) error { if err != nil { return err } - b, err := json.Marshal(server.EncryptionRequest{Enable: pointer.Bool(true)}) + b, err := json.Marshal(server.EncryptionRequest{Enable: ptr.To(true)}) if err != nil { return err } @@ -74,7 +74,7 @@ func Disable(app *cli.Context) error { if err != nil { return err } - b, err := json.Marshal(server.EncryptionRequest{Enable: pointer.Bool(false)}) + b, err := json.Marshal(server.EncryptionRequest{Enable: ptr.To(false)}) if err != nil { return err } @@ -155,7 +155,7 @@ func Prepare(app *cli.Context) error { return err } b, err := json.Marshal(server.EncryptionRequest{ - Stage: pointer.String(secretsencrypt.EncryptionPrepare), + Stage: ptr.To(secretsencrypt.EncryptionPrepare), Force: cmds.ServerConfig.EncryptForce, }) if err != nil { @@ -177,7 +177,7 @@ func Rotate(app *cli.Context) error { return err } b, err := json.Marshal(server.EncryptionRequest{ - Stage: pointer.String(secretsencrypt.EncryptionRotate), + Stage: ptr.To(secretsencrypt.EncryptionRotate), Force: cmds.ServerConfig.EncryptForce, }) if err != nil { @@ -199,7 +199,7 @@ func Reencrypt(app *cli.Context) error { return err } b, err := json.Marshal(server.EncryptionRequest{ - Stage: pointer.String(secretsencrypt.EncryptionReencryptActive), + Stage: ptr.To(secretsencrypt.EncryptionReencryptActive), Force: cmds.ServerConfig.EncryptForce, Skip: cmds.ServerConfig.EncryptSkip, }) @@ -222,7 +222,7 @@ func RotateKeys(app *cli.Context) error { return err } b, err := json.Marshal(server.EncryptionRequest{ - Stage: pointer.String(secretsencrypt.EncryptionRotateKeys), + Stage: ptr.To(secretsencrypt.EncryptionRotateKeys), }) if err != nil { return err diff --git a/pkg/cli/token/token.go b/pkg/cli/token/token.go index c8d7d2ce98..7af7cee82c 100644 --- a/pkg/cli/token/token.go +++ b/pkg/cli/token/token.go @@ -27,7 +27,7 @@ import ( "k8s.io/client-go/tools/clientcmd" bootstrapapi "k8s.io/cluster-bootstrap/token/api" bootstraputil "k8s.io/cluster-bootstrap/token/util" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) func Create(app *cli.Context) error { @@ -155,7 +155,7 @@ func Rotate(app *cli.Context) error { return err } b, err := json.Marshal(server.TokenRotateRequest{ - NewToken: pointer.String(cmds.TokenConfig.NewToken), + NewToken: ptr.To(cmds.TokenConfig.NewToken), }) if err != nil { return err diff --git a/pkg/cloudprovider/servicelb.go b/pkg/cloudprovider/servicelb.go index e128e985b0..fa2e3d4ccd 100644 --- a/pkg/cloudprovider/servicelb.go +++ b/pkg/cloudprovider/servicelb.go @@ -30,7 +30,7 @@ import ( servicehelper "k8s.io/cloud-provider/service/helpers" "k8s.io/kubernetes/pkg/features" utilsnet "k8s.io/utils/net" - utilpointer "k8s.io/utils/pointer" + utilsptr "k8s.io/utils/ptr" ) var ( @@ -488,7 +488,7 @@ func (k *k3s) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) { }, Spec: core.PodSpec{ ServiceAccountName: "svclb", - AutomountServiceAccountToken: utilpointer.Bool(false), + AutomountServiceAccountToken: utilsptr.To(false), SecurityContext: &core.PodSecurityContext{ Sysctls: sysctls, }, diff --git a/pkg/etcd/snapshot.go b/pkg/etcd/snapshot.go index 19d18a8245..899ffe20c0 100644 --- a/pkg/etcd/snapshot.go +++ b/pkg/etcd/snapshot.go @@ -42,7 +42,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/util/retry" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) const ( @@ -1074,7 +1074,7 @@ func (sf *snapshotFile) toETCDSnapshotFile(esf *apisv1.ETCDSnapshotFile) { esf.Spec.SnapshotName = sf.Name esf.Spec.Location = sf.Location esf.Status.CreationTime = sf.CreatedAt - esf.Status.ReadyToUse = pointer.Bool(sf.Status == successfulSnapshotStatus) + esf.Status.ReadyToUse = ptr.To(sf.Status == successfulSnapshotStatus) esf.Status.Size = resource.NewQuantity(sf.Size, resource.DecimalSI) if sf.nodeSource != "" { diff --git a/pkg/nodepassword/nodepassword.go b/pkg/nodepassword/nodepassword.go index defb5e8481..708c6c577c 100644 --- a/pkg/nodepassword/nodepassword.go +++ b/pkg/nodepassword/nodepassword.go @@ -15,7 +15,7 @@ import ( v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) var ( @@ -80,7 +80,7 @@ func Ensure(secretClient coreclient.SecretController, nodeName, pass string) err Name: getSecretName(nodeName), Namespace: metav1.NamespaceSystem, }, - Immutable: pointer.Bool(true), + Immutable: ptr.To(true), Data: map[string][]byte{"hash": []byte(hash)}, }) } diff --git a/pkg/server/secrets-encrypt.go b/pkg/server/secrets-encrypt.go index 0acda0702f..0ec8ac266a 100644 --- a/pkg/server/secrets-encrypt.go +++ b/pkg/server/secrets-encrypt.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/labels" apiserverconfigv1 "k8s.io/apiserver/pkg/apis/config/v1" "k8s.io/client-go/util/retry" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) const aescbcKeySize = 32 @@ -84,9 +84,9 @@ func encryptionStatus(server *config.Control) (EncryptionState, error) { return state, err } if providers[1].Identity != nil && providers[0].AESCBC != nil { - state.Enable = pointer.Bool(true) + state.Enable = ptr.To(true) } else if providers[0].Identity != nil && providers[1].AESCBC != nil || !server.EncryptSecrets { - state.Enable = pointer.Bool(false) + state.Enable = ptr.To(false) } if err := verifyEncryptionHashAnnotation(server.Runtime, server.Runtime.Core.Core(), ""); err != nil { diff --git a/pkg/spegel/spegel.go b/pkg/spegel/spegel.go index 8c42eea1e1..1fa589ec13 100644 --- a/pkg/spegel/spegel.go +++ b/pkg/spegel/spegel.go @@ -20,7 +20,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apiserver/pkg/authentication/authenticator" "k8s.io/apiserver/pkg/authentication/request/union" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "github.com/go-logr/logr" "github.com/go-logr/stdr" @@ -141,7 +141,7 @@ func (c *Config) Start(ctx context.Context, nodeConfig *config.Node) error { if logrus.IsLevelEnabled(logrus.DebugLevel) { level = ipfslog.LevelDebug stdlog := log.New(logrus.StandardLogger().Writer(), "spegel ", log.LstdFlags) - logger := stdr.NewWithOptions(stdlog, stdr.Options{Verbosity: pointer.Int(10)}) + logger := stdr.NewWithOptions(stdlog, stdr.Options{Verbosity: ptr.To(10)}) ctx = logr.NewContext(ctx, logger) } ipfslog.SetAllLoggers(level)