Skip to content

Commit

Permalink
Merge pull request #2 from Gsantomaggio/add_persistence
Browse files Browse the repository at this point in the history
Add persistence
  • Loading branch information
Gsantomaggio authored Dec 24, 2019
2 parents ab45c4e + 29671fa commit 5b3781a
Show file tree
Hide file tree
Showing 16 changed files with 656 additions and 205 deletions.
84 changes: 27 additions & 57 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,33 @@
language: go

go:
- '1.13'

- '1.13'
services:
- docker

- docker
install:
- export GOPROXY=https://proxy.golang.org
- go install github.com/onsi/ginkgo/ginkgo
- export PATH=$PATH:$GOPATH/bin
- curl -sL https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.2.0/kubebuilder_2.2.0_linux_amd64.tar.gz | tar -xz -C /tmp/
- sudo mv /tmp/kubebuilder_2.2.0_linux_amd64 /usr/local/kubebuilder
- export PATH=$PATH:/usr/local/kubebuilder/bin

- export GOPROXY=https://proxy.golang.org
- go install github.com/onsi/ginkgo/ginkgo
- export PATH=$PATH:$GOPATH/bin
- curl -sL https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.2.0/kubebuilder_2.2.0_linux_amd64.tar.gz
| tar -xz -C /tmp/
- sudo mv /tmp/kubebuilder_2.2.0_linux_amd64 /usr/local/kubebuilder
- export PATH=$PATH:/usr/local/kubebuilder/bin
jobs:
include:
- stage: Unit Tests
script: make test

- stage: Cluster Tests
before_script:
# Download and install kubectl
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

- curl -Lo kind curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/v0.6.0/kind-linux-amd64 && chmod +x kind && sudo mv kind /usr/local/bin/
- export PATH=$PATH:/usr/local/bin
- kind create cluster
- export KUBECONFIG="$(kind get kubeconfig-path)"
script: USE_EXISTING_CLUSTER=true make test
# # Download and install helm
# - curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
# - chmod 700 get_helm.sh
# - sudo ./get_helm.sh
# # yes, heredocs are broken in before_script: https://travis-ci.community/t/multiline-commands-have-two-spaces-in-front-breaks-heredocs/2756
# - |
# sed 's/^ //' <<\ \ EOF > tiller.yml
# ---
# apiVersion: v1
# kind: ServiceAccount
# metadata:
# name: tiller
# namespace: kube-system
# ---
# apiVersion: rbac.authorization.k8s.io/v1
# kind: ClusterRoleBinding
# metadata:
# name: tiller
# roleRef:
# apiGroup: rbac.authorization.k8s.io
# kind: ClusterRole
# name: cluster-admin
# subjects:
# - kind: ServiceAccount
# name: tiller
# namespace: kube-system
# EOF
# - kubectl create -f tiller.yml
# - helm init --service-account tiller --wait



- stage: cover
script: make cover_travis
- stage: Unit Tests
script: make test
- stage: Cluster Tests
before_script:
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s
https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
&& chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- curl -Lo kind curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/v0.6.0/kind-linux-amd64
&& chmod +x kind && sudo mv kind /usr/local/bin/
- export PATH=$PATH:/usr/local/bin
- kind create cluster
- export KUBECONFIG="$(kind get kubeconfig-path)"
script: USE_EXISTING_CLUSTER=true make test
env:
global:
secure: P2RvtKakKme14c9imzSRiIUBuiNh8+higkrXICtFSqefW7rr49MBiwijcDCtmnx9zFIcI10WK/NUB0sC4uZU9UOnJZvQvGAirsFvjsJlHS+tCsbyAl1t0PynOdAwzBeYvFqVaLhoith4Sx7mbDSibNNWnzRKwDKVD8KGcslKKyoNqR2HVO23YJrJdvYoyn1sMc5TSJf7wGMlwo0+h+cymgUzQx4lG/zRgIN/tcK0rN+3Pbm4fflcdLhZo13fs2K4dXvuiXz5puKYByBMipRXyyGQAgY17jRctsfgqKVqpiXdjC6rQBTaYL7LhbnIIA2q518pcH5cipj6T6bTW/wEvgpQQWViauCdxLWAhKKNAxkwGXlEWPwpUUsxvcad6MzaQn2umCPQjTLWGBUQUCNtjxe3ukzCXdV48vD2uobN2hKQzjIZqeQVUUqhpmhZtjJoPb8nQ4zy2q0OLsyI+k8/mdJYOa2e8xht8Vyu0uQjiFgTkdPkR7y7xq9fpiapdKZXl690FVxYYxbB5/rtFcJU/fWinaKmDYnVZOwxwKUIiQktl1cS9U8Mw3n9HVxwD5E0mNzZjZEzitQA3AxOf4ZOLYGiIDy4dxwKnLcXNgkLTlwV1WDlYcWymM2kdj98LFPReaR/ki5z22+PLDcx7s2DBLnxF02vt86bBXAxZgyZFYs=
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ endif

all: manager


# Run Tests with cover
cover_travis: generate fmt vet manifests
go get golang.org/x/tools/cmd/cover
go get github.com/mattn/goveralls
go test ./... -covermode=count -coverprofile=coverage.out
$$(go env GOPATH | awk 'BEGIN{FS=":"} {print $$1}')/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $$COVERALLS_TOKEN

# Run Tests with cover
cover: test
go tool cover -html=cover.out

# Run tests
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# RabbitMQ Kubernetes Operator

[![Build Status](https://travis-ci.org/Gsantomaggio/rabbitmq-operator.svg?branch=master)](https://travis-ci.org/Gsantomaggio/rabbitmq-operator)
[![Build Status](https://travis-ci.org/Gsantomaggio/rabbitmq-operator.svg?branch=master)](https://travis-ci.org/Gsantomaggio/rabbitmq-operator) [![Coverage Status](https://coveralls.io/repos/github/Gsantomaggio/rabbitmq-operator/badge.svg?branch=add_persistence)](https://coveralls.io/github/Gsantomaggio/rabbitmq-operator?branch=add_persistence)


Kubernetes Operator to handle the RabbitMQ deploy.

Expand Down
16 changes: 12 additions & 4 deletions api/v1alpha/rabbitmq_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,23 @@ type CheckProbe struct {
TimeoutSeconds int32 `json:"timeoutSeconds"`
}

type PersistentVolumeClaimSpec struct {
StorageClass string `json:"storageClass"`
Name string `json:"name"`
AccessModes []v1.PersistentVolumeAccessMode `json:"accessModes"`
Resources v1.ResourceRequirements `json:"resources"`
}

// RabbitMQSpec defines the desired state of RabbitMQ
type RabbitMQSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Template v1.StatefulSet `json:"template"`
Replicas int32 `json:"replicas"`
Template TemplateSpec `json:"template,omitempty"`
ServiceDefinition ServiceDefinition `json:"serviceDefinition"`
ConfigMap string `json:"configMap"`
Replicas int32 `json:"replicas"`
Template TemplateSpec `json:"template,omitempty"`
ServiceDefinition ServiceDefinition `json:"serviceDefinition"`
ConfigMap string `json:"configMap"`
PersistentVolume PersistentVolumeClaimSpec `json:"persistentVolume"`
}

// RabbitMQStatus defines the observed state of RabbitMQ
Expand Down
36 changes: 36 additions & 0 deletions config/crd/bases/scaling.queues_rabbitmqs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ spec:
properties:
configMap:
type: string
persistentVolume:
properties:
accessModes:
items:
type: string
type: array
name:
type: string
resources:
description: ResourceRequirements describes the compute resource
requirements.
properties:
limits:
additionalProperties:
type: string
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
type: string
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
storageClass:
type: string
required:
- accessModes
- name
- resources
- storageClass
type: object
replicas:
description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
Important: Run "make" to regenerate code after modifying this file
Expand Down Expand Up @@ -107,6 +142,7 @@ spec:
type: object
required:
- configMap
- persistentVolume
- replicas
- serviceDefinition
type: object
Expand Down
8 changes: 7 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ rules:
- events
verbs:
- create
- patch
- patch
- apiGroups: [""]
resources:
- persistentvolumes
verbs:
- list

7 changes: 7 additions & 0 deletions config/samples/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ spec:
replicas: 3
serviceDefinition: Internal
configMap: rabbitmq-config
persistentVolume:
name: data
accessModes: [ "ReadWriteOnce" ]
storageClass: "standard"
resources:
requests:
storage: 1Gi
template:
spec:
contaniers:
Expand Down
4 changes: 0 additions & 4 deletions controllers/rabbitmq_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ var (
terminationGracePeriodSeconds = int64(10)
)

// func labelsForRabbitMQ(name string) map[string]string {
// return map[string]string{"app": "rabbitmq-operator", "rabbitmq_cr": name}
// }

func labelSelector(labels map[string]string) *metav1.LabelSelector {
return &metav1.LabelSelector{MatchLabels: labels}
}
Expand Down
8 changes: 4 additions & 4 deletions controllers/rabbitmq_controller_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"

"github.com/go-logr/logr"
scalingv1 "github.com/gsantomaggio/rabbitmq-operator/api/v1alpha"
opv1alpha "github.com/gsantomaggio/rabbitmq-operator/api/v1alpha"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -46,7 +46,7 @@ type RabbitMQReconcilerCreate struct {
// Reconcile handles the reconcile
func (r *RabbitMQReconcilerCreate) Reconcile(req ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
logRmq := r.Log.WithValues("rabbitmq_w", req.NamespacedName)
logRmq := r.Log.WithValues("RabbitmqCreate", req.NamespacedName)
logRmq.Info("Handling Create RabbitMQReconciler ")

instance, err := getRabbitMQInstanceResource(r.Recorder, r.Client, req)
Expand All @@ -63,7 +63,7 @@ func (r *RabbitMQReconcilerCreate) Reconcile(req ctrl.Request) (ctrl.Result, err
if err != nil && errors.IsNotFound(err) {
service := &corev1.Service{}

if instance.Spec.ServiceDefinition == scalingv1.Internal {
if instance.Spec.ServiceDefinition == opv1alpha.Internal {
serv, errSrv := newService(instance, r)
errSrv = r.Create(context.TODO(), serv.DeepCopy())
if errSrv != nil && errors.IsAlreadyExists(errSrv) == false {
Expand Down Expand Up @@ -117,7 +117,7 @@ func (r *RabbitMQReconcilerCreate) SetupWithManager(mgr ctrl.Manager) error {
}

c := ctrl.NewControllerManagedBy(mgr)
return c.For(&scalingv1.RabbitMQ{}).
return c.For(&opv1alpha.RabbitMQ{}).
Named("RabbitMQCreate").
WithEventFilter(p).
Complete(r)
Expand Down
9 changes: 8 additions & 1 deletion controllers/rabbitmq_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand Down Expand Up @@ -43,7 +44,13 @@ var _ = Describe("RabbitMQ Controller", func() {
Namespace: key.Namespace,
},
Spec: scalingv1.RabbitMQSpec{
Replicas: 3,
Replicas: 3,
ConfigMap: "TEST",
ServiceDefinition: "Internal",
PersistentVolume: scalingv1.PersistentVolumeClaimSpec{
StorageClass: "standard",
AccessModes: []v1.PersistentVolumeAccessMode{"ReadWriteOnce"},
},
Template: scalingv1.TemplateSpec{
Spec: scalingv1.ContainerSpec{
Contaniers: scalingv1.ContainerDetailsSpec{
Expand Down
4 changes: 2 additions & 2 deletions controllers/rabbitmq_controller_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"

"github.com/go-logr/logr"
scalingv1 "github.com/gsantomaggio/rabbitmq-operator/api/v1alpha"
opv1alpha "github.com/gsantomaggio/rabbitmq-operator/api/v1alpha"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -95,7 +95,7 @@ func (r *RabbitMQReconcilerUpdate) SetupWithManager(mgr ctrl.Manager) error {
}

c := ctrl.NewControllerManagedBy(mgr)
return c.For(&scalingv1.RabbitMQ{}).
return c.For(&opv1alpha.RabbitMQ{}).
Named("RabbitMQUpdate").
WithEventFilter(p).
Complete(r)
Expand Down
Loading

0 comments on commit 5b3781a

Please sign in to comment.