Skip to content

Commit

Permalink
Add pod spec to the CR (#56)
Browse files Browse the repository at this point in the history
- Refactored the CR and pod creation to use a pod spec for Redis pods
- Improved the waiting for pod creation
- Removed the headless service
- Removed option to toggle hugepages
- Cleaned up unused kustomize configuration
- Upgraded Golang version from 1.14 to 1.15
  • Loading branch information
voltbit authored Jan 18, 2021
1 parent e35c1a9 commit ff23a6c
Show file tree
Hide file tree
Showing 52 changed files with 9,382 additions and 5,899 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.14
- image: circleci/golang:1.15
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.14 as builder
FROM golang:1.15 as builder

ARG DEBIAN_FRONTEND=noninteractive

Expand Down
13 changes: 1 addition & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ OPERATOR_NAMESPACE ?= "default"
METRICS_ADDR ?= ":8080"
ENABLE_LEADER_ELECTION ?= "true"

# Used to specify what environment is targeted, it determines what kustomize config is built
# by default it builds the config for the local kind cluster.
# To build for development/production environment run with envconfig=production.
ifeq ($(envconfig), production)
CONFIG_ENV = config-build-production
endif

ifdef NOTEST
TEST := skip
endif
Expand Down Expand Up @@ -72,16 +65,12 @@ config-build: $(CONFIG_ENV)
config-build-local:
kustomize build config/default | kubectl apply -f -

# Use kustomize to build the YAML configuration files for the development cluster
config-build-production:
(cd config/production && kustomize edit set image controller=$(IMG)) && kustomize build config/production | kubectl apply -f -

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy-default: generate manifests config-build docker-build-operator docker-build-local-redis docker-build-local-redis-init docker-build-local-metrics-exporter kind-load-all

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-clusterrole webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager paths="./..." output:crd:artifacts:config=config/crd/bases

# Run go fmt against code
fmt:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ If you are missing an image in the cluster, an easy way to build and load all ne

The Helm chart was developed with Helm v3, it might work with v2 but it was not tested as such.
The chart can create the CRD, Redis operator and RedisCluster CR and it has feature flags for all of them plus the RBAC setup.
Use example:

Examples:

```
# create everything in the default namespace
Expand Down Expand Up @@ -86,7 +87,7 @@ To develop directly on a deployed operator without rebuilding and loading/deploy
2. Swap the dev image with the operator deploy using Telepresence

```
telepresence --mount /tmp/podtoken --context kind-redis-test --namespace default --swap-deployment redis-operator-controller-manager --docker-run --rm -it -v $(pwd):/app -v=/tmp/podtoken/var/run/secrets:/var/run/secrets redis-operator:dev
telepresence --mount /tmp/podtoken --context kind-redis-test --namespace default --swap-deployment redis-operator-manager --docker-run --rm -it -v $(pwd):/app -v=/tmp/podtoken/var/run/secrets:/var/run/secrets redis-operator:dev
```

**How it works**
Expand Down
54 changes: 20 additions & 34 deletions api/v1/rediscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,50 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// PodLabelSelector will use to identify
// which pod our controller needs to maintain
type PodLabelSelector struct {
App string `json:"app"`
}

// TopologyKeys defines the topology keys used inside affinity rules
type TopologyKeys struct {
HostTopologyKey string `json:"hostTopologyKey,omitempty"`
ZoneTopologyKey string `json:"zoneTopologyKey,omitempty"`
}

// RedisClusterSpec defines the desired state of RedisCluster
// RedisClusterSpec defines the desired state of RedisCluster.
type RedisClusterSpec struct {

// +kubebuilder:validation:Minimum=3
// The number of leader instances to run
// The number of leader instances to run.
LeaderCount int `json:"leaderCount,omitempty"`

// +optional
// +kubebuilder:validation:Minimum=0
// The number of followers that each leader will have
// The number of followers that each leader will have.
LeaderFollowersCount int `json:"leaderFollowersCount,omitempty"`

// +optional
// modify kernel setting regarding backlogged sockets and transparent huge pages.
InitContainer corev1.Container `json:"initContainer,omitempty"`

Redis corev1.Container `json:"redis"`
// Flag that toggles the default affinity rules added by the operator.
// Default is true.
EnableDefaultAffinity bool `json:"enableDefaultAffinity,omitempty"`

PrometheusExporter corev1.Container `json:"prometheusExporter,omitempty"`

PodLabelSelector PodLabelSelector `json:"podLabelSelector"`

PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
// +optional
// Annotations for the Redis pods.
Annotations map[string]string `json:"annotations,omitempty"`

ImagePullSecrets string `json:"imagePullSecrets,omitempty"`
// Labels used by the operator to get the pods that it manages. Added by default
// to the list of labels of the Redis pod.
PodLabelSelector map[string]string `json:"podLabelSelector"`

EnableHugePages bool `json:"enableHugePages,omitempty"`
// +optional
// Labels for the Redis pods.
Labels map[string]string `json:"labels,omitempty"`

Affinity TopologyKeys `json:"affinity,omitempty"`
// PodSpec for Redis pods.
RedisPodSpec corev1.PodSpec `json:"redisPodSpec"`
}

// RedisClusterStatus defines the observed state of RedisCluster
type RedisClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// A list of pointers to currently running pods.
// +optional
Pods []corev1.ObjectReference `json:"active,omitempty"`

// the current state of the cluster
// The current state of the cluster.
// +optional
ClusterState string `json:"clusterState,omitempty"`

// the total expected pod number when
// the cluster is ready and stable
// The total expected pod number when the cluster is ready and stable.
// +optional
TotalExpectedPods int `json:"totalExpectedPods,omitempty"`
}
Expand All @@ -87,7 +73,7 @@ type RedisClusterStatus struct {
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=rdc

// RedisCluster is the Schema for the redisclusters API
// RedisCluster is the Schema for the redisclusters API.
type RedisCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
54 changes: 17 additions & 37 deletions api/v1/zz_generated.deepcopy.go

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

26 changes: 0 additions & 26 deletions config/certmanager/certificate.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions config/certmanager/kustomization.yaml

This file was deleted.

16 changes: 0 additions & 16 deletions config/certmanager/kustomizeconfig.yaml

This file was deleted.

Loading

0 comments on commit ff23a6c

Please sign in to comment.