Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated usages of k8s.io/utils/pointer #4026

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ linters-settings:
Usages of the k8s cloud provider are only allowed from within the
k0s cloud provider package. This is to ensure that it's not
leaking global flags into k0s.
deprecations:
list-mode: lax
deny:
- pkg: k8s.io/utils/pointer
desc: Use k8s.io/utils/ptr.
golint:
min-confidence: 0
goheader:
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/sysinfo/probes/linux/cgroup_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"path/filepath"
"strings"

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

"github.com/cilium/ebpf/rlimit"
"github.com/containerd/cgroups/v3/cgroup2"
Expand Down Expand Up @@ -92,8 +92,8 @@ func attachDummyDeviceFilter(mountPoint string) (err error) {
insts, license, err := cgroup2.DeviceFilter([]specs.LinuxDeviceCgroup{{
Allow: true,
Type: "a",
Major: pointer.Int64(-1),
Minor: pointer.Int64(-1),
Major: ptr.To(int64(-1)),
Minor: ptr.To(int64(-1)),
Access: "rwm",
}})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions inttest/psp/psp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ func (s *PSPSuite) TestK0sGetsUp() {
Name: "pause",
Image: "registry.k8s.io/pause",
SecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(0),
RunAsUser: ptr.To(int64(0)),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/k0s/v1beta1/nllb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

// NodeLocalLoadBalancing defines the configuration options related to k0s's
Expand Down Expand Up @@ -180,7 +180,7 @@ func (p *EnvoyProxy) setDefaults() {
p.APIServerBindPort = 7443
}
if p.KonnectivityServerBindPort == nil {
p.KonnectivityServerBindPort = pointer.Int32(7132)
p.KonnectivityServerBindPort = ptr.To(int32(7132))
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/component/controller/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/sirupsen/logrus"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/k0sproject/k0s/internal/pkg/dir"
"github.com/k0sproject/k0s/internal/pkg/templatewriter"
Expand Down Expand Up @@ -397,7 +397,7 @@ func (c *CoreDNS) getConfig(ctx context.Context, clusterConfig *v1beta1.ClusterC
// to 7 replicas, it would be the same as the default, and for
// deployments with 8 or more replicas, this would artificially
// constrain the rolling update speed.
config.MaxUnavailableReplicas = pointer.Uint(1)
config.MaxUnavailableReplicas = ptr.To(uint(1))

}

Expand Down
10 changes: 5 additions & 5 deletions pkg/component/controller/workerconfig/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/wait"
kubeletv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/sirupsen/logrus"
"go.uber.org/multierr"
Expand Down Expand Up @@ -510,11 +510,11 @@ func (r *Reconciler) buildConfigMaps(snapshot *snapshot) ([]*corev1.ConfigMap, e
workerProfiles := make(map[string]*workerconfig.Profile)

workerProfile := r.buildProfile(snapshot)
workerProfile.KubeletConfiguration.CgroupsPerQOS = pointer.Bool(true)
workerProfile.KubeletConfiguration.CgroupsPerQOS = ptr.To(true)
workerProfiles["default"] = workerProfile

workerProfile = r.buildProfile(snapshot)
workerProfile.KubeletConfiguration.CgroupsPerQOS = pointer.Bool(false)
workerProfile.KubeletConfiguration.CgroupsPerQOS = ptr.To(false)
workerProfiles["default-windows"] = workerProfile

for _, profile := range snapshot.profiles {
Expand Down Expand Up @@ -605,10 +605,10 @@ func (r *Reconciler) buildProfile(snapshot *snapshot) *workerconfig.Profile {
ClusterDomain: r.clusterDomain,
TLSMinVersion: "VersionTLS12",
TLSCipherSuites: cipherSuites,
FailSwapOn: pointer.Bool(false),
FailSwapOn: ptr.To(false),
RotateCertificates: true,
ServerTLSBootstrap: true,
EventRecordQPS: pointer.Int32(0),
EventRecordQPS: ptr.To(int32(0)),
},
PauseImage: snapshot.pauseImage.DeepCopy(),
NodeLocalLoadBalancing: snapshot.nodeLocalLoadBalancing.DeepCopy(),
Expand Down
12 changes: 6 additions & 6 deletions pkg/component/controller/workerconfig/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

k8stesting "k8s.io/client-go/testing"
kubeletv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
Expand Down Expand Up @@ -374,17 +374,17 @@ func TestReconciler_ResourceGeneration(t *testing.T) {

configMaps := map[string]func(t *testing.T, expected *kubeletConfig){
"worker-config-default-1.29": func(t *testing.T, expected *kubeletConfig) {
expected.CgroupsPerQOS = pointer.Bool(true)
expected.CgroupsPerQOS = ptr.To(true)
expected.FeatureGates = map[string]bool{"kubelet-feature": true}
},

"worker-config-default-windows-1.29": func(t *testing.T, expected *kubeletConfig) {
expected.CgroupsPerQOS = pointer.Bool(false)
expected.CgroupsPerQOS = ptr.To(false)
expected.FeatureGates = map[string]bool{"kubelet-feature": true}
},

"worker-config-profile_XXX-1.29": func(t *testing.T, expected *kubeletConfig) {
expected.Authentication.Anonymous.Enabled = pointer.Bool(true)
expected.Authentication.Anonymous.Enabled = ptr.To(true)
expected.FeatureGates = map[string]bool{"kubelet-feature": true}
},

Expand Down Expand Up @@ -747,8 +747,8 @@ func makeKubeletConfig(t *testing.T, mods ...func(*kubeletConfig)) string {
},
ClusterDNS: []string{"99.99.99.10"},
ClusterDomain: "test.local",
EventRecordQPS: pointer.Int32(0),
FailSwapOn: pointer.Bool(false),
EventRecordQPS: ptr.To(int32(0)),
FailSwapOn: ptr.To(false),
RotateCertificates: true,
ServerTLSBootstrap: true,
TLSMinVersion: "VersionTLS12",
Expand Down
4 changes: 2 additions & 2 deletions pkg/component/worker/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
logsv1 "k8s.io/component-base/logs/api/v1"
kubeletv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -151,7 +151,7 @@ var roundtripTests = []roundtripTest{
},
ImagePullPolicy: corev1.PullAlways,
APIServerBindPort: 4711,
KonnectivityServerBindPort: pointer.Int32(1337),
KonnectivityServerBindPort: ptr.To(int32(1337)),
},
},
Konnectivity: Konnectivity{AgentPort: 1337},
Expand Down
6 changes: 3 additions & 3 deletions pkg/component/worker/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/validation"
kubeletv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/sirupsen/logrus"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -236,8 +236,8 @@ func (k *Kubelet) prepareLocalKubeletConfig(kubeletConfigData kubeletConfig) (st
preparedConfig.VolumePluginDir = kubeletConfigData.VolumePluginDir // k.K0sVars.KubeletVolumePluginDir
preparedConfig.KubeReservedCgroup = kubeletConfigData.KubeReservedCgroup
preparedConfig.KubeletCgroups = kubeletConfigData.KubeletCgroups
preparedConfig.ResolverConfig = pointer.String(kubeletConfigData.ResolvConf)
preparedConfig.CgroupsPerQOS = pointer.Bool(kubeletConfigData.CgroupsPerQOS)
preparedConfig.ResolverConfig = ptr.To(kubeletConfigData.ResolvConf)
preparedConfig.CgroupsPerQOS = ptr.To(kubeletConfigData.CgroupsPerQOS)
preparedConfig.StaticPodURL = kubeletConfigData.StaticPodURL

if k.CRISocket == "" && runtime.GOOS != "windows" {
Expand Down
12 changes: 6 additions & 6 deletions pkg/component/worker/nllb/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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"

"github.com/sirupsen/logrus"
"go.uber.org/multierr"
Expand Down Expand Up @@ -276,17 +276,17 @@ func makePodManifest(params *envoyParams, podParams *envoyPodParams) corev1.Pod
Spec: corev1.PodSpec{
HostNetwork: true,
SecurityContext: &corev1.PodSecurityContext{
RunAsNonRoot: pointer.Bool(true),
RunAsNonRoot: ptr.To(true),
},
Containers: []corev1.Container{{
Name: "nllb",
Image: podParams.image.URI(),
ImagePullPolicy: podParams.pullPolicy,
Ports: ports,
SecurityContext: &corev1.SecurityContext{
ReadOnlyRootFilesystem: pointer.Bool(true),
Privileged: pointer.Bool(false),
AllowPrivilegeEscalation: pointer.Bool(false),
ReadOnlyRootFilesystem: ptr.To(true),
Privileged: ptr.To(false),
AllowPrivilegeEscalation: ptr.To(false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
Expand All @@ -312,7 +312,7 @@ func makePodManifest(params *envoyParams, podParams *envoyPodParams) corev1.Pod
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: params.configDir,
Type: (*corev1.HostPathType)(pointer.String(string(corev1.HostPathDirectory))),
Type: (*corev1.HostPathType)(ptr.To(string(corev1.HostPathDirectory))),
},
}},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubernetes/watch/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

type VersionedResource interface {
Expand Down Expand Up @@ -259,7 +259,7 @@ func (w *Watcher[T]) list(ctx context.Context, condition Condition[T]) (*startWa
resourceVersion, items, err := w.List(ctx, metav1.ListOptions{
FieldSelector: w.fieldSelector,
LabelSelector: w.labelSelector,
TimeoutSeconds: pointer.Int64(maxListDurationSecs),
TimeoutSeconds: ptr.To(int64(maxListDurationSecs)),
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -289,7 +289,7 @@ func (w *Watcher[T]) watch(ctx context.Context, resourceVersion string, conditio
AllowWatchBookmarks: true,
FieldSelector: w.fieldSelector,
LabelSelector: w.labelSelector,
TimeoutSeconds: pointer.Int64(maxWatchDurationSecs),
TimeoutSeconds: ptr.To(int64(maxWatchDurationSecs)),
})
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubernetes/watch/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
apiwatch "k8s.io/apimachinery/pkg/watch"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestWatcher(t *testing.T) {
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestWatcher(t *testing.T) {
provider.watch = func(opts metav1.ListOptions) error {
assert.Equal(t, t.Name(), opts.ResourceVersion)
assert.True(t, opts.AllowWatchBookmarks)
assert.Equal(t, opts.TimeoutSeconds, pointer.Int64(120))
assert.Equal(t, opts.TimeoutSeconds, ptr.To(int64(120)))

provider.ch = openEventChanWith(
apiwatch.Event{
Expand Down
6 changes: 3 additions & 3 deletions pkg/leaderelection/lease_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"k8s.io/client-go/kubernetes/fake"
fakecoordinationv1 "k8s.io/client-go/kubernetes/typed/coordination/v1/fake"
k8stesting "k8s.io/client-go/testing"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestLeasePoolWatcherTriggersOnLeaseAcquisition(t *testing.T) {
Expand Down Expand Up @@ -176,10 +176,10 @@ func TestSecondWatcherAcquiresReleasedLease(t *testing.T) {
Name: "test",
},
Spec: coordinationv1.LeaseSpec{
HolderIdentity: pointer.String("pool1"),
HolderIdentity: ptr.To("pool1"),
AcquireTime: &now,
RenewTime: &now,
LeaseDurationSeconds: pointer.Int32(60 * 60), // block lease for a very long time
LeaseDurationSeconds: ptr.To(int32((1 * time.Hour).Seconds())), // block lease for a very long time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just doing ptr.To(int32(time.Hour.Seconds())) would be a bit cleaner. But it's certainly not worth a discussion.

},
}, metav1.CreateOptions{})
require.NoError(t, err)
Expand Down
Loading