Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pych/redis-operator into add-sidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
samof76 committed Aug 31, 2022
2 parents 4fe8632 + a5f0462 commit f151b69
Show file tree
Hide file tree
Showing 3,079 changed files with 714 additions and 1,026,069 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
ignore:
# Ignore Kubernetes dependencies to have full control on them.
- dependency-name: "k8s.io/*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
22 changes: 13 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,36 @@ jobs:
# Execute the checks inside the container instead the VM.
container: golangci/golangci-lint:v1.43.0-alpine
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: ./scripts/check.sh

unit-test:
name: Unit test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.17
- run: make ci-unit-test

integration-test:
name: Integration test
runs-on: ubuntu-latest
needs: [check, unit-test]
strategy:
matrix:
kubernetes: [1.22.12, 1.23.9, 1.24.3]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.17
- name: Install conntrack
run: sudo apt-get install -y conntrack
- uses: medyagh/[email protected].7
- uses: medyagh/[email protected].8
with:
kubernetes-version: 1.22.2
kubernetes-version: ${{ matrix.kubernetes }}
driver: none
- name: Add redisfailover CRD
run: kubectl create -f manifests/databases.spotahome.com_redisfailovers.yaml
Expand All @@ -48,12 +52,12 @@ jobs:
name: Chart testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install Helm
uses: azure/setup-helm@v1
uses: azure/setup-helm@v3
with:
version: v3.7.2

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git
Expand All @@ -18,12 +18,12 @@ jobs:
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Install Helm
uses: azure/setup-helm@v1
uses: azure/setup-helm@v3
with:
version: v3.7.2

- name: Release
uses: helm/chart-releaser-action@v1.2.1
uses: helm/chart-releaser-action@v1.4.0
with:
charts_dir: charts
config: charts/chart-release-config.yaml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staleissues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v3
- uses: actions/stale@v5
with:
days-before-issue-stale: 45
days-before-issue-close: 14
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/bin
.bash_history
.vscode
.idea/
6 changes: 3 additions & 3 deletions api/redisfailover/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package v1
const (
defaultRedisNumber = 3
defaultSentinelNumber = 3
defaultSentinelExporterImage = "quay.io/oliver006/redis_exporter:v1.33.0-alpine"
defaultExporterImage = "quay.io/oliver006/redis_exporter:v1.33.0-alpine"
defaultSentinelExporterImage = "quay.io/oliver006/redis_exporter:v1.43.0"
defaultExporterImage = "quay.io/oliver006/redis_exporter:v1.43.0"
defaultImage = "redis:6.2.6-alpine"
defaultRedisPort = "6379"
defaultRedisPort = 6379
)

var (
Expand Down
1 change: 1 addition & 0 deletions api/redisfailover/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type RedisSettings struct {
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
Port int32 `json:"port,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
CustomConfig []string `json:"customConfig,omitempty"`
CustomCommandRenames []RedisCommandRename `json:"customCommandRenames,omitempty"`
Expand Down
7 changes: 6 additions & 1 deletion api/redisfailover/v1/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1
import (
"errors"
"fmt"
"strconv"
)

const (
Expand All @@ -22,7 +23,7 @@ func (r *RedisFailover) Validate() error {
}

if r.Spec.BootstrapNode.Port == "" {
r.Spec.BootstrapNode.Port = defaultRedisPort
r.Spec.BootstrapNode.Port = strconv.Itoa(defaultRedisPort)
}
initialRedisCustomConfig = bootstrappingRedisCustomConfig
}
Expand All @@ -41,6 +42,10 @@ func (r *RedisFailover) Validate() error {
r.Spec.Redis.Replicas = defaultRedisNumber
}

if r.Spec.Redis.Port <= 0 {
r.Spec.Redis.Port = defaultRedisPort
}

if r.Spec.Sentinel.Replicas <= 0 {
r.Spec.Sentinel.Replicas = defaultSentinelNumber
}
Expand Down
1 change: 1 addition & 0 deletions api/redisfailover/v1/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestValidate(t *testing.T) {
Redis: RedisSettings{
Image: defaultImage,
Replicas: defaultRedisNumber,
Port: defaultRedisPort,
Exporter: RedisExporter{
Image: defaultExporterImage,
},
Expand Down
42 changes: 42 additions & 0 deletions api/redisfailover/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions charts/redisoperator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ spec:
{{- include "chart.selectorLabels" $data | nindent 8 }}
spec:
serviceAccountName: {{ template "chart.serviceAccountName" . }}
{{- if .Values.imageCredentials.create }}
imagePullSecrets:
{{- if (and .Values.imageCredentials.create (not .Values.imageCredentials.existsSecrets)) }}
imagePullSecrets:
- name: {{ $fullName }}-{{ $name }}
{{- else if (and .Values.imageCredentials.create .Values.imageCredentials.existsSecrets) }}
{{- range .Values.imageCredentials.existsSecrets }}
imagePullSecrets:
{{ printf "- name: %s" . }}
{{- end }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
Expand Down Expand Up @@ -70,4 +75,3 @@ spec:
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}

2 changes: 1 addition & 1 deletion charts/redisoperator/templates/private-registry.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.imageCredentials.create -}}
{{- if (and .Values.imageCredentials.create (not .Values.imageCredentials.existsSecrets)) -}}
{{- $fullName := include "chart.fullname" . -}}
{{- $name := "registry" -}}
{{- $data := dict "name" $name "Chart" .Chart "Release" .Release "Values" .Values -}}
Expand Down
7 changes: 5 additions & 2 deletions charts/redisoperator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ imageCredentials:
username: someone
password: somepassword
email: [email protected]
# Use exists secrets in namespace
existsSecrets:
- registrysecret

updateStrategy:
updateStrategy:
type: RollingUpdate

# A name in place of the chart name for `app:` labels.
nameOverride: ""

Expand Down
31 changes: 28 additions & 3 deletions cmd/redisoperator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -74,19 +76,22 @@ func (m *Main) Run() error {
}()

// Kubernetes clients.
stdclient, customclient, aeClientset, err := utils.CreateKubernetesClients(m.flags)
k8sClient, customClient, aeClientset, err := utils.CreateKubernetesClients(m.flags)
if err != nil {
return err
}

// Create kubernetes service.
k8sservice := k8s.New(stdclient, customclient, aeClientset, m.logger)
k8sservice := k8s.New(k8sClient, customClient, aeClientset, m.logger)

// Create the redis clients
redisClient := redis.New()

// Get lease lock resource namespace
lockNamespace := getNamespace()

// Create operator and run.
redisfailoverOperator, err := redisfailover.New(m.flags.ToRedisOperatorConfig(), k8sservice, redisClient, metricsRecorder, m.logger)
redisfailoverOperator, err := redisfailover.New(m.flags.ToRedisOperatorConfig(), k8sservice, k8sClient, lockNamespace, redisClient, metricsRecorder, m.logger)
if err != nil {
return err
}
Expand Down Expand Up @@ -124,6 +129,26 @@ func (m *Main) stop(stopC chan struct{}) {
time.Sleep(gracePeriod)
}

func getNamespace() string {
// This way assumes you've set the POD_NAMESPACE environment
// variable using the downward API. This check has to be done first
// for backwards compatibility with the way InClusterConfig was
// originally set up
if ns, ok := os.LookupEnv("POD_NAMESPACE"); ok {
return ns
}

// Fall back to the namespace associated with the service account
// token, if available
if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
return ns
}
}

return "default"
}

// Run app.
func main() {
logger := log.Base()
Expand Down
4 changes: 3 additions & 1 deletion docker/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ RUN apk --no-cache add \
WORKDIR /src
COPY . .

ARG TARGETOS TARGETARCH VERSION
ARG TARGETOS
ARG TARGETARCH
ARG VERSION
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH VERSION=$VERSION ./scripts/build.sh

FROM alpine:latest
Expand Down
Loading

0 comments on commit f151b69

Please sign in to comment.