diff --git a/Makefile b/Makefile index b91b9ce325b..778e4376383 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION ?= $(shell git rev-parse --verify HEAD) GOOS ?= $(shell go env | grep GOOS | cut -d'"' -f2) -BINARIES := apiserver kubernikus kubernikusctl wormhole play +BINARIES := apiserver kubernikus kubernikusctl wormhole LDFLAGS := -X github.com/sapcc/kubernikus/pkg/version.GitCommit=$(VERSION) GOFLAGS := -ldflags "$(LDFLAGS) -s -w" diff --git a/cmd/play/main.go b/cmd/play/main.go deleted file mode 100644 index 289d562cff4..00000000000 --- a/cmd/play/main.go +++ /dev/null @@ -1,166 +0,0 @@ -package main - -import ( - "fmt" - "os" - "time" - - "github.com/go-kit/kit/log" -) - -type Kluster struct { - Name string - Pool []string -} - -var KLUSTER = []Kluster{ - Kluster{"fabus", []string{"mypool"}}, - Kluster{"esther", []string{"swimmingpool"}}, - Kluster{"michi", []string{"poo", "pool"}}, - Kluster{"marian", []string{"schwarz", "weiss"}}, -} - -var RECONCILLIATION_COUNTER = 0 - -type Controller interface { - Run() -} - -type Reconciler interface { - Reconcile(Kluster) (bool, error) -} - -type controller struct { - Reconciler Reconciler - Logger log.Logger -} - -func (c *controller) Run() { - c.Logger.Log("msg", "running") - - for _, kluster := range KLUSTER { - requeue, _ := c.Reconciler.Reconcile(kluster) - if requeue { - c.Logger.Log("msg", "requeue requested", "kluster", kluster.Name) - c.Reconciler.Reconcile(kluster) - } - } -} - -type loggingReconciler struct { - Reconciler Reconciler - Logger log.Logger -} - -type eventingReconciler struct { - Reconciler -} - -type instrumentedReconciler struct { - Reconciler -} - -type launchReconciler struct { - Logger log.Logger -} - -type groundReconciler struct { - Logger log.Logger -} - -func NewLaunchControl(logger log.Logger) Controller { - logger = log.With(logger, "controller", "launch") - - var reconciler Reconciler - reconciler = &launchReconciler{logger} - reconciler = &loggingReconciler{reconciler, logger} - reconciler = &eventingReconciler{reconciler} - reconciler = &instrumentedReconciler{reconciler} - - return &controller{reconciler, logger} -} - -func NewGroundControl(logger log.Logger) Controller { - logger = log.With(logger, "controller", "ground") - - var reconciler Reconciler - reconciler = &groundReconciler{logger} - reconciler = &loggingReconciler{reconciler, logger} - reconciler = &eventingReconciler{reconciler} - reconciler = &instrumentedReconciler{reconciler} - - return &controller{reconciler, logger} -} - -func (r *instrumentedReconciler) Reconcile(kluster Kluster) (requeue bool, err error) { - defer func() { - RECONCILLIATION_COUNTER = RECONCILLIATION_COUNTER + 1 - fmt.Printf("Metrics: Reconciled %v kluster\n", RECONCILLIATION_COUNTER) - }() - return r.Reconciler.Reconcile(kluster) -} - -func (r *eventingReconciler) Reconcile(kluster Kluster) (requeue bool, err error) { - fmt.Printf("EVENT: Reconciled %v\n", kluster.Name) - return r.Reconciler.Reconcile(kluster) -} - -func (r *loggingReconciler) Reconcile(kluster Kluster) (requeue bool, err error) { - defer func(begin time.Time) { - r.Logger.Log( - "msg", "reconciled kluster", - "kluster", kluster.Name, - "reqeue", requeue, - "took", time.Since(begin), - "err", err) - }(time.Now()) - return r.Reconciler.Reconcile(kluster) -} - -func (r *launchReconciler) Reconcile(kluster Kluster) (requeue bool, err error) { - if kluster.Name == "michi" { - return false, fmt.Errorf("reconciliation failed") - } - - for _, pool := range kluster.Pool { - if err = r.ReconcilePool(kluster, pool); err != nil { - return - } - } - - if kluster.Name == "fabus" { - return true, nil - } - - return -} - -func (r *launchReconciler) ReconcilePool(kluster Kluster, pool string) (err error) { - defer func(begin time.Time) { - r.Logger.Log( - "msg", "reconciled pool", - "kluster", kluster.Name, - "pool", pool, - "took", time.Since(begin), - "err", err) - }(time.Now()) - - return nil -} - -func (r *groundReconciler) Reconcile(kluster Kluster) (requeue bool, err error) { - if kluster.Name == "michi" { - return false, fmt.Errorf("reconciliation failed") - } - - return false, nil -} - -func main() { - w := log.NewSyncWriter(os.Stderr) - logger := log.NewLogfmtLogger(w) - logger = log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) - - NewLaunchControl(logger).Run() - NewGroundControl(logger).Run() -}