Skip to content

Commit

Permalink
fix: remove deprecated method
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Gupta <[email protected]>
  • Loading branch information
shubham-cmyk committed Mar 29, 2024
1 parent 6a53042 commit 6056ff0
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 146 deletions.
6 changes: 3 additions & 3 deletions api/v1beta2/rediscluster_default.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package v1beta2

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

// SetDefault sets default values for the RedisCluster object.
func (r *RedisCluster) SetDefault() {
if r.Spec.Port == nil {
r.Spec.Port = pointer.Int(6379)
r.Spec.Port = ptr.To(6379)
}
if r.Spec.RedisExporter != nil && r.Spec.RedisExporter.Port == nil {
r.Spec.RedisExporter.Port = pointer.Int(9121)
r.Spec.RedisExporter.Port = ptr.To(9121)
}
}
1 change: 1 addition & 0 deletions k8sutils/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func finalizeRedisReplicationPVC(client kubernetes.Interface, logger logr.Logger
return nil
}

//nolint:unparam
func finalizeRedisSentinelPVC(cr *redisv1beta2.RedisSentinel) error {
return nil
}
20 changes: 10 additions & 10 deletions k8sutils/finalizers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
k8sClientFake "k8s.io/client-go/kubernetes/fake"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -217,7 +217,7 @@ func TestHandleRedisClusterFinalizer(t *testing.T) {
},
},
Spec: v1beta2.RedisClusterSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
Storage: &v1beta2.ClusterStorage{
Storage: api.Storage{
KeepAfterDelete: false,
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestHandleRedisClusterFinalizer(t *testing.T) {
},
},
Spec: v1beta2.RedisClusterSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
Storage: &v1beta2.ClusterStorage{
Storage: api.Storage{
KeepAfterDelete: true,
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestHandleRedisReplicationFinalizer(t *testing.T) {
},
},
Spec: v1beta2.RedisReplicationSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
Storage: &v1beta2.Storage{
Storage: api.Storage{
KeepAfterDelete: false,
Expand Down Expand Up @@ -379,7 +379,7 @@ func TestHandleRedisReplicationFinalizer(t *testing.T) {
},
},
Spec: v1beta2.RedisReplicationSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
Storage: &v1beta2.Storage{
Storage: api.Storage{
KeepAfterDelete: false,
Expand Down Expand Up @@ -427,7 +427,7 @@ func TestHandleRedisReplicationFinalizer(t *testing.T) {
},
},
Spec: v1beta2.RedisReplicationSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
Storage: &v1beta2.Storage{
Storage: api.Storage{
KeepAfterDelete: true,
Expand Down Expand Up @@ -651,7 +651,7 @@ func TestFinalizeRedisReplicationPVC(t *testing.T) {
Namespace: "redis",
},
Spec: v1beta2.RedisReplicationSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
},
},
existingPVCs: []*corev1.PersistentVolumeClaim{
Expand Down Expand Up @@ -685,7 +685,7 @@ func TestFinalizeRedisReplicationPVC(t *testing.T) {
Namespace: "redis",
},
Spec: v1beta2.RedisReplicationSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
},
},
expectError: false,
Expand Down Expand Up @@ -735,7 +735,7 @@ func TestFinalizeRedisClusterPVC(t *testing.T) {
Namespace: "redis",
},
Spec: v1beta2.RedisClusterSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
Storage: &v1beta2.ClusterStorage{
NodeConfVolume: true,
},
Expand All @@ -753,7 +753,7 @@ func TestFinalizeRedisClusterPVC(t *testing.T) {
Namespace: "redis",
},
Spec: v1beta2.RedisClusterSpec{
Size: pointer.Int32(3),
Size: ptr.To(int32(3)),
Storage: &v1beta2.ClusterStorage{
NodeConfVolume: false,
},
Expand Down
8 changes: 4 additions & 4 deletions k8sutils/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func Test_generateMetaInformation(t *testing.T) {
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestRedisClusterAsOwner(t *testing.T) {
Kind: "RedisCluster",
Name: "test-redis-cluster",
UID: "abcdef",
Controller: pointer.Bool(true),
Controller: ptr.To(true),
}

result := redisClusterAsOwner(clusterObj)
Expand All @@ -340,7 +340,7 @@ func TestRedisReplicationAsOwner(t *testing.T) {
Kind: "RedisReplication",
Name: "test-redis-replication",
UID: "ghijkl",
Controller: pointer.Bool(true),
Controller: ptr.To(true),
}

result := redisReplicationAsOwner(replicationObj)
Expand All @@ -367,7 +367,7 @@ func TestRedisSentinelAsOwner(t *testing.T) {
Kind: "RedisSentinel",
Name: "test-redis-sentinel",
UID: "mnopqr",
Controller: pointer.Bool(true),
Controller: ptr.To(true),
}

result := redisSentinelAsOwner(sentinelObj)
Expand Down
4 changes: 2 additions & 2 deletions k8sutils/redis-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

// RedisClusterSTS is a interface to call Redis Statefulset function
Expand Down Expand Up @@ -295,7 +295,7 @@ func (service RedisClusterService) CreateRedisClusterService(cr *redisv1beta2.Re
var epp exporterPortProvider
if cr.Spec.RedisExporter != nil {
epp = func() (port int, enable bool) {
defaultP := pointer.Int(redisExporterPort)
defaultP := ptr.To(redisExporterPort)

Check warning on line 298 in k8sutils/redis-cluster.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-cluster.go#L298

Added line #L298 was not covered by tests
return *util.Coalesce(cr.Spec.RedisExporter.Port, defaultP), cr.Spec.RedisExporter.Enabled
}
} else {
Expand Down
66 changes: 33 additions & 33 deletions k8sutils/redis-cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func Test_generateRedisClusterParams(t *testing.T) {
path := filepath.Join("..", "tests", "testdata", "redis-cluster.yaml")

expectedLeaderSTS := statefulSetParameters{
Replicas: pointer.Int32(3),
Replicas: ptr.To(int32(3)),
ClusterMode: true,
NodeConfVolume: true,
PodSecurityContext: &corev1.PodSecurityContext{
RunAsUser: pointer.Int64(1000),
FSGroup: pointer.Int64(1000),
RunAsUser: ptr.To(int64(1000)),
FSGroup: ptr.To(int64(1000)),
},
PriorityClassName: "high-priority",
Affinity: &corev1.Affinity{
Expand Down Expand Up @@ -59,7 +59,7 @@ func Test_generateRedisClusterParams(t *testing.T) {
},
PersistentVolumeClaim: corev1.PersistentVolumeClaim{
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.String("standard"),
StorageClassName: ptr.To("standard"),
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
Expand All @@ -70,7 +70,7 @@ func Test_generateRedisClusterParams(t *testing.T) {
},
NodeConfPersistentVolumeClaim: corev1.PersistentVolumeClaim{
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.String("standard"),
StorageClassName: ptr.To("standard"),
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
Expand All @@ -81,17 +81,17 @@ func Test_generateRedisClusterParams(t *testing.T) {
},
EnableMetrics: true,
ImagePullSecrets: &[]corev1.LocalObjectReference{{Name: "mysecret"}},
ExternalConfig: pointer.String("redis-external-config-leader"),
ServiceAccountName: pointer.String("redis-sa"),
ExternalConfig: ptr.To("redis-external-config-leader"),
ServiceAccountName: ptr.To("redis-sa"),
IgnoreAnnotations: []string{"opstreelabs.in/ignore"},
}
expectedFollowerSTS := statefulSetParameters{
Replicas: pointer.Int32(3),
Replicas: ptr.To(int32(3)),
ClusterMode: true,
NodeConfVolume: true,
PodSecurityContext: &corev1.PodSecurityContext{
RunAsUser: pointer.Int64(1000),
FSGroup: pointer.Int64(1000),
RunAsUser: ptr.To(int64(1000)),
FSGroup: ptr.To(int64(1000)),
},
PriorityClassName: "high-priority",
Affinity: &corev1.Affinity{
Expand Down Expand Up @@ -125,7 +125,7 @@ func Test_generateRedisClusterParams(t *testing.T) {
},
PersistentVolumeClaim: corev1.PersistentVolumeClaim{
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.String("standard"),
StorageClassName: ptr.To("standard"),
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
Expand All @@ -136,7 +136,7 @@ func Test_generateRedisClusterParams(t *testing.T) {
},
NodeConfPersistentVolumeClaim: corev1.PersistentVolumeClaim{
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: pointer.String("standard"),
StorageClassName: ptr.To("standard"),
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
Expand All @@ -147,8 +147,8 @@ func Test_generateRedisClusterParams(t *testing.T) {
},
EnableMetrics: true,
ImagePullSecrets: &[]corev1.LocalObjectReference{{Name: "mysecret"}},
ExternalConfig: pointer.String("redis-external-config-follower"),
ServiceAccountName: pointer.String("redis-sa"),
ExternalConfig: ptr.To("redis-external-config-follower"),
ServiceAccountName: ptr.To("redis-sa"),
IgnoreAnnotations: []string{"opstreelabs.in/ignore"},
}

Expand Down Expand Up @@ -206,10 +206,10 @@ func Test_generateRedisClusterContainerParams(t *testing.T) {
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(1000),
RunAsGroup: pointer.Int64(1000),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: ptr.To(int64(1000)),
RunAsGroup: ptr.To(int64(1000)),
RunAsNonRoot: ptr.To(true),
ReadOnlyRootFilesystem: ptr.To(true),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
Add: []corev1.Capability{"NET_BIND_SERVICE"},
Expand Down Expand Up @@ -256,10 +256,10 @@ func Test_generateRedisClusterContainerParams(t *testing.T) {
},
},
Role: "cluster",
EnabledPassword: pointer.Bool(true),
SecretName: pointer.String("redis-secret"),
SecretKey: pointer.String("password"),
PersistenceEnabled: pointer.Bool(true),
EnabledPassword: ptr.To(true),
SecretName: ptr.To("redis-secret"),
SecretKey: ptr.To("password"),
PersistenceEnabled: ptr.To(true),
TLSConfig: &redisv1beta2.TLSConfig{
TLSConfig: common.TLSConfig{
CaKeyFile: "ca.key",
Expand Down Expand Up @@ -319,10 +319,10 @@ func Test_generateRedisClusterContainerParams(t *testing.T) {
},
},
SecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(1000),
RunAsGroup: pointer.Int64(1000),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: ptr.To(int64(1000)),
RunAsGroup: ptr.To(int64(1000)),
RunAsNonRoot: ptr.To(true),
ReadOnlyRootFilesystem: ptr.To(true),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
Add: []corev1.Capability{"NET_BIND_SERVICE"},
Expand Down Expand Up @@ -369,10 +369,10 @@ func Test_generateRedisClusterContainerParams(t *testing.T) {
},
},
Role: "cluster",
EnabledPassword: pointer.Bool(true),
SecretName: pointer.String("redis-secret"),
SecretKey: pointer.String("password"),
PersistenceEnabled: pointer.Bool(true),
EnabledPassword: ptr.To(true),
SecretName: ptr.To("redis-secret"),
SecretKey: ptr.To("password"),
PersistenceEnabled: ptr.To(true),
TLSConfig: &redisv1beta2.TLSConfig{
TLSConfig: common.TLSConfig{
CaKeyFile: "ca.key",
Expand Down Expand Up @@ -440,7 +440,7 @@ func Test_generateRedisClusterContainerParams(t *testing.T) {
func Test_generateRedisClusterInitContainerParams(t *testing.T) {
path := filepath.Join("..", "tests", "testdata", "redis-cluster.yaml")
expected := initContainerParameters{
Enabled: pointer.Bool(true),
Enabled: ptr.To(true),
Image: "quay.io/opstree/redis-operator-restore:latest",
ImagePullPolicy: corev1.PullPolicy("Always"),
Resources: &corev1.ResourceRequirements{
Expand All @@ -456,7 +456,7 @@ func Test_generateRedisClusterInitContainerParams(t *testing.T) {
Role: "cluster",
Command: []string{"/bin/bash", "-c", "/app/restore.bash"},
Arguments: []string{"--restore-from", "redis-cluster-restore"},
PersistenceEnabled: pointer.Bool(true),
PersistenceEnabled: ptr.To(true),
AdditionalEnvVariable: &[]corev1.EnvVar{
{
Name: "CLUSTER_NAME",
Expand Down
6 changes: 3 additions & 3 deletions k8sutils/redis-replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/go-logr/logr"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

// CreateReplicationService method will create replication service for Redis
Expand All @@ -18,7 +18,7 @@ func CreateReplicationService(cr *redisv1beta2.RedisReplication, cl kubernetes.I
var epp exporterPortProvider
if cr.Spec.RedisExporter != nil {
epp = func() (port int, enable bool) {
defaultP := pointer.Int(redisExporterPort)
defaultP := ptr.To(redisExporterPort)

Check warning on line 21 in k8sutils/redis-replication.go

View check run for this annotation

Codecov / codecov/patch

k8sutils/redis-replication.go#L21

Added line #L21 was not covered by tests
return *util.Coalesce(cr.Spec.RedisExporter.Port, defaultP), cr.Spec.RedisExporter.Enabled
}
} else {
Expand Down Expand Up @@ -125,7 +125,7 @@ func generateRedisReplicationContainerParams(cr *redisv1beta2.RedisReplication)
ImagePullPolicy: cr.Spec.KubernetesConfig.ImagePullPolicy,
Resources: cr.Spec.KubernetesConfig.Resources,
SecurityContext: cr.Spec.SecurityContext,
Port: pointer.Int(6379),
Port: ptr.To(6379),
}
if cr.Spec.EnvVars != nil {
containerProp.EnvVars = cr.Spec.EnvVars
Expand Down
Loading

0 comments on commit 6056ff0

Please sign in to comment.