Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable reconciler #672

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cyclops-ctrl/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ PORT=8888
WATCH_NAMESPACE=cyclops
WATCH_NAMESPACE_HELM=
CYCLOPS_VERSION=v0.0.0
DISABLE_MODULE_RECONCILER=false
108 changes: 59 additions & 49 deletions cyclops-ctrl/cmd/main/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -55,7 +56,7 @@ func main() {
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
opts := zap.Options{
Development: true,
Development: false,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
Expand Down Expand Up @@ -101,58 +102,67 @@ func main() {
panic(err)
}

go handler.Start()

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "f9d9f115.cyclops-ui.com",
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
}),
Cache: ctrlCache.Options{
DefaultNamespaces: map[string]ctrlCache.Config{
watchNamespace: {},
},
},
})
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

if err = (modulecontroller.NewModuleReconciler(
mgr.GetClient(),
mgr.GetScheme(),
templatesRepo,
k8sClient,
renderer,
telemetryClient,
monitor,
)).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Module")
os.Exit(1)
disableReconciler := getEnvBool("DISABLE_MODULE_RECONCILER")
if disableReconciler {
setupLog.Info("reconciler disabled")
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
if !disableReconciler {
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "f9d9f115.cyclops-ui.com",
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
}),
Cache: ctrlCache.Options{
DefaultNamespaces: map[string]ctrlCache.Config{
watchNamespace: {},
},
},
})
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

if err = (modulecontroller.NewModuleReconciler(
mgr.GetClient(),
mgr.GetScheme(),
templatesRepo,
k8sClient,
renderer,
telemetryClient,
monitor,
)).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Module")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}

go func() {
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}()
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
handler.Start(context.Background())
}

func getEnvBool(key string) bool {
Expand Down
20 changes: 15 additions & 5 deletions cyclops-ctrl/internal/handler/handler.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package handler

import (
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/controller/sse"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/integrations/helm"
"github.com/gin-gonic/gin"
"context"
"net/http"
"os/signal"
"syscall"

"github.com/gin-gonic/gin"

"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/controller"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/controller/sse"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/integrations/helm"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/prometheus"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/telemetry"
templaterepo "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template"
Expand Down Expand Up @@ -45,7 +49,7 @@ func New(
}, nil
}

func (h *Handler) Start() error {
func (h *Handler) Start(ctx context.Context) {
gin.SetMode(gin.DebugMode)

templatesController := controller.NewTemplatesController(h.templatesRepo, h.k8sClient, h.telemetryClient)
Expand All @@ -57,6 +61,9 @@ func (h *Handler) Start() error {

server := sse.NewServer(h.k8sClient)

h.router.GET("/healthz", func(c *gin.Context) { c.String(http.StatusOK, "OK") })
h.router.GET("/readyz", func(c *gin.Context) { c.String(http.StatusOK, "OK") })

h.router.GET("/stream/resources/:name", sse.HeadersMiddleware(), server.Resources)
h.router.GET("/stream/releases/resources/:name", sse.HeadersMiddleware(), server.ReleaseResources)
h.router.POST("/stream/resources", sse.HeadersMiddleware(), server.SingleResource)
Expand Down Expand Up @@ -116,7 +123,10 @@ func (h *Handler) Start() error {

h.router.Use(h.options)

return h.router.Run()
c, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
go h.router.Run()
<-c.Done()
stop()
}

func (h *Handler) pong() func(ctx *gin.Context) {
Expand Down
4 changes: 2 additions & 2 deletions install/cyclops-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ spec:
spec:
containers:
- name: cyclops-ui
image: cyclopsui/cyclops-ui:v0.15.1
image: cyclopsui/cyclops-ui:v0.15.2-rc.1
ports:
- containerPort: 80
env:
Expand Down Expand Up @@ -448,7 +448,7 @@ spec:
serviceAccountName: cyclops-ctrl
containers:
- name: cyclops-ctrl
image: cyclopsui/cyclops-ctrl:v0.15.1
image: cyclopsui/cyclops-ctrl:v0.15.2-rc.1
ports:
- containerPort: 8080
env:
Expand Down