Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
Version alpha v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmxs committed May 8, 2020
1 parent 444dc01 commit 5532d45
Show file tree
Hide file tree
Showing 26 changed files with 883 additions and 18 deletions.
38 changes: 31 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
GIT_COMMIT_SHA:=$(shell git rev-parse HEAD 2>/dev/null)

IMG_REPO ?= quay.io/mhmxs
IMG_NAME ?= calico-route-reflector-controller
IMG_VERSION ?= latest

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"

Expand All @@ -13,6 +16,9 @@ endif

all: manager

_calculate-build-number:
$(eval export CONTAINER_VERSION?=$(GIT_COMMIT_SHA)-$(shell date "+%s"))

# Run tests
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
Expand All @@ -35,9 +41,19 @@ uninstall: manifests

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG}
cd config/manager && kustomize edit set image controller=$(IMG_REPO)/$(IMG_NAME):$(IMG_VERSION)
kustomize build config/default | kubectl apply -f -

# Undeploy deletes resources
undeploy:
kustomize build config/default | kubectl delete -f -

logs:
kubectl logs -n calico-route-reflector-operator-system $$(kubectl get po -A | grep calico-route-reflector-operator-system | awk '{print $$2}') manager

logs-f:
kubectl logs -f -n calico-route-reflector-operator-system $$(kubectl get po -A | grep calico-route-reflector-operator-system | awk '{print $$2}') manager

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
Expand All @@ -55,12 +71,20 @@ generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# Build the docker image
docker-build: test
docker build . -t ${IMG}
docker-build: _calculate-build-number test
docker build -t $(IMG_NAME):$(IMG_VERSION) .

dev-docker-build: _calculate-build-number test
docker build -t $(IMG_NAME):$(CONTAINER_VERSION) .

# Push the docker image
docker-push:
docker push ${IMG}
docker-push: docker-build
docker tag $(IMG_NAME):$(IMG_VERSION) $(IMG_REPO)/$(IMG_NAME):$(IMG_VERSION)
docker push $(IMG_REPO)/$(IMG_NAME):$(IMG_VERSION)

dev-docker-push: docker-build
docker tag $(IMG_NAME):$(CONTAINER_VERSION) $(IMG_REPO)/$(IMG_NAME):$(CONTAINER_VERSION)
docker push $(IMG_REPO)/$(IMG_NAME):$(CONTAINER_VERSION)

# find or download controller-gen
# download controller-gen if necessary
Expand Down
4 changes: 4 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
domain: calico-route-reflector-operator.mhmxs.github.com
repo: github.com/mhmxs/calico-route-reflector-operator
resources:
- group: route-reflector
kind: RouteReflectorConfig
version: v1
version: "2"
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# calico-route-reflector-operator
This Kubernetes operator can monitor and scale Calico route refloctor pods based on cluster size.
[![Go Report Card](https://goreportcard.com/badge/github.com/mhmxs/calico-route-reflector-operator)](https://goreportcard.com/report/mhmxs/calico-route-reflector-operator) [![Active](http://img.shields.io/badge/Status-Active-green.svg)](https://github.com/mhmxs/calico-route-reflector-operator) [![PR's Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](https://github.com/mhmxs/calico-route-reflector-operator/pulls) [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

# Calico Route Reflector Operator

This project is work in progress !!!
Use your own risk !!!

This Kubernetes operator can monitor and scale Calico route refloctor pods based on cluster size. The operator has a few environment variable:
* `ROUTE_REFLECTOR_MIN` Minimum number of route reflector pods, default `3`
* `ROUTE_REFLECTOR_MAX` Maximum number of route reflector pods, default `10`
* `ROUTE_REFLECTOR_RATIO` Node / route reflector pod ratio, default `0.2` (`100 * 0.2 = 20`)
* `ROUTE_REFLECTOR_NODE_LABEL` Node label of the route reflector nodes, default `calico-route-reflector=`
// * `ROUTE_REFLECTOR_ZONE_LABEL` Node label of the zone, default `""`
// * `ROUTE_REFLECTOR_PROTECTED` Node label of the nodes where route reflector pods are not allowed, default `""`

During the `api/core/v1/Node` reconcile phases it calculates the right number of route refloctor pods by multiply the number of nodes with the given ratio.
It updates the route reflector replicas to the expected number.
// If the given `ROUTE_REFLECTOR_ZONE_LABEL` is not empty, the operator balancing route reflector pods between the zones.

## Build

This is a standard Kubebuilder opertor so building and deploying process is similar as a (stock Kubebuilder project)[https://book.kubebuilder.io/cronjob-tutorial/running.html].

`IMG_REPO=[IMG_REPO] IMG_NAME=[IMG_NAME] IMG_VERSION=[IMG_VERSION] make docker-push install deploy`
36 changes: 36 additions & 0 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1 contains API Schema definitions for the route-reflector v1 API group
// +kubebuilder:object:generate=true
// +groupName=route-reflector.calico-route-reflector-operator.mhmxs.github.com
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "route-reflector.calico-route-reflector-operator.mhmxs.github.com", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
63 changes: 63 additions & 0 deletions api/v1/routereflectorconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// RouteReflectorConfigSpec defines the desired state of RouteReflectorConfig
type RouteReflectorConfigSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of RouteReflectorConfig. Edit RouteReflectorConfig_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

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

// +kubebuilder:object:root=true

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

Spec RouteReflectorConfigSpec `json:"spec,omitempty"`
Status RouteReflectorConfigStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&RouteReflectorConfig{}, &RouteReflectorConfigList{})
}
114 changes: 114 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: routereflectorconfigs.route-reflector.calico-route-reflector-operator.mhmxs.github.com
spec:
group: route-reflector.calico-route-reflector-operator.mhmxs.github.com
names:
kind: RouteReflectorConfig
listKind: RouteReflectorConfigList
plural: routereflectorconfigs
singular: routereflectorconfig
scope: Namespaced
validation:
openAPIV3Schema:
description: RouteReflectorConfig is the Schema for the routereflectorconfigs
API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: RouteReflectorConfigSpec defines the desired state of RouteReflectorConfig
properties:
foo:
description: Foo is an example field of RouteReflectorConfig. Edit RouteReflectorConfig_types.go
to remove/update
type: string
type: object
status:
description: RouteReflectorConfigStatus defines the observed state of RouteReflectorConfig
type: object
type: object
version: v1
versions:
- name: v1
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
21 changes: 21 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/route-reflector.calico-route-reflector-operator.mhmxs.github.com_routereflectorconfigs.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_routereflectorconfigs.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_routereflectorconfigs.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
Loading

0 comments on commit 5532d45

Please sign in to comment.