Skip to content

Commit

Permalink
Pull request OT-CONTAINER-KIT#12: Sync our internal branch to v0.14 w…
Browse files Browse the repository at this point in the history
…/internal patches

Merge in OSS/redis-operator from ~ATHOMPSON/redis-operator:sync-internal-cs-main-to-0.14 to cs-main

* commit '2ea8fcaf61b322186f8a0a2c4e7bcb310f55ea2d':
  Revert "Handle nil probe"
  Handle nil probe
  Bumps prometheus/client_golang to address vuln
  Adds CODEOWNERS for our internal branch
  [Feature] Add Redis Sentinel Support  (OT-CONTAINER-KIT#408)
  Fixed Redis Replicate Cache bug (OT-CONTAINER-KIT#424)
  [Feature] : Add Replication Mode to the Redis Operator (OT-CONTAINER-KIT#417)
  [Development][Add] Added recreation logic for statefulset (OT-CONTAINER-KIT#411)
  Fixes issue with arm64 support. (OT-CONTAINER-KIT#404)
  [Development][Add] Added nodeSelector and tolerations for cluster (OT-CONTAINER-KIT#410)
  Add Label Selector to pod anti affinity  (OT-CONTAINER-KIT#407)
  When cr annotation update,sts annotations will not updated! (OT-CONTAINER-KIT#398)
  fix: invalid memory address or nil pointer dereference (OT-CONTAINER-KIT#395)
  export redis exporter as a container port (OT-CONTAINER-KIT#393)
  [Development][Add] Added feature for additional volume mounts (OT-CONTAINER-KIT#389)
  fix crash with go panic (OT-CONTAINER-KIT#385)
  Add check PersistenceEnabled not nil (OT-CONTAINER-KIT#380)
  [feature]add serviceType functionality for standalone and cluster with annotations (OT-CONTAINER-KIT#376)
  • Loading branch information
devkmsg committed Mar 7, 2023
2 parents 167c0d6 + 2ea8fca commit 8b233c9
Show file tree
Hide file tree
Showing 56 changed files with 11,117 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .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.13.0"
AppVersion: "v0.14.0"
GolangVersion: "1.17"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#### :beetle: Bug Fixes

- Fixed multiple follower logic for redis cluster
- Fixed CR's annotations updated,sts annotations will not updated

#### :tada: Features

Expand Down
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Build the manager binary
ARG ARCH="amd64"
FROM golang:1.17 as builder
ARG BUILDOS
ARG BUILDPLATFORM
ARG BUILDARCH
ARG BUILDVARIANT
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -17,11 +24,16 @@ COPY controllers/ controllers/
COPY k8sutils/ k8sutils/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=on go build -a -o manager main.go
ARG LDFLAGS="-s -w"
ENV GOOS=$TARGETOS
ENV GOARCH=$TARGETARCH
ENV CGO_ENABLED=0

RUN GO111MODULE=on go build -ldflags "${LDFLAGS}" -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot-${ARCH}
FROM gcr.io/distroless/static:nonroot
LABEL maintainer="The Opstree Opensource <opensource@opstree.com>"
WORKDIR /
COPY --from=builder /workspace/manager .
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Current Operator version
VERSION ?= 0.13.0
VERSION ?= 0.14.0
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
Expand Down Expand Up @@ -73,13 +73,16 @@ vet:
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

docker-create:
docker buildx create --platform "linux/amd64,linux/arm64" --use

# Build the docker image
docker-build:
docker build -t ${IMG} .
docker buildx build --platform="linux/arm64,linux/amd64" -t ${IMG} .

# Push the docker image
docker-push:
docker push ${IMG}
docker buildx build --push --platform="linux/arm64,linux/amd64" -t ${IMG} .

# Download controller-gen locally if necessary
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
Expand Down Expand Up @@ -116,4 +119,4 @@ bundle: manifests kustomize
# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
docker buildx build --platform="linux/arm64,linux/amd64" -f bundle.Dockerfile -t $(BUNDLE_IMG) .
15 changes: 15 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ type KubernetesConfig struct {
ExistingPasswordSecret *ExistingPasswordSecret `json:"redisSecret,omitempty"`
ImagePullSecrets *[]corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
UpdateStrategy appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty"`
Service *ServiceConfig `json:"service,omitempty"`
}

// ServiceConfig define the type of service to be created and its annotations
type ServiceConfig struct {
// +kubebuilder:validation:Enum=LoadBalancer;NodePort;ClusterIP
ServiceType string `json:"serviceType,omitempty"`
ServiceAnnotations map[string]string `json:"annotations,omitempty"`
}

// RedisConfig defines the external configuration of Redis
Expand All @@ -45,6 +53,13 @@ type ExistingPasswordSecret struct {
// Storage is the inteface to add pvc and pv support in redis
type Storage struct {
VolumeClaimTemplate corev1.PersistentVolumeClaim `json:"volumeClaimTemplate,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"`
MountPath []corev1.VolumeMount `json:"mountPath,omitempty"`
}

// RedisExporter interface will have the information for redis exporter related stuff
Expand Down
14 changes: 8 additions & 6 deletions api/v1beta1/rediscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ type RedisClusterSpec struct {
RedisFollower RedisFollower `json:"redisFollower,omitempty"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
Storage *Storage `json:"storage,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
TLS *TLSConfig `json:"TLS,omitempty"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
Expand All @@ -63,7 +61,9 @@ type RedisLeader struct {
// +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"`
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// RedisFollower interface will have the redis follower configuration
Expand All @@ -75,7 +75,9 @@ type RedisFollower struct {
// +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"`
LivenessProbe *Probe `json:"livenessProbe,omitempty" protobuf:"bytes,11,opt,name=livenessProbe"`
Tolerations *[]corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

// RedisClusterStatus defines the observed state of RedisCluster
Expand All @@ -89,8 +91,8 @@ type RedisPodDisruptionBudget struct {
MaxUnavailable *int32 `json:"maxUnavailable,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="ClusterSize",type=integer,JSONPath=`.spec.clusterSize`,description=Current cluster node count
// +kubebuilder:printcolumn:name="LeaderReplicas",type=integer,JSONPath=`.spec.redisLeader.replicas`,description=Overridden Leader replica count
// +kubebuilder:printcolumn:name="FollowerReplicas",type=integer,JSONPath=`.spec.redisFollower.replicas`,description=Overridden Follower replica count
Expand Down
60 changes: 60 additions & 0 deletions api/v1beta1/redisreplication_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package v1beta1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

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"`
// +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"`
}

func (cr *RedisReplicationSpec) GetReplicationCounts(t string) int32 {
replica := cr.Size
return *replica
}

// RedisStatus defines the observed state of Redis
type RedisReplicationStatus struct {
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Redis is the Schema for the redis API
type RedisReplication struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec RedisReplicationSpec `json:"spec"`
Status RedisReplicationStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// RedisList contains a list of Redis
type RedisReplicationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RedisReplication `json:"items"`
}

func init() {
SchemeBuilder.Register(&RedisReplication{}, &RedisReplicationList{})
}
78 changes: 78 additions & 0 deletions api/v1beta1/redissentinel_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package v1beta1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type RedisSentinelSpec struct {
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Default=3
// +kubebuilder:validation:Not=2
Size *int32 `json:"clusterSize"`
KubernetesConfig KubernetesConfig `json:"kubernetesConfig"`
RedisSentinelConfig *RedisSentinelConfig `json:"redisSentinelConfig,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"`
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"`
Sidecars *[]Sidecar `json:"sidecars,omitempty"`
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
}

func (cr *RedisSentinelSpec) GetSentinelCounts(t string) int32 {
replica := cr.Size
return *replica
}

type RedisSentinelConfig struct {
AdditionalSentinelConfig *string `json:"additionalSentinelConfig,omitempty"`
RedisReplicationName string `json:"redisReplicationName"`
// +kubebuilder:default:=myMaster
MasterGroupName string `json:"masterGroupName,omitempty"`
// +kubebuilder:default:="6379"
RedisPort string `json:"redisPort,omitempty"`
// +kubebuilder:default:="2"
Quorum string `json:"quorum,omitempty"`
// +kubebuilder:default:="1"
ParallelSyncs string `json:"parallelSyncs,omitempty"`
// +kubebuilder:default:="180000"
FailoverTimeout string `json:"failoverTimeout,omitempty"`
// +kubebuilder:default:="30000"
DownAfterMilliseconds string `json:"downAfterMilliseconds,omitempty"`
}

type RedisSentinelStatus struct {
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Redis is the Schema for the redis API
type RedisSentinel struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec RedisSentinelSpec `json:"spec"`
Status RedisSentinelStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// RedisList contains a list of Redis
type RedisSentinelList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RedisSentinel `json:"items"`
}

func init() {
SchemeBuilder.Register(&RedisSentinel{}, &RedisSentinelList{})
}
Loading

0 comments on commit 8b233c9

Please sign in to comment.