diff --git a/api/v1beta1/redis_types.go b/api/v1beta1/redis_types.go index 6a38be57a..5461b93d5 100644 --- a/api/v1beta1/redis_types.go +++ b/api/v1beta1/redis_types.go @@ -45,8 +45,7 @@ type RedisSpec struct { } // RedisStatus defines the observed state of Redis -type RedisStatus struct { -} +type RedisStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/api/v1beta1/rediscluster_types.go b/api/v1beta1/rediscluster_types.go index 4076e71c0..cbd9b9ecd 100644 --- a/api/v1beta1/rediscluster_types.go +++ b/api/v1beta1/rediscluster_types.go @@ -64,8 +64,7 @@ type RedisFollower struct { } // RedisClusterStatus defines the observed state of RedisCluster -type RedisClusterStatus struct { -} +type RedisClusterStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/api/v1beta1/redisreplication_types.go b/api/v1beta1/redisreplication_types.go index df9ea159c..c4c800722 100644 --- a/api/v1beta1/redisreplication_types.go +++ b/api/v1beta1/redisreplication_types.go @@ -31,8 +31,7 @@ func (cr *RedisReplicationSpec) GetReplicationCounts(t string) int32 { } // RedisStatus defines the observed state of Redis -type RedisReplicationStatus struct { -} +type RedisReplicationStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/api/v1beta1/redissentinel_types.go b/api/v1beta1/redissentinel_types.go index 43103f2d5..36fceb5a6 100644 --- a/api/v1beta1/redissentinel_types.go +++ b/api/v1beta1/redissentinel_types.go @@ -37,8 +37,7 @@ type RedisSentinelConfig struct { common.RedisSentinelConfig `json:",inline"` } -type RedisSentinelStatus struct { -} +type RedisSentinelStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/api/v1beta2/redis_types.go b/api/v1beta2/redis_types.go index 091cb19ea..f5f177dd5 100644 --- a/api/v1beta2/redis_types.go +++ b/api/v1beta2/redis_types.go @@ -50,8 +50,7 @@ type RedisSpec struct { } // RedisStatus defines the observed state of Redis -type RedisStatus struct { -} +type RedisStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/api/v1beta2/redisreplication_types.go b/api/v1beta2/redisreplication_types.go index cb04c169d..be6c4dabe 100644 --- a/api/v1beta2/redisreplication_types.go +++ b/api/v1beta2/redisreplication_types.go @@ -36,8 +36,7 @@ func (cr *RedisReplicationSpec) GetReplicationCounts(t string) int32 { } // RedisStatus defines the observed state of Redis -type RedisReplicationStatus struct { -} +type RedisReplicationStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/api/v1beta2/redissentinel_types.go b/api/v1beta2/redissentinel_types.go index b40ee6e10..dd53ca8fb 100644 --- a/api/v1beta2/redissentinel_types.go +++ b/api/v1beta2/redissentinel_types.go @@ -41,8 +41,7 @@ type RedisSentinelConfig struct { common.RedisSentinelConfig `json:",inline"` } -type RedisSentinelStatus struct { -} +type RedisSentinelStatus struct{} // +kubebuilder:object:root=true // +kubebuilder:subresource:status diff --git a/controllers/redisreplication_controller.go b/controllers/redisreplication_controller.go index 9929e332c..15ff633b3 100644 --- a/controllers/redisreplication_controller.go +++ b/controllers/redisreplication_controller.go @@ -26,7 +26,6 @@ type RedisReplicationReconciler struct { } func (r *RedisReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - reqLogger := r.Log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name) reqLogger.Info("Reconciling opstree redis replication controller") instance := &redisv1beta2.RedisReplication{} @@ -91,7 +90,6 @@ func (r *RedisReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req reqLogger.Info("Will reconcile redis operator in again 10 seconds") return ctrl.Result{RequeueAfter: time.Second * 10}, nil - } // SetupWithManager sets up the controller with the Manager. diff --git a/controllers/redisreplication_controller_test.go b/controllers/redisreplication_controller_test.go index 3d12c07ee..ff833a5b1 100644 --- a/controllers/redisreplication_controller_test.go +++ b/controllers/redisreplication_controller_test.go @@ -49,7 +49,6 @@ var _ = Describe("Redis replication test", func() { Context("When creating a redis replication CR", func() { It("should create a statefulset, service", func() { - svc := &corev1.Service{} sts := &appsv1.StatefulSet{} @@ -101,7 +100,6 @@ var _ = Describe("Redis replication test", func() { "redis_setup_type": "replication", "role": "replication", })) - }) Context("then deleting the redis replication CR", func() { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 0ab8268ff..c32be548b 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -39,8 +39,10 @@ import ( // +kubebuilder:scaffold:imports ) -var k8sClient client.Client -var testEnv *envtest.Environment +var ( + k8sClient client.Client + testEnv *envtest.Environment +) const ( ns = "default" @@ -136,5 +138,4 @@ var _ = BeforeSuite(func() { err := testEnv.Stop() Expect(err).ToNot(HaveOccurred()) }() - }) diff --git a/k8sutils/client_test.go b/k8sutils/client_test.go index 13618dc70..4a9904e1c 100644 --- a/k8sutils/client_test.go +++ b/k8sutils/client_test.go @@ -11,6 +11,7 @@ import ( func mockK8sConfigProvider() (*rest.Config, error) { return &rest.Config{}, nil } + func mockInvalidK8sConfigProvider() (*rest.Config, error) { return nil, errors.New("invalid configuration") } diff --git a/k8sutils/cluster-scaling.go b/k8sutils/cluster-scaling.go index 957b74b28..4b4d9649b 100644 --- a/k8sutils/cluster-scaling.go +++ b/k8sutils/cluster-scaling.go @@ -290,7 +290,6 @@ func getAttachedFollowerNodeIDs(ctx context.Context, client kubernetes.Interface slaveIDs = append(slaveIDs, parts[0]) } } - } logger.V(1).Info("Slaves Nodes attached to", "node", masterNodeID, "are", slaveIDs) @@ -345,7 +344,7 @@ func RemoveRedisFollowerNodesFromCluster(ctx context.Context, client kubernetes. // Remove redis cluster node would remove last node to the existing redis cluster using redis-cli func RemoveRedisNodeFromCluster(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster, removePod RedisDetails) { var cmd []string - //currentRedisCount := CheckRedisNodeCount(ctx, client, logger, cr, "leader") + // currentRedisCount := CheckRedisNodeCount(ctx, client, logger, cr, "leader") existingPod := RedisDetails{ PodName: cr.ObjectMeta.Name + "-leader-0", diff --git a/k8sutils/finalizer.go b/k8sutils/finalizer.go index 526fac516..aeac02ff3 100644 --- a/k8sutils/finalizer.go +++ b/k8sutils/finalizer.go @@ -3,6 +3,7 @@ package k8sutils import ( "context" "fmt" + "k8s.io/utils/env" redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2" @@ -192,6 +193,5 @@ func finalizeRedisReplicationPVC(client kubernetes.Interface, logger logr.Logger } func finalizeRedisSentinelPVC(cr *redisv1beta2.RedisSentinel) error { - return nil } diff --git a/k8sutils/labels_test.go b/k8sutils/labels_test.go index 274f9c1a0..3331a1784 100644 --- a/k8sutils/labels_test.go +++ b/k8sutils/labels_test.go @@ -48,7 +48,8 @@ func Test_generateObjectMetaInformation(t *testing.T) { name: "test", namespace: "default", labels: map[string]string{"test": "test"}, - annotations: map[string]string{"test": "test"}}, + annotations: map[string]string{"test": "test"}, + }, want: metav1.ObjectMeta{ Name: "test", Namespace: "default", diff --git a/k8sutils/redis-replication_test.go b/k8sutils/redis-replication_test.go index 509f863e7..57765acba 100644 --- a/k8sutils/redis-replication_test.go +++ b/k8sutils/redis-replication_test.go @@ -21,7 +21,8 @@ func Test_generateRedisReplicationParams(t *testing.T) { ClusterMode: false, NodeConfVolume: false, NodeSelector: map[string]string{ - "node-role.kubernetes.io/infra": "worker"}, + "node-role.kubernetes.io/infra": "worker", + }, PodSecurityContext: &corev1.PodSecurityContext{ RunAsUser: pointer.Int64(1000), FSGroup: pointer.Int64(1000), diff --git a/k8sutils/redis-sentinel.go b/k8sutils/redis-sentinel.go index 698a19980..4984dddb1 100644 --- a/k8sutils/redis-sentinel.go +++ b/k8sutils/redis-sentinel.go @@ -52,12 +52,10 @@ func CreateRedisSentinel(ctx context.Context, client kubernetes.Interface, logge } return prop.CreateRedisSentinelSetup(ctx, client, logger, cr, cl, dcl) - } // Create RedisSentinel Service func CreateRedisSentinelService(cr *redisv1beta2.RedisSentinel, cl kubernetes.Interface) error { - prop := RedisSentinelService{ RedisServiceRole: "sentinel", } @@ -80,7 +78,6 @@ func (service RedisSentinelSTS) CreateRedisSentinelSetup(ctx context.Context, cl cr.Spec.Sidecars, cl, ) - if err != nil { logger.Error(err, "Cannot create Sentinel statefulset for Redis") return err @@ -90,7 +87,6 @@ func (service RedisSentinelSTS) CreateRedisSentinelSetup(ctx context.Context, cl // Create Redis Sentile Params for the statefulset func generateRedisSentinelParams(cr *redisv1beta2.RedisSentinel, replicas int32, externalConfig *string, affinity *corev1.Affinity) statefulSetParameters { - res := statefulSetParameters{ Replicas: &replicas, ClusterMode: false, @@ -123,7 +119,6 @@ func generateRedisSentinelParams(cr *redisv1beta2.RedisSentinel, replicas int32, // generateRedisSentinelInitContainerParams generates Redis sentinel initcontainer information func generateRedisSentinelInitContainerParams(cr *redisv1beta2.RedisSentinel) initContainerParameters { - initcontainerProp := initContainerParameters{} if cr.Spec.InitContainer != nil { @@ -190,7 +185,6 @@ func generateRedisSentinelContainerParams(ctx context.Context, client kubernetes } return containerProp - } // Get the Count of the Sentinel @@ -243,7 +237,6 @@ func (service RedisSentinelService) CreateRedisSentinelService(cr *redisv1beta2. return err } return nil - } func getSentinelEnvVariable(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisSentinel, dcl dynamic.Interface) *[]corev1.EnvVar { @@ -289,7 +282,6 @@ func getSentinelEnvVariable(ctx context.Context, client kubernetes.Interface, lo }) } return envVar - } func getRedisReplicationMasterIP(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisSentinel, dcl dynamic.Interface) string { diff --git a/k8sutils/redis-sentinel_test.go b/k8sutils/redis-sentinel_test.go index 85260d5b1..a62d3ee65 100644 --- a/k8sutils/redis-sentinel_test.go +++ b/k8sutils/redis-sentinel_test.go @@ -28,7 +28,8 @@ func Test_generateRedisSentinelParams(t *testing.T) { ClusterMode: false, NodeConfVolume: false, NodeSelector: map[string]string{ - "node-role.kubernetes.io/infra": "worker"}, + "node-role.kubernetes.io/infra": "worker", + }, PodSecurityContext: &corev1.PodSecurityContext{ RunAsUser: pointer.Int64(1000), FSGroup: pointer.Int64(1000), diff --git a/k8sutils/redis-standalone.go b/k8sutils/redis-standalone.go index c47e6a934..1c45fe471 100644 --- a/k8sutils/redis-standalone.go +++ b/k8sutils/redis-standalone.go @@ -103,7 +103,6 @@ func generateRedisStandaloneParams(cr *redisv1beta2.Redis) statefulSetParameters } if cr.Spec.RedisExporter != nil { res.EnableMetrics = cr.Spec.RedisExporter.Enabled - } if cr.Spec.ServiceAccountName != nil { res.ServiceAccountName = cr.Spec.ServiceAccountName diff --git a/k8sutils/redis-standalone_test.go b/k8sutils/redis-standalone_test.go index 81d13e537..e7eebe882 100644 --- a/k8sutils/redis-standalone_test.go +++ b/k8sutils/redis-standalone_test.go @@ -29,7 +29,8 @@ func Test_generateRedisStandaloneParams(t *testing.T) { // "opstreelabs.in.redis": "true"}, // }, NodeSelector: map[string]string{ - "node-role.kubernetes.io/infra": "worker"}, + "node-role.kubernetes.io/infra": "worker", + }, PodSecurityContext: &corev1.PodSecurityContext{ RunAsUser: pointer.Int64(1000), FSGroup: pointer.Int64(1000), diff --git a/k8sutils/redis.go b/k8sutils/redis.go index 221917c13..f0a08e621 100644 --- a/k8sutils/redis.go +++ b/k8sutils/redis.go @@ -546,7 +546,6 @@ func checkAttachedSlave(ctx context.Context, client kubernetes.Interface, logger } return "" - } func CreateMasterSlaveReplication(ctx context.Context, client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisReplication, masterPods []string, slavePods []string) error { diff --git a/k8sutils/redis_test.go b/k8sutils/redis_test.go index 8dacd2032..14c0b2717 100644 --- a/k8sutils/redis_test.go +++ b/k8sutils/redis_test.go @@ -24,7 +24,7 @@ func TestCheckRedisNodePresence(t *testing.T) { csvOutput.FieldsPerRecord = -1 nodes, _ := csvOutput.ReadAll() - var tests = []struct { + tests := []struct { nodes [][]string ip string want bool diff --git a/k8sutils/services.go b/k8sutils/services.go index 353e68f58..a2e4f6892 100644 --- a/k8sutils/services.go +++ b/k8sutils/services.go @@ -19,9 +19,7 @@ const ( redisExporterPortName = "redis-exporter" ) -var ( - serviceType corev1.ServiceType -) +var serviceType corev1.ServiceType // exporterPortProvider return the exporter port if bool is true type exporterPortProvider func() (port int, enable bool) diff --git a/k8sutils/statefulset.go b/k8sutils/statefulset.go index 67f394a6e..7ae335ad7 100644 --- a/k8sutils/statefulset.go +++ b/k8sutils/statefulset.go @@ -612,7 +612,8 @@ func getProbeInfo(probe *commonapi.Probe) *corev1.Probe { // getEnvironmentVariables returns all the required Environment Variables func getEnvironmentVariables(role string, enabledPassword *bool, secretName *string, secretKey *string, persistenceEnabled *bool, tlsConfig *redisv1beta2.TLSConfig, - aclConfig *redisv1beta2.ACLConfig, envVar *[]corev1.EnvVar, port *int, clusterVersion *string) []corev1.EnvVar { + aclConfig *redisv1beta2.ACLConfig, envVar *[]corev1.EnvVar, port *int, clusterVersion *string, +) []corev1.EnvVar { envVars := []corev1.EnvVar{ {Name: "SERVER_MODE", Value: role}, {Name: "SETUP_MODE", Value: role},