From 2e8ed0f252229b65185e838b9b877aa634b09f36 Mon Sep 17 00:00:00 2001 From: Aurel Canciu Date: Thu, 25 Jul 2024 13:53:52 +0200 Subject: [PATCH] Replace deprecated package k8s.io/utils/pointer Using k8s.io/utils/ptr as advised instead. Signed-off-by: Aurel Canciu --- .../planetscale/v2/etcdlockserver_defaults.go | 8 +++---- .../planetscale/v2/vitesscell_defaults.go | 4 ++-- .../planetscale/v2/vitesscluster_defaults.go | 22 +++++++++---------- .../planetscale/v2/vitessshard_defaults.go | 8 +++---- pkg/operator/contenthash/tolerations_test.go | 4 ++-- pkg/operator/etcd/pod.go | 6 ++--- pkg/operator/secrets/volume_mount.go | 4 ++-- pkg/operator/vtadmin/deployment.go | 8 +++---- pkg/operator/vtctld/deployment.go | 8 +++---- pkg/operator/vtgate/deployment.go | 8 +++---- pkg/operator/vtorc/deployment.go | 6 ++--- pkg/operator/vttablet/mysqlctld.go | 4 ++-- pkg/operator/vttablet/pod.go | 8 +++---- pkg/operator/vttablet/vtbackup_pod.go | 6 ++--- 14 files changed, 52 insertions(+), 52 deletions(-) diff --git a/pkg/apis/planetscale/v2/etcdlockserver_defaults.go b/pkg/apis/planetscale/v2/etcdlockserver_defaults.go index b86a9946..0489cc19 100644 --- a/pkg/apis/planetscale/v2/etcdlockserver_defaults.go +++ b/pkg/apis/planetscale/v2/etcdlockserver_defaults.go @@ -19,7 +19,7 @@ package v2 import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) func DefaultEtcdLockserver(ls *EtcdLockserver) { @@ -57,13 +57,13 @@ func DefaultEtcdLockserverTemplate(ls *EtcdLockserverTemplate) { } } if ls.CreatePDB == nil { - ls.CreatePDB = pointer.BoolPtr(defaultEtcdCreatePDB) + ls.CreatePDB = ptr.To(defaultEtcdCreatePDB) } if ls.CreateClientService == nil { - ls.CreateClientService = pointer.BoolPtr(defaultEtcdCreateClientService) + ls.CreateClientService = ptr.To(defaultEtcdCreateClientService) } if ls.CreatePeerService == nil { - ls.CreatePeerService = pointer.BoolPtr(defaultEtcdCreatePeerService) + ls.CreatePeerService = ptr.To(defaultEtcdCreatePeerService) } DefaultServiceOverrides(&ls.ClientService) DefaultServiceOverrides(&ls.PeerService) diff --git a/pkg/apis/planetscale/v2/vitesscell_defaults.go b/pkg/apis/planetscale/v2/vitesscell_defaults.go index 4af5574e..01b25390 100644 --- a/pkg/apis/planetscale/v2/vitesscell_defaults.go +++ b/pkg/apis/planetscale/v2/vitesscell_defaults.go @@ -19,7 +19,7 @@ package v2 import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // DefaultVitessCell fills in API-level defaults for a VitessCell object. @@ -43,7 +43,7 @@ func DefaultLocalLockserver(ls *LockserverSpec) { func DefaultVitessGateway(gtway *VitessCellGatewaySpec) { if gtway.Replicas == nil { - gtway.Replicas = pointer.Int32Ptr(defaultVtgateReplicas) + gtway.Replicas = ptr.To(int32(defaultVtgateReplicas)) } if len(gtway.Resources.Requests) == 0 { gtway.Resources.Requests = corev1.ResourceList{ diff --git a/pkg/apis/planetscale/v2/vitesscluster_defaults.go b/pkg/apis/planetscale/v2/vitesscluster_defaults.go index dd03e753..6a281fa3 100644 --- a/pkg/apis/planetscale/v2/vitesscluster_defaults.go +++ b/pkg/apis/planetscale/v2/vitesscluster_defaults.go @@ -19,7 +19,7 @@ package v2 import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // DefaultVitessCluster fills in default values for unspecified fields. @@ -84,7 +84,7 @@ func DefaultVitessDashboard(dashboard **VitessDashboardSpec) { *dashboard = &VitessDashboardSpec{} } if (*dashboard).Replicas == nil { - (*dashboard).Replicas = pointer.Int32Ptr(defaultVtctldReplicas) + (*dashboard).Replicas = ptr.To(int32(defaultVtctldReplicas)) } if len((*dashboard).Resources.Requests) == 0 { (*dashboard).Resources.Requests = corev1.ResourceList{ @@ -106,7 +106,7 @@ func DefaultVtAdmin(dashboard **VtAdminSpec) { return } if (*dashboard).Replicas == nil { - (*dashboard).Replicas = pointer.Int32Ptr(defaultVtadminReplicas) + (*dashboard).Replicas = ptr.To(int32(defaultVtadminReplicas)) } if len((*dashboard).WebResources.Requests) == 0 { (*dashboard).WebResources.Requests = corev1.ResourceList{ @@ -186,30 +186,30 @@ func DefaultTopoReconcileConfig(confPtr **TopoReconcileConfig) { // Defaulting registration code. if conf.RegisterCells == nil { - conf.RegisterCells = pointer.BoolPtr(true) + conf.RegisterCells = ptr.To(true) } if conf.RegisterCellsAliases == nil { - conf.RegisterCellsAliases = pointer.BoolPtr(true) + conf.RegisterCellsAliases = ptr.To(true) } // Defaulting pruning code. if conf.PruneCells == nil { - conf.PruneCells = pointer.BoolPtr(true) + conf.PruneCells = ptr.To(true) } if conf.PruneKeyspaces == nil { - conf.PruneKeyspaces = pointer.BoolPtr(true) + conf.PruneKeyspaces = ptr.To(true) } if conf.PruneShards == nil { - conf.PruneShards = pointer.BoolPtr(true) + conf.PruneShards = ptr.To(true) } if conf.PruneShardCells == nil { - conf.PruneShardCells = pointer.BoolPtr(true) + conf.PruneShardCells = ptr.To(true) } if conf.PruneTablets == nil { - conf.PruneTablets = pointer.BoolPtr(true) + conf.PruneTablets = ptr.To(true) } if conf.PruneSrvKeyspaces == nil { - conf.PruneSrvKeyspaces = pointer.BoolPtr(true) + conf.PruneSrvKeyspaces = ptr.To(true) } } diff --git a/pkg/apis/planetscale/v2/vitessshard_defaults.go b/pkg/apis/planetscale/v2/vitessshard_defaults.go index b19c5a72..94f2e617 100644 --- a/pkg/apis/planetscale/v2/vitessshard_defaults.go +++ b/pkg/apis/planetscale/v2/vitessshard_defaults.go @@ -17,7 +17,7 @@ limitations under the License. package v2 import ( - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) // DefaultVitessShard fills in VitessShard defaults for unspecified fields. @@ -41,16 +41,16 @@ func DefaultVitessShardTemplate(shardTemplate *VitessShardTemplate) { func DefaultVitessReplicationSpec(replicationSpec *VitessReplicationSpec) { // Enable initialization of replication by default. if replicationSpec.InitializeMaster == nil { - replicationSpec.InitializeMaster = pointer.BoolPtr(true) + replicationSpec.InitializeMaster = ptr.To(true) } // Enable initialization of backup by default. if replicationSpec.InitializeBackup == nil { - replicationSpec.InitializeBackup = pointer.BoolPtr(true) + replicationSpec.InitializeBackup = ptr.To(true) } // Enable replication repair by default. if replicationSpec.RecoverRestartedMaster == nil { - replicationSpec.RecoverRestartedMaster = pointer.BoolPtr(true) + replicationSpec.RecoverRestartedMaster = ptr.To(true) } } diff --git a/pkg/operator/contenthash/tolerations_test.go b/pkg/operator/contenthash/tolerations_test.go index cbaa6267..e1089e6c 100644 --- a/pkg/operator/contenthash/tolerations_test.go +++ b/pkg/operator/contenthash/tolerations_test.go @@ -20,7 +20,7 @@ import ( "testing" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) func TestTolerationSecondsNil(t *testing.T) { @@ -29,7 +29,7 @@ func TestTolerationSecondsNil(t *testing.T) { {TolerationSeconds: nil}, }) zeroHash := Tolerations([]corev1.Toleration{ - {TolerationSeconds: pointer.Int64Ptr(0)}, + {TolerationSeconds: ptr.To(int64(0))}, }) if nilHash == zeroHash { t.Errorf("nilHash = zeroHash = %v; expected different values", nilHash) diff --git a/pkg/operator/etcd/pod.go b/pkg/operator/etcd/pod.go index bd349b86..657775db 100644 --- a/pkg/operator/etcd/pod.go +++ b/pkg/operator/etcd/pod.go @@ -22,7 +22,7 @@ import ( 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" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" @@ -161,7 +161,7 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { var securityContext *corev1.SecurityContext if planetscalev2.DefaultEtcdRunAsUser >= 0 { securityContext = &corev1.SecurityContext{ - RunAsUser: pointer.Int64Ptr(planetscalev2.DefaultEtcdRunAsUser), + RunAsUser: ptr.To(planetscalev2.DefaultEtcdRunAsUser), } } @@ -234,7 +234,7 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { if obj.Spec.SecurityContext == nil { obj.Spec.SecurityContext = &corev1.PodSecurityContext{} } - obj.Spec.SecurityContext.FSGroup = pointer.Int64Ptr(planetscalev2.DefaultEtcdFSGroup) + obj.Spec.SecurityContext.FSGroup = ptr.To(planetscalev2.DefaultEtcdFSGroup) } if planetscalev2.DefaultEtcdServiceAccount != "" { diff --git a/pkg/operator/secrets/volume_mount.go b/pkg/operator/secrets/volume_mount.go index 69de6822..ee98880b 100644 --- a/pkg/operator/secrets/volume_mount.go +++ b/pkg/operator/secrets/volume_mount.go @@ -20,7 +20,7 @@ import ( "path/filepath" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" ) @@ -89,7 +89,7 @@ func (v *VolumeMount) PodVolumes() []corev1.Volume { VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: v.Secret.Name, - DefaultMode: pointer.Int32Ptr(volumeMountMode), + DefaultMode: ptr.To(int32(volumeMountMode)), Items: []corev1.KeyToPath{ { Key: v.Secret.Key, diff --git a/pkg/operator/vtadmin/deployment.go b/pkg/operator/vtadmin/deployment.go index 8c169ada..76132da6 100644 --- a/pkg/operator/vtadmin/deployment.go +++ b/pkg/operator/vtadmin/deployment.go @@ -25,7 +25,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" @@ -135,7 +135,7 @@ func UpdateDeploymentImmediate(obj *appsv1.Deployment, spec *Spec) { update.Labels(&obj.Labels, spec.Labels) // Scaling up or down doesn't require a rolling update. - obj.Spec.Replicas = pointer.Int32Ptr(spec.Replicas) + obj.Spec.Replicas = ptr.To(spec.Replicas) } // UpdateDeployment updates the mutable parts of the vtadmin Deployment @@ -154,7 +154,7 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec) { obj.Spec.Template.Annotations = spec.Annotations // Deployment options. - obj.Spec.RevisionHistoryLimit = pointer.Int32Ptr(0) + obj.Spec.RevisionHistoryLimit = ptr.To(int32(0)) // Reset the list of volumes in the template so we remove old ones. obj.Spec.Template.Spec.Volumes = nil @@ -179,7 +179,7 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec) { securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = ptr.To(planetscalev2.DefaultVitessRunAsUser) } update.PodTemplateContainers(&obj.Spec.Template.Spec.InitContainers, spec.InitContainers) diff --git a/pkg/operator/vtctld/deployment.go b/pkg/operator/vtctld/deployment.go index 5901cf3e..43b628ff 100644 --- a/pkg/operator/vtctld/deployment.go +++ b/pkg/operator/vtctld/deployment.go @@ -23,7 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "planetscale.dev/vitess-operator/pkg/operator/mysql" "sigs.k8s.io/controller-runtime/pkg/client" @@ -100,7 +100,7 @@ func UpdateDeploymentImmediate(obj *appsv1.Deployment, spec *Spec) { update.Labels(&obj.Labels, spec.Labels) // Scaling up or down doesn't require a rolling update. - obj.Spec.Replicas = pointer.Int32Ptr(spec.Replicas) + obj.Spec.Replicas = ptr.To(spec.Replicas) } // UpdateDeployment updates the mutable parts of the vtctld Deployment @@ -119,7 +119,7 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec, mysqldImage string) { obj.Spec.Template.Annotations = spec.Annotations // Deployment options. - obj.Spec.RevisionHistoryLimit = pointer.Int32Ptr(0) + obj.Spec.RevisionHistoryLimit = ptr.To(int32(0)) // Reset the list of volumes in the template so we remove old ones. obj.Spec.Template.Spec.Volumes = nil @@ -153,7 +153,7 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec, mysqldImage string) { securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = ptr.To(planetscalev2.DefaultVitessRunAsUser) } update.PodTemplateContainers(&obj.Spec.Template.Spec.InitContainers, spec.InitContainers) diff --git a/pkg/operator/vtgate/deployment.go b/pkg/operator/vtgate/deployment.go index a2882881..04005061 100644 --- a/pkg/operator/vtgate/deployment.go +++ b/pkg/operator/vtgate/deployment.go @@ -23,7 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "planetscale.dev/vitess-operator/pkg/operator/mysql" "sigs.k8s.io/controller-runtime/pkg/client" @@ -121,8 +121,8 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec, mysqldImage string) { obj.Spec.Template.Annotations = spec.Annotations // Deployment options. - obj.Spec.Replicas = pointer.Int32Ptr(spec.Replicas) - obj.Spec.RevisionHistoryLimit = pointer.Int32Ptr(0) + obj.Spec.Replicas = ptr.To(spec.Replicas) + obj.Spec.RevisionHistoryLimit = ptr.To(int32(0)) // Reset the list of volumes in the template so we remove old ones. obj.Spec.Template.Spec.Volumes = nil @@ -169,7 +169,7 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec, mysqldImage string) { securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = ptr.To(planetscalev2.DefaultVitessRunAsUser) } // Start building the main Container to put in the Pod template. diff --git a/pkg/operator/vtorc/deployment.go b/pkg/operator/vtorc/deployment.go index 7bed1175..01332817 100644 --- a/pkg/operator/vtorc/deployment.go +++ b/pkg/operator/vtorc/deployment.go @@ -23,7 +23,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" @@ -115,7 +115,7 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec) { obj.Spec.Template.Annotations = spec.Annotations // Deployment options. - obj.Spec.RevisionHistoryLimit = pointer.Int32Ptr(0) + obj.Spec.RevisionHistoryLimit = ptr.To(int32(0)) // Reset the list of volumes in the template so we remove old ones. obj.Spec.Template.Spec.Volumes = nil @@ -140,7 +140,7 @@ func UpdateDeployment(obj *appsv1.Deployment, spec *Spec) { securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = ptr.To(planetscalev2.DefaultVitessRunAsUser) } update.PodTemplateContainers(&obj.Spec.Template.Spec.InitContainers, spec.InitContainers) diff --git a/pkg/operator/vttablet/mysqlctld.go b/pkg/operator/vttablet/mysqlctld.go index 442aaf6d..2fe12f56 100644 --- a/pkg/operator/vttablet/mysqlctld.go +++ b/pkg/operator/vttablet/mysqlctld.go @@ -19,7 +19,7 @@ package vttablet import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" "planetscale.dev/vitess-operator/pkg/operator/lazy" @@ -68,7 +68,7 @@ func init() { securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = ptr.To(planetscalev2.DefaultVitessRunAsUser) } // Use an init container to copy only the files we need from the Vitess image. diff --git a/pkg/operator/vttablet/pod.go b/pkg/operator/vttablet/pod.go index 9dcc25f1..c07df5d9 100644 --- a/pkg/operator/vttablet/pod.go +++ b/pkg/operator/vttablet/pod.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "planetscale.dev/vitess-operator/pkg/operator/mysql" "sigs.k8s.io/controller-runtime/pkg/client" topodatapb "vitess.io/vitess/go/vt/proto/topodata" @@ -108,7 +108,7 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = ptr.To(planetscalev2.DefaultVitessRunAsUser) } vttabletLifecycle := &spec.Vttablet.Lifecycle @@ -315,13 +315,13 @@ func UpdatePod(obj *corev1.Pod, spec *Spec) { obj.Spec.SecurityContext = &corev1.PodSecurityContext{} } if planetscalev2.DefaultVitessFSGroup >= 0 { - obj.Spec.SecurityContext.FSGroup = pointer.Int64Ptr(planetscalev2.DefaultVitessFSGroup) + obj.Spec.SecurityContext.FSGroup = ptr.To(planetscalev2.DefaultVitessFSGroup) } if spec.Vttablet.TerminationGracePeriodSeconds != nil { obj.Spec.TerminationGracePeriodSeconds = spec.Vttablet.TerminationGracePeriodSeconds } else { - obj.Spec.TerminationGracePeriodSeconds = pointer.Int64Ptr(defaultTerminationGracePeriodSeconds) + obj.Spec.TerminationGracePeriodSeconds = ptr.To(int64(defaultTerminationGracePeriodSeconds)) } // In both the case of the user injecting their own affinity and the default, we diff --git a/pkg/operator/vttablet/vtbackup_pod.go b/pkg/operator/vttablet/vtbackup_pod.go index 5823cdb1..813257f9 100644 --- a/pkg/operator/vttablet/vtbackup_pod.go +++ b/pkg/operator/vttablet/vtbackup_pod.go @@ -22,7 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "planetscale.dev/vitess-operator/pkg/operator/mysql" "sigs.k8s.io/controller-runtime/pkg/client" @@ -122,11 +122,11 @@ func NewBackupPod(key client.ObjectKey, backupSpec *BackupSpec, mysqldImage stri podSecurityContext := &corev1.PodSecurityContext{} if planetscalev2.DefaultVitessFSGroup >= 0 { - podSecurityContext.FSGroup = pointer.Int64Ptr(planetscalev2.DefaultVitessFSGroup) + podSecurityContext.FSGroup = ptr.To(planetscalev2.DefaultVitessFSGroup) } securityContext := &corev1.SecurityContext{} if planetscalev2.DefaultVitessRunAsUser >= 0 { - securityContext.RunAsUser = pointer.Int64Ptr(planetscalev2.DefaultVitessRunAsUser) + securityContext.RunAsUser = ptr.To(planetscalev2.DefaultVitessRunAsUser) } var containerResources corev1.ResourceRequirements