Skip to content

Instantly share code, notes, and snippets.

View mmontes11's full-sized avatar
🦭
Incubating mariadb-operator

Martin Montes mmontes11

🦭
Incubating mariadb-operator
View GitHub Profile
@mmontes11
mmontes11 / hello-world-echo-crd.yml
Created July 31, 2021 15:49
Hello world Echo CRD
apiVersion: mmontes.io/v1alpha1
kind: Echo
metadata:
name: hello-world
namespace: default
spec:
message: "Hola, 世界!"
@mmontes11
mmontes11 / operator-rbac.yml
Last active July 31, 2021 11:20
Operator RBAC
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "echoperator.fullname" . }}
labels:
{{- include "echoperator.labels" . | nindent 4 }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
@mmontes11
mmontes11 / operator-deployment.yml
Last active July 31, 2021 11:21
Operator deployment
{{ $fullName := include "echoperator.fullname" . }}
{{ $selectorLabels := include "echoperator.selectorLabels" . }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $fullName }}
labels:
{{ include "echoperator.labels" . | nindent 4 }}
spec:
{{ if .Values.ha.enabled}}
@mmontes11
mmontes11 / operator-configmap.yml
Created July 31, 2021 10:32
Operator configmap
{{ $fullName := include "echoperator.fullname" . }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $fullName }}
labels:
{{ include "echoperator.labels" . | nindent 4 }}
data:
NAMESPACE: {{ .Release.Namespace }}
NUM_WORKERS: {{ .Values.numWorkers | quote }}
@mmontes11
mmontes11 / operator-values.yml
Created July 31, 2021 10:25
Operator values
nameOverride: ""
fullnameOverride: ""
image:
repository: mmontes11/echoperator
pullPolicy: IfNotPresent
tag: v0.0.1
env: production
@mmontes11
mmontes11 / runner.go
Created July 31, 2021 08:14
Controller runner
type Runner struct {
ctrl *controller.Controller
clientset *kubernetes.Clientset
config config.Config
logger log.Logger
}
func (r *Runner) Start(ctx context.Context) {
if r.config.HA.Enabled {
r.logger.Info("starting HA controller")
@mmontes11
mmontes11 / worker-resource.go
Last active February 22, 2023 21:59
Worker controller resource
import (
echo "github.com/mmontes11/echoperator/pkg/echo"
echov1alpha1 "github.com/mmontes11/echoperator/pkg/echo/v1alpha1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func createJob(newEcho *echov1alpha1.Echo, namespace string) *batchv1.Job {
return &batchv1.Job{
@mmontes11
mmontes11 / worker.go
Created July 30, 2021 14:38
Worker controller
func (c *Controller) runWorker(ctx context.Context) {
for c.processNextItem(ctx) {
}
}
func (c *Controller) processNextItem(ctx context.Context) bool {
obj, shutdown := c.queue.Get()
if shutdown {
return false
}
@mmontes11
mmontes11 / controller.go
Last active July 30, 2021 11:04
Kubernetes controller
type Controller struct {
kubeClientSet kubernetes.Interface
echoInformer cache.SharedIndexInformer
jobInformer cache.SharedIndexInformer
scheduledEchoInformer cache.SharedIndexInformer
cronjobInformer cache.SharedIndexInformer
queue workqueue.RateLimitingInterface
@mmontes11
mmontes11 / k8s-api-conn.go
Last active July 30, 2021 10:18
Connect to Kubernetes API
var restConfig *rest.Config
var errKubeConfig error
if config.KubeConfig != "" {
restConfig, errKubeConfig = clientcmd.BuildConfigFromFlags("", config.KubeConfig)
} else {
restConfig, errKubeConfig = rest.InClusterConfig()
}
if errKubeConfig != nil {
logger.Fatal("error getting kubernetes config ", err)
}