Skip to content
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
13 changes: 4 additions & 9 deletions .github/workflows/operator-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- master

permissions:
contents: read

env:
GOLANG_VERSION: 1.21
APPLICATION_NAME: redis-operator
Expand Down Expand Up @@ -44,15 +47,7 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOLANG_VERSION }}

- name: Download Go modules
run: go mod download

- name: Check disk space
run: df -h

- name: List Go module cache
run: ls -la $(go env GOPATH)/pkg/mod
cache: false

- name: Run GolangCI-Lint
uses: golangci/golangci-lint-action@v3
Expand Down
87 changes: 48 additions & 39 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,59 @@ linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0.8
min-confidence: 0.8
gofmt:
simplify: true

linters:
disable:
- errcheck
- tagliatelle
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- decorder
- dogsled
- durationcheck
- errcheck
- errname
- exportloopref
- gci
- gochecknoinits
- gofmt
- gofumpt
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
- makezero
- misspell
- noctx
- nolintlint
- nosprintfhostport
- staticcheck

# Exclude the files that are causing the errors
issues:
exclude-rules:
- path: _test\.go # Ignore test files for linting
linters:
- gocyclo
- errcheck
- dupl
- gosec
run:
timeout: 5m
go-version: "1.21"
output:
format: colored-line-number
sort-results: true
- tenv
- thelper
- tparallel
- typecheck
- unconvert
- unused
- wastedassign
- whitespace

test: false
# Exclude third-party packages and go.mod from the lint checks
exclude: |
'(^vendor/.*|.*_test\.go|go\.mod|.*validatingwebhookconfiguration\.go|.*mutatingwebhookconfiguration\.go)'
run:
timeout: 15m
go: "1.21"
tests: true
show-stats: true
skip-files:
- '^.*validatingwebhookconfiguration\.go$'
- controllers/suite_test.go
skip-dirs:
- k8s.io/client-go
- github.com/banzaicloud/k8s-objectmatcher
- github.com/go-logr/logr
- github.com/redis/go-redis
- github.com/onsi/ginkgo
- github.com/onsi/gomega
- github.com/pkg/errors
- k8s.io/api
- k8s.io/apimachinery
- sigs.k8s.io/controller-runtime
- golang.org/x/sys
- vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
- ".+\\.generated.go"

output:
format: colored-line-number
sort-results: true
print-linter-name: true
print-issued-lines: true
4 changes: 2 additions & 2 deletions api/v1beta1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,6 +68,7 @@ type RedisList struct {
Items []Redis `json:"items"`
}

// //nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&Redis{}, &RedisList{})
}
4 changes: 2 additions & 2 deletions api/v1beta1/rediscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -91,6 +90,7 @@ type RedisClusterList struct {
Items []RedisCluster `json:"items"`
}

//nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&RedisCluster{}, &RedisClusterList{})
}
4 changes: 2 additions & 2 deletions api/v1beta1/redisreplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,6 +54,7 @@ type RedisReplicationList struct {
Items []RedisReplication `json:"items"`
}

//nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&RedisReplication{}, &RedisReplicationList{})
}
4 changes: 2 additions & 2 deletions api/v1beta1/redissentinel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ type RedisSentinelConfig struct {
common.RedisSentinelConfig `json:",inline"`
}

type RedisSentinelStatus struct {
}
type RedisSentinelStatus struct{}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
Expand All @@ -61,6 +60,7 @@ type RedisSentinelList struct {
Items []RedisSentinel `json:"items"`
}

//nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&RedisSentinel{}, &RedisSentinelList{})
}
4 changes: 2 additions & 2 deletions api/v1beta2/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,6 +74,7 @@ type RedisList struct {
Items []Redis `json:"items"`
}

//nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&Redis{}, &RedisList{})
}
1 change: 1 addition & 0 deletions api/v1beta2/rediscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ type RedisClusterList struct {
Items []RedisCluster `json:"items"`
}

//nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&RedisCluster{}, &RedisClusterList{})
}
4 changes: 2 additions & 2 deletions api/v1beta2/redisreplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -61,6 +60,7 @@ type RedisReplicationList struct {
Items []RedisReplication `json:"items"`
}

//nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&RedisReplication{}, &RedisReplicationList{})
}
4 changes: 2 additions & 2 deletions api/v1beta2/redissentinel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ type RedisSentinelConfig struct {
common.RedisSentinelConfig `json:",inline"`
}

type RedisSentinelStatus struct {
}
type RedisSentinelStatus struct{}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
Expand All @@ -66,6 +65,7 @@ type RedisSentinelList struct {
Items []RedisSentinel `json:"items"`
}

//nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&RedisSentinel{}, &RedisSentinelList{})
}
4 changes: 1 addition & 3 deletions controllers/redis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"context"
"fmt"

appsv1 "k8s.io/api/apps/v1"

redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
1 change: 0 additions & 1 deletion controllers/rediscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func (r *RedisClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
}

if redisLeaderInfo.Status.ReadyReplicas == leaderReplicas {

// Mark the cluster status as initializing if there are no follower nodes
if instance.Status.ReadyLeaderReplicas == 0 && instance.Status.ReadyFollowerReplicas == 0 {
err = k8sutils.UpdateRedisClusterStatus(instance, status.RedisClusterInitializing, status.InitializingClusterFollowerReason, leaderReplicas, 0, r.Dk8sClient)
Expand Down
6 changes: 2 additions & 4 deletions controllers/rediscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"context"
"fmt"

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

redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
6 changes: 1 addition & 5 deletions controllers/redisreplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -73,7 +72,7 @@ func (r *RedisReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
}

// Check that the Leader and Follower are ready in redis replication
if int32(redisReplicationInfo.Status.ReadyReplicas) != totalReplicas {
if redisReplicationInfo.Status.ReadyReplicas != totalReplicas {
reqLogger.Info("Redis replication nodes are not ready yet", "Ready.Replicas", strconv.Itoa(int(redisReplicationInfo.Status.ReadyReplicas)), "Expected.Replicas", totalReplicas)
return ctrl.Result{RequeueAfter: time.Second * 60}, nil
}
Expand All @@ -86,12 +85,9 @@ func (r *RedisReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
if err != nil {
return ctrl.Result{RequeueAfter: time.Second * 60}, err
}

}

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.
Expand Down
2 changes: 0 additions & 2 deletions controllers/redisreplication_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -101,7 +100,6 @@ var _ = Describe("Redis replication test", func() {
"redis_setup_type": "replication",
"role": "replication",
}))

})

Context("then deleting the redis replication CR", func() {
Expand Down
10 changes: 4 additions & 6 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@ import (

// redisv1beta1 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta1"
redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
)

var k8sClient client.Client
var testEnv *envtest.Environment
var (
k8sClient client.Client
testEnv *envtest.Environment
)

const (
ns = "default"
Expand Down Expand Up @@ -136,5 +135,4 @@ var _ = BeforeSuite(func() {
err := testEnv.Stop()
Expect(err).ToNot(HaveOccurred())
}()

})
1 change: 1 addition & 0 deletions k8sutils/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Loading