Skip to content

Commit

Permalink
Merge branch 'OT-CONTAINER-KIT:master' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
jiuker authored Jul 20, 2023
2 parents 7e08192 + 2e813e6 commit 0228c5c
Show file tree
Hide file tree
Showing 109 changed files with 5,599 additions and 1,119 deletions.
4 changes: 2 additions & 2 deletions .azure-pipelines/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ extends:
QuayImageName: opstree/redis-operator
GithubImageName: ot-container-kit/redis-operator/redis-operator
BuildDocs: false
AppVersion: "v0.14.0"
GolangVersion: "1.17"
AppVersion: "v0.15.0"
GolangVersion: "1.17"
45 changes: 45 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0.8
gofmt:
simplify: true

# linters:
# enable-all: true
# disable:
# - errcheck
# - tagliatelle
# 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.17"
test: false
# Exclude third-party packages and go.mod from the lint checks
exclude: |
'(^vendor/.*|.*_test\.go|go\.mod|.*validatingwebhookconfiguration\.go|.*mutatingwebhookconfiguration\.go)'
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/go-redis/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$
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Current Operator version
VERSION ?= 0.14.0
VERSION ?= 0.15.0
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
Expand Down Expand Up @@ -87,23 +87,23 @@ docker-push:
# Download controller-gen locally if necessary
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen:
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

# Download kustomize locally if necessary
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize:
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

# go-get-tool will 'go get' any package $2 and install it to $1.
# go-install-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
Expand Down
55 changes: 52 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ A Golang based redis operator that will make/oversee Redis standalone and cluste

For documentation, please refer to https://ot-redis-operator.netlify.app/

Organizations that are using Redis Operator to manage their redis workload can be found [here](./USED_BY_ORGANIZATIONS.md). If your organization is also using Redis Operator, please free to add by creating a PR https://github.com/OT-CONTAINER-KIT/redis-operator/pulls.
Organizations that are using Redis Operator to manage their redis workload can be found [here](./USED_BY_ORGANIZATIONS.md). If your organization is also using Redis Operator, please free to add by creating a [pull request](https://github.com/OT-CONTAINER-KIT/redis-operator/pulls)

This operator only supports versions of redis `=>6`.

Expand Down Expand Up @@ -63,6 +63,16 @@ The configuration of Redis setup should be described in [CRD definitions](config

Redis operator requires a Kubernetes cluster of version `>=1.18.0`. If you have just started with Operators, it's highly recommended using the latest version of Kubernetes.

## Image Compatibility

The following table shows the compatibility between the Operator Version, Redis Image, Sentinel Image, and Exporter Image:

| Operator Version | Redis Image | Sentinel Image | Exporter Image |
|------------------|-------------|----------------|----------------|
| v0.15.0 | v7.0.11 | v7.0.11 | v1.48.0 |
| v0.14.0 | v7.0.7 | v7.0.7 | v1.48.0 |
| v0.13.0 | v6.2.5 | nil | v1.48.0 |

## Quickstart

The setup can be done by using helm. If you want to see more example, please go through the [example](./example) folder.
Expand All @@ -82,10 +92,10 @@ $ helm upgrade redis-operator ot-helm/redis-operator --install --namespace ot-op
After deployment, verify the installation of operator

```shell
$ helm test redis-operator --namespace ot-operators
helm test redis-operator --namespace ot-operators
```

Creating redis cluster or standalone setup.
Creating redis cluster, standalone, replication and sentinel setup.

```shell
# Create redis cluster setup
Expand All @@ -100,6 +110,45 @@ $ helm upgrade redis ot-helm/redis \
--install --namespace ot-operators
```

```shell
# Create redis replication setup
$ helm upgrade redis-replication ot-helm/replication \
--install --namespace ot-operators
```

```shell
# Create redis sentinel setup
$ helm upgrade redis-sentinel ot-helm/sentinel \
--install --namespace ot-operators
```

If you used this just for testing and development purpose you can delete the resources associated with it

```shell
# Delete the Redis standalone setup
$ helm uninstall redis --namespace ot-operators
```

```shell
# Delete the Redis cluster setup
$ helm uninstall redis-cluster --namespace ot-operators
```

```shell
# Delete the Redis replication setup
$ helm uninstall redis-replication --namespace ot-operators
```

```shell
# Delete the Redis sentinel setup
$ helm uninstall redis-sentinel --namespace ot-operators
```

```shell
# Delete the Redis operator
$ helm uninstall redis-operator --namespace ot-operators
```

If you want to customize the value file by yourself while initializing the helm command, the values files for reference are present [here](https://github.com/OT-CONTAINER-KIT/helm-charts/tree/main/charts/redis-setup).

## Monitoring with Prometheus
Expand Down
25 changes: 25 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ type Storage struct {
VolumeMount AdditionalVolume `json:"volumeMount,omitempty"`
}

// Node-conf needs to be added only in redis cluster
type ClusterStorage struct {
VolumeClaimTemplate corev1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
NodeConfVolumeClaimTemplate corev1.PersistentVolumeClaim `json:"nodeConfVolumeClaimTemplate,omitempty"`
VolumeMount AdditionalVolume `json:"volumeMount,omitempty"`
}

// Additional Volume is provided by user that is mounted on the pods
type AdditionalVolume struct {
Volume []corev1.Volume `json:"volume,omitempty"`
Expand All @@ -80,6 +87,10 @@ type TLSConfig struct {
Secret corev1.SecretVolumeSource `json:"secret"`
}

type ACLConfig struct {
Secret *corev1.SecretVolumeSource `json:"secret,omitempty"`
}

// Probe is a interface for ReadinessProbe and LivenessProbe
type Probe struct {
// +kubebuilder:validation:Minimum=1
Expand All @@ -106,4 +117,18 @@ type Sidecar struct {
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
EnvVars *[]corev1.EnvVar `json:"env,omitempty"`
Volumes *[]corev1.VolumeMount `json:"mountPath,omitempty"`
Command []string `json:"command,omitempty" protobuf:"bytes,3,rep,name=command"`
Ports *[]corev1.ContainerPort `json:"ports,omitempty" patchStrategy:"merge" patchMergeKey:"containerPort" protobuf:"bytes,6,rep,name=ports"`
}

// InitContainer for each Redis pods
type InitContainer struct {
Enabled *bool `json:"enabled,omitempty"`
Image string `json:"image"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
EnvVars *[]corev1.EnvVar `json:"env,omitempty"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
}
30 changes: 17 additions & 13 deletions api/v1beta1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,26 @@ import (

// RedisSpec defines the desired state of Redis
type RedisSpec struct {
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
ACL *ACLConfig `json:"acl,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
InitContainer *InitContainer `json:"initContainer,omitempty"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
}

// RedisStatus defines the observed state of Redis
Expand Down
22 changes: 14 additions & 8 deletions api/v1beta1/rediscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ type RedisClusterSpec struct {
// +kubebuilder:default:={livenessProbe:{initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}, readinessProbe:{initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}}
RedisFollower RedisFollower `json:"redisFollower,omitempty"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
Storage *Storage `json:"storage,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
Storage *ClusterStorage `json:"storage,omitempty"`
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
ACL *ACLConfig `json:"acl,omitempty"`
InitContainer *InitContainer `json:"initContainer,omitempty"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
PersistenceEnabled *bool `json:"persistenceEnabled,omitempty"`
Expand All @@ -56,28 +58,32 @@ func (cr *RedisClusterSpec) GetReplicaCounts(t string) int32 {
type RedisLeader struct {
Replicas *int32 `json:"replicas,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
PodDisruptionBudget *RedisPodDisruptionBudget `json:"pdb,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
}

// RedisFollower interface will have the redis follower configuration
type RedisFollower struct {
Replicas *int32 `json:"replicas,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
PodDisruptionBudget *RedisPodDisruptionBudget `json:"pdb,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
}

// RedisClusterStatus defines the observed state of RedisCluster
Expand Down
32 changes: 18 additions & 14 deletions api/v1beta1/redisreplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@ import (
)

type RedisReplicationSpec struct {
Size *int32 `json:"clusterSize"`
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
Size *int32 `json:"clusterSize"`
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
RedisConfig *RedisConfig `json:"redisConfig,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
ACL *ACLConfig `json:"acl,omitempty"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
ReadinessProbe *Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"`
// +kubebuilder:default:={initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
InitContainer *InitContainer `json:"initContainer,omitempty"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
}

func (cr *RedisReplicationSpec) GetReplicationCounts(t string) int32 {
Expand Down
Loading

0 comments on commit 0228c5c

Please sign in to comment.