Skip to content

Commit

Permalink
Merge pull request #590 from relu/replace-deprecated-pointer-util
Browse files Browse the repository at this point in the history
Replace deprecated package k8s.io/utils/pointer
  • Loading branch information
mattlord authored Jul 25, 2024
2 parents 0a3e8da + 2e8ed0f commit a451314
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 52 deletions.
8 changes: 4 additions & 4 deletions pkg/apis/planetscale/v2/etcdlockserver_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/planetscale/v2/vitesscell_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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{
Expand Down
22 changes: 11 additions & 11 deletions pkg/apis/planetscale/v2/vitesscluster_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/planetscale/v2/vitessshard_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
}
4 changes: 2 additions & 2 deletions pkg/operator/contenthash/tolerations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/operator/etcd/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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 != "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/secrets/volume_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pkg/operator/vtadmin/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/operator/vtctld/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/operator/vtgate/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/operator/vtorc/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/vttablet/mysqlctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions pkg/operator/vttablet/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit a451314

Please sign in to comment.