Skip to content

Commit

Permalink
Switch to k8s.io/utils/ptr
Browse files Browse the repository at this point in the history
Replace "k8s.io/utils/pointer"
and "go.ytsaurus.tech/library/go/ptr"
with "k8s.io/utils/pt".
  • Loading branch information
koct9i committed Jul 2, 2024
1 parent 8afeb53 commit 372b614
Show file tree
Hide file tree
Showing 31 changed files with 150 additions and 138 deletions.
2 changes: 0 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ linters-settings:
alias: kerrors
- pkg: k8s.io/component-base/logs/api/v1
alias: logsv1
- pkg: k8s.io/utils/pointer
alias: ptr
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
Expand Down
4 changes: 2 additions & 2 deletions api/v1/ytsaurus_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/yaml"
ptr "k8s.io/utils/pointer" //nolint:staticcheck
"k8s.io/utils/ptr"

ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -107,7 +107,7 @@ func (r *Ytsaurus) validateHostAddresses(masterSpec MastersSpec, fieldPath *fiel
var allErrors field.ErrorList

hostAddressesFieldPath := fieldPath.Child("hostAddresses")
if !ptr.BoolDeref(masterSpec.HostNetwork, r.Spec.HostNetwork) && len(masterSpec.HostAddresses) != 0 {
if !ptr.Deref(masterSpec.HostNetwork, r.Spec.HostNetwork) && len(masterSpec.HostAddresses) != 0 {
allErrors = append(
allErrors,
field.Required(
Expand Down
7 changes: 4 additions & 3 deletions controllers/remoteexecnodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ptr "k8s.io/utils/pointer" //nolint:staticcheck
"k8s.io/utils/ptr"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -202,7 +203,7 @@ func TestRemoteExecNodesStatusRunningWithPods(t *testing.T) {

nodes := buildRemoteExecNodes(h, remoteYtsaurusName, remoteExecNodesName)
nodes.Spec.InstanceSpec.InstanceCount = 1
nodes.Spec.InstanceSpec.MinReadyInstanceCount = ptr.Int(1)
nodes.Spec.InstanceSpec.MinReadyInstanceCount = ptr.To(1)
testutil.DeployObject(h, &nodes)
waitRemoteExecNodesDeployed(h, remoteExecNodesName)

Expand Down Expand Up @@ -256,7 +257,7 @@ func buildRemoteExecNodes(h *testutil.TestHelper, remoteYtsaurusName, remoteExec
}),
ExecNodesSpec: ytv1.ExecNodesSpec{
InstanceSpec: ytv1.InstanceSpec{
Image: ptr.String(testYtsaurusImage),
Image: ptr.To(testYtsaurusImage),
Locations: []ytv1.LocationSpec{
{
LocationType: ytv1.LocationTypeChunkCache,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/pmezard/go-difflib v1.0.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.25.0
go.ytsaurus.tech/library/go/ptr v0.0.1
go.ytsaurus.tech/yt/go v0.0.16
k8s.io/api v0.28.3
k8s.io/apimachinery v0.30.2
Expand Down Expand Up @@ -71,6 +70,7 @@ require (
go.ytsaurus.tech/library/go/blockcodecs v0.0.2 // indirect
go.ytsaurus.tech/library/go/core/log v0.0.3 // indirect
go.ytsaurus.tech/library/go/core/xerrors v0.0.3 // indirect
go.ytsaurus.tech/library/go/ptr v0.0.1 // indirect
go.ytsaurus.tech/library/go/x/xreflect v0.0.2 // indirect
go.ytsaurus.tech/library/go/x/xruntime v0.0.3 // indirect
golang.org/x/crypto v0.21.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/controller_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package components
import (
"context"

"go.ytsaurus.tech/library/go/ptr"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
"github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy"
Expand All @@ -30,7 +30,7 @@ func NewControllerAgent(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus,
}

if resource.Spec.ControllerAgents.InstanceSpec.MonitoringPort == nil {
resource.Spec.ControllerAgents.InstanceSpec.MonitoringPort = ptr.Int32(consts.ControllerAgentMonitoringPort)
resource.Spec.ControllerAgents.InstanceSpec.MonitoringPort = ptr.To(int32(consts.ControllerAgentMonitoringPort))
}

srv := newServer(
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/data_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package components
import (
"context"

"go.ytsaurus.tech/library/go/ptr"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
"github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy"
Expand Down Expand Up @@ -35,7 +35,7 @@ func NewDataNode(
}

if spec.InstanceSpec.MonitoringPort == nil {
spec.InstanceSpec.MonitoringPort = ptr.Int32(consts.DataNodeMonitoringPort)
spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.DataNodeMonitoringPort))
}

srv := newServer(
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package components
import (
"context"

"go.ytsaurus.tech/library/go/ptr"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
"github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy"
Expand All @@ -29,7 +29,7 @@ func NewDiscovery(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Disco
}

if resource.Spec.Discovery.InstanceSpec.MonitoringPort == nil {
resource.Spec.Discovery.InstanceSpec.MonitoringPort = ptr.Int32(consts.DiscoveryMonitoringPort)
resource.Spec.Discovery.InstanceSpec.MonitoringPort = ptr.To(int32(consts.DiscoveryMonitoringPort))
}

srv := newServer(
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/exec_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package components
import (
"context"

"go.ytsaurus.tech/library/go/ptr"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
"github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy"
Expand Down Expand Up @@ -34,7 +34,7 @@ func NewExecNode(
}

if spec.InstanceSpec.MonitoringPort == nil {
spec.InstanceSpec.MonitoringPort = ptr.Int32(consts.ExecNodeMonitoringPort)
spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.ExecNodeMonitoringPort))
}

srv := newServer(
Expand Down
6 changes: 3 additions & 3 deletions pkg/components/exec_node_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path"

corev1 "k8s.io/api/core/v1"
ptr "k8s.io/utils/pointer" //nolint:staticcheck
"k8s.io/utils/ptr"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"

Expand Down Expand Up @@ -61,7 +61,7 @@ func (n *baseExecNode) doBuildBase() error {
ct.SecurityContext = &corev1.SecurityContext{}
}
if ct.SecurityContext.Privileged == nil {
ct.SecurityContext.Privileged = ptr.Bool(n.spec.Privileged)
ct.SecurityContext.Privileged = ptr.To(n.spec.Privileged)
}
}

Expand Down Expand Up @@ -146,7 +146,7 @@ func (n *baseExecNode) doBuildCRISidecar(envSpec *ytv1.JobEnvironmentSpec, podSp
Args: []string{"--config", configPath},
VolumeMounts: createVolumeMounts(n.spec.VolumeMounts),
SecurityContext: &corev1.SecurityContext{
Privileged: ptr.Bool(true),
Privileged: ptr.To(true),
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/components/exec_node_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package components
import (
"context"

"go.ytsaurus.tech/library/go/ptr"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
"github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy"
Expand Down Expand Up @@ -33,7 +33,7 @@ func NewRemoteExecNodes(
}

if spec.InstanceSpec.MonitoringPort == nil {
spec.InstanceSpec.MonitoringPort = ptr.Int32(consts.ExecNodeMonitoringPort)
spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.ExecNodeMonitoringPort))
}

srv := newServerConfigured(
Expand Down
9 changes: 5 additions & 4 deletions pkg/components/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

"k8s.io/apimachinery/pkg/util/yaml"

"go.ytsaurus.tech/library/go/ptr"
"k8s.io/utils/ptr"

"go.ytsaurus.tech/yt/go/ypath"
"go.ytsaurus.tech/yt/go/yson"
"go.ytsaurus.tech/yt/go/yt"
Expand Down Expand Up @@ -132,14 +133,14 @@ func handleUpdatingClusterState(
if !dry {
err = removePods(ctx, server, cmpBase)
}
return ptr.T(WaitingStatus(SyncStatusUpdating, "pods removal")), err
return ptr.To(WaitingStatus(SyncStatusUpdating, "pods removal")), err
}

if ytsaurus.GetUpdateState() != ytv1.UpdateStateWaitingForPodsCreation {
return ptr.T(NewComponentStatus(SyncStatusReady, "Nothing to do now")), err
return ptr.To(NewComponentStatus(SyncStatusReady, "Nothing to do now")), err
}
} else {
return ptr.T(NewComponentStatus(SyncStatusReady, "Not updating component")), err
return ptr.To(NewComponentStatus(SyncStatusReady, "Not updating component")), err
}
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/components/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package components
import (
"context"

"go.ytsaurus.tech/library/go/ptr"
"k8s.io/utils/ptr"

corev1 "k8s.io/api/core/v1"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
Expand Down Expand Up @@ -40,7 +41,7 @@ func NewHTTPProxy(
}

if spec.InstanceSpec.MonitoringPort == nil {
spec.InstanceSpec.MonitoringPort = ptr.Int32(consts.HTTPProxyMonitoringPort)
spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.HTTPProxyMonitoringPort))
}

srv := newServer(
Expand Down
11 changes: 6 additions & 5 deletions pkg/components/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"fmt"
"strings"

"go.ytsaurus.tech/library/go/ptr"
"k8s.io/utils/ptr"

"go.ytsaurus.tech/yt/go/yson"
"go.ytsaurus.tech/yt/go/yt"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -43,7 +44,7 @@ func NewMaster(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Master {
}

if resource.Spec.PrimaryMasters.InstanceSpec.MonitoringPort == nil {
resource.Spec.PrimaryMasters.InstanceSpec.MonitoringPort = ptr.Int32(consts.MasterMonitoringPort)
resource.Spec.PrimaryMasters.InstanceSpec.MonitoringPort = ptr.To(int32(consts.MasterMonitoringPort))
}

srv := newServer(
Expand Down Expand Up @@ -357,14 +358,14 @@ func (m *Master) exitReadOnly(ctx context.Context, dry bool) (*ComponentStatus,
if !m.ytsaurus.IsUpdateStatusConditionTrue(consts.ConditionMasterExitReadOnlyPrepared) {
if !m.exitReadOnlyJob.isRestartPrepared() {
if err := m.exitReadOnlyJob.prepareRestart(ctx, dry); err != nil {
return ptr.T(SimpleStatus(SyncStatusUpdating)), err
return ptr.To(SimpleStatus(SyncStatusUpdating)), err
}
}

if !dry {
m.setMasterReadOnlyExitPrepared(ctx, metav1.ConditionTrue)
}
return ptr.T(SimpleStatus(SyncStatusUpdating)), nil
return ptr.To(SimpleStatus(SyncStatusUpdating)), nil
}

if !m.exitReadOnlyJob.IsCompleted() {
Expand All @@ -384,7 +385,7 @@ func (m *Master) exitReadOnly(ctx context.Context, dry bool) (*ComponentStatus,
})
m.setMasterReadOnlyExitPrepared(ctx, metav1.ConditionFalse)
}
return ptr.T(SimpleStatus(SyncStatusUpdating)), nil
return ptr.To(SimpleStatus(SyncStatusUpdating)), nil
}

func (m *Master) setMasterReadOnlyExitPrepared(ctx context.Context, status metav1.ConditionStatus) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/components/master_caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package components
import (
"context"

"go.ytsaurus.tech/library/go/ptr"
"k8s.io/utils/ptr"

corev1 "k8s.io/api/core/v1"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
Expand All @@ -30,7 +31,7 @@ func NewMasterCache(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Mas
}

if resource.Spec.MasterCaches.InstanceSpec.MonitoringPort == nil {
resource.Spec.MasterCaches.InstanceSpec.MonitoringPort = ptr.Int32(consts.MasterCachesMonitoringPort)
resource.Spec.MasterCaches.InstanceSpec.MonitoringPort = ptr.To(int32(consts.MasterCachesMonitoringPort))
}

srv := newServer(
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/microservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package components
import (
"context"

ptr "k8s.io/utils/pointer" //nolint:staticcheck
"k8s.io/utils/ptr"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"

Expand Down Expand Up @@ -185,7 +185,7 @@ func (m *microserviceImpl) podsImageCorrespondsToSpec() bool {
func (m *microserviceImpl) removePods(ctx context.Context) error {
m.builtDeployment = m.deployment.Build()
m.builtDeployment.Spec = m.deployment.OldObject().(*appsv1.Deployment).Spec
m.builtDeployment.Spec.Replicas = ptr.Int32(0)
m.builtDeployment.Spec.Replicas = ptr.To(int32(0))
return m.Sync(ctx)
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/components/query_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"fmt"
"strings"

"go.ytsaurus.tech/library/go/ptr"
"k8s.io/utils/ptr"

"go.ytsaurus.tech/yt/go/ypath"
"go.ytsaurus.tech/yt/go/yt"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -47,7 +48,7 @@ func NewQueryTracker(
}

if resource.Spec.QueryTrackers.InstanceSpec.MonitoringPort == nil {
resource.Spec.QueryTrackers.InstanceSpec.MonitoringPort = ptr.Int32(consts.QueryTrackerMonitoringPort)
resource.Spec.QueryTrackers.InstanceSpec.MonitoringPort = ptr.To(int32(consts.QueryTrackerMonitoringPort))
}

srv := newServer(
Expand Down Expand Up @@ -438,20 +439,20 @@ func (qt *QueryTracker) updateQTState(ctx context.Context, dry bool) (*Component
switch qt.ytsaurus.GetUpdateState() {
case ytv1.UpdateStateWaitingForQTStateUpdatingPrepare:
if !qt.initQTState.isRestartPrepared() {
return ptr.T(SimpleStatus(SyncStatusUpdating)), qt.initQTState.prepareRestart(ctx, dry)
return ptr.To(SimpleStatus(SyncStatusUpdating)), qt.initQTState.prepareRestart(ctx, dry)
}
if !dry {
qt.setConditionQTStatePreparedForUpdating(ctx)
}
return ptr.T(SimpleStatus(SyncStatusUpdating)), err
return ptr.To(SimpleStatus(SyncStatusUpdating)), err
case ytv1.UpdateStateWaitingForQTStateUpdate:
if !qt.initQTState.isRestartCompleted() {
return nil, nil
}
if !dry {
qt.setConditionQTStateUpdated(ctx)
}
return ptr.T(SimpleStatus(SyncStatusUpdating)), err
return ptr.To(SimpleStatus(SyncStatusUpdating)), err
default:
return nil, nil
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/components/queue_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"fmt"
"strings"

"go.ytsaurus.tech/library/go/ptr"
"k8s.io/utils/ptr"

"go.ytsaurus.tech/yt/go/ypath"
"go.ytsaurus.tech/yt/go/yt"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -49,7 +50,7 @@ func NewQueueAgent(
}

if resource.Spec.QueueAgents.InstanceSpec.MonitoringPort == nil {
resource.Spec.QueueAgents.InstanceSpec.MonitoringPort = ptr.Int32(consts.QueueAgentMonitoringPort)
resource.Spec.QueueAgents.InstanceSpec.MonitoringPort = ptr.To(int32(consts.QueueAgentMonitoringPort))
}

srv := newServer(
Expand Down
Loading

0 comments on commit 372b614

Please sign in to comment.