From b2ab9419bf6ce129e1cd19fe582c0d1f1e0defd4 Mon Sep 17 00:00:00 2001 From: petar-cvit Date: Sun, 3 Nov 2024 21:33:00 +0100 Subject: [PATCH 1/6] skip reconciliation --- cyclops-ctrl/.env | 1 + cyclops-ctrl/cmd/main/main.go | 6 ++++ .../modulecontroller/module_controller.go | 30 ++++++++++++------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/cyclops-ctrl/.env b/cyclops-ctrl/.env index 011a7a1d..d36b2c94 100644 --- a/cyclops-ctrl/.env +++ b/cyclops-ctrl/.env @@ -3,3 +3,4 @@ PORT=8888 WATCH_NAMESPACE=cyclops WATCH_NAMESPACE_HELM= CYCLOPS_VERSION=v0.0.0 +DISABLE_RECONCILER=false diff --git a/cyclops-ctrl/cmd/main/main.go b/cyclops-ctrl/cmd/main/main.go index 12fc3773..723fb107 100644 --- a/cyclops-ctrl/cmd/main/main.go +++ b/cyclops-ctrl/cmd/main/main.go @@ -122,12 +122,18 @@ func main() { os.Exit(1) } + disableReconciler := getEnvBool("DISABLE_RECONCILER") + if disableReconciler { + setupLog.Info("reconciler disabled") + } + if err = (modulecontroller.NewModuleReconciler( mgr.GetClient(), mgr.GetScheme(), templatesRepo, k8sClient, renderer, + disableReconciler, telemetryClient, monitor, )).SetupWithManager(mgr); err != nil { diff --git a/cyclops-ctrl/internal/modulecontroller/module_controller.go b/cyclops-ctrl/internal/modulecontroller/module_controller.go index 476371db..c4694370 100644 --- a/cyclops-ctrl/internal/modulecontroller/module_controller.go +++ b/cyclops-ctrl/internal/modulecontroller/module_controller.go @@ -50,9 +50,10 @@ type ModuleReconciler struct { client.Client Scheme *runtime.Scheme - templatesRepo templaterepo.ITemplateRepo - kubernetesClient k8sclient.IKubernetesClient - renderer *render.Renderer + templatesRepo templaterepo.ITemplateRepo + kubernetesClient k8sclient.IKubernetesClient + renderer *render.Renderer + skipReconciliation bool telemetryClient telemetry.Client monitor prometheus.Monitor @@ -65,18 +66,20 @@ func NewModuleReconciler( templatesRepo templaterepo.ITemplateRepo, kubernetesClient k8sclient.IKubernetesClient, renderer *render.Renderer, + skipReconciliation bool, telemetryClient telemetry.Client, monitor prometheus.Monitor, ) *ModuleReconciler { return &ModuleReconciler{ - Client: client, - Scheme: scheme, - templatesRepo: templatesRepo, - kubernetesClient: kubernetesClient, - renderer: renderer, - telemetryClient: telemetryClient, - monitor: monitor, - logger: ctrl.Log.WithName("reconciler"), + Client: client, + Scheme: scheme, + templatesRepo: templatesRepo, + kubernetesClient: kubernetesClient, + renderer: renderer, + telemetryClient: telemetryClient, + monitor: monitor, + skipReconciliation: skipReconciliation, + logger: ctrl.Log.WithName("reconciler"), } } @@ -94,6 +97,11 @@ func NewModuleReconciler( // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.4/pkg/reconcile func (r *ModuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + if r.skipReconciliation { + r.logger.Info("skipping reconciliation", "namespaced name", req.NamespacedName) + return ctrl.Result{}, nil + } + _ = log.FromContext(ctx) r.telemetryClient.ModuleReconciliation() r.monitor.OnReconciliation() From 6738776aa577b5450fbf35c17d65f09d09638497 Mon Sep 17 00:00:00 2001 From: petar-cvit Date: Sun, 3 Nov 2024 21:33:55 +0100 Subject: [PATCH 2/6] rename skip reconciliation env var --- cyclops-ctrl/.env | 2 +- cyclops-ctrl/cmd/main/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cyclops-ctrl/.env b/cyclops-ctrl/.env index d36b2c94..d4aa3a58 100644 --- a/cyclops-ctrl/.env +++ b/cyclops-ctrl/.env @@ -3,4 +3,4 @@ PORT=8888 WATCH_NAMESPACE=cyclops WATCH_NAMESPACE_HELM= CYCLOPS_VERSION=v0.0.0 -DISABLE_RECONCILER=false +DISABLE_MODULE_RECONCILER=true diff --git a/cyclops-ctrl/cmd/main/main.go b/cyclops-ctrl/cmd/main/main.go index 723fb107..46be04d7 100644 --- a/cyclops-ctrl/cmd/main/main.go +++ b/cyclops-ctrl/cmd/main/main.go @@ -122,7 +122,7 @@ func main() { os.Exit(1) } - disableReconciler := getEnvBool("DISABLE_RECONCILER") + disableReconciler := getEnvBool("DISABLE_MODULE_RECONCILER") if disableReconciler { setupLog.Info("reconciler disabled") } From abff03a338fdb481b25983289453bb02232e7541 Mon Sep 17 00:00:00 2001 From: petar-cvit Date: Sun, 3 Nov 2024 23:15:25 +0100 Subject: [PATCH 3/6] disable false --- cyclops-ctrl/.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyclops-ctrl/.env b/cyclops-ctrl/.env index d4aa3a58..bb1967f0 100644 --- a/cyclops-ctrl/.env +++ b/cyclops-ctrl/.env @@ -3,4 +3,4 @@ PORT=8888 WATCH_NAMESPACE=cyclops WATCH_NAMESPACE_HELM= CYCLOPS_VERSION=v0.0.0 -DISABLE_MODULE_RECONCILER=true +DISABLE_MODULE_RECONCILER=false From 9b972763c1f62f7d973ae10568c9ab0a2570f4f3 Mon Sep 17 00:00:00 2001 From: petar-cvit Date: Mon, 4 Nov 2024 12:10:33 +0100 Subject: [PATCH 4/6] disable manager --- cyclops-ctrl/cmd/main/main.go | 129 +++++++++--------- cyclops-ctrl/internal/handler/handler.go | 20 ++- .../modulecontroller/module_controller.go | 30 ++-- 3 files changed, 91 insertions(+), 88 deletions(-) diff --git a/cyclops-ctrl/cmd/main/main.go b/cyclops-ctrl/cmd/main/main.go index 46be04d7..43f4614d 100644 --- a/cyclops-ctrl/cmd/main/main.go +++ b/cyclops-ctrl/cmd/main/main.go @@ -1,34 +1,34 @@ package main import ( + "context" "flag" "fmt" + "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/modulecontroller" "os" - "strconv" - "time" - - _ "github.com/joho/godotenv/autoload" - "k8s.io/apimachinery/pkg/runtime" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - clientgoscheme "k8s.io/client-go/kubernetes/scheme" - _ "k8s.io/client-go/plugin/pkg/client/auth" - ctrl "sigs.k8s.io/controller-runtime" ctrlCache "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" - "sigs.k8s.io/controller-runtime/pkg/log/zap" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" + "strconv" + "time" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/auth" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/handler" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/integrations/helm" - "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/modulecontroller" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/prometheus" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/telemetry" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template/cache" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template/render" "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient" + _ "github.com/joho/godotenv/autoload" + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + _ "k8s.io/client-go/plugin/pkg/client/auth" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/log/zap" cyclopsv1alpha1 "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1" ) @@ -55,7 +55,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() @@ -98,64 +98,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{ - getWatchNamespace(): {}, - }, - }, - }) - if err != nil { - setupLog.Error(err, "unable to start manager") - os.Exit(1) - } - disableReconciler := getEnvBool("DISABLE_MODULE_RECONCILER") if disableReconciler { setupLog.Info("reconciler disabled") } - if err = (modulecontroller.NewModuleReconciler( - mgr.GetClient(), - mgr.GetScheme(), - templatesRepo, - k8sClient, - renderer, - disableReconciler, - 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) + 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{ + getWatchNamespace(): {}, + }, + }, + }) + 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 { diff --git a/cyclops-ctrl/internal/handler/handler.go b/cyclops-ctrl/internal/handler/handler.go index f31f158f..78531b2e 100644 --- a/cyclops-ctrl/internal/handler/handler.go +++ b/cyclops-ctrl/internal/handler/handler.go @@ -1,17 +1,19 @@ package handler import ( + "context" + "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/gin-gonic/gin" - "net/http" - - "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/controller" "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" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template/render" "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient" + "github.com/gin-gonic/gin" + "net/http" + "os/signal" + "syscall" ) type Handler struct { @@ -45,7 +47,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) @@ -57,6 +59,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) @@ -116,7 +121,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) { diff --git a/cyclops-ctrl/internal/modulecontroller/module_controller.go b/cyclops-ctrl/internal/modulecontroller/module_controller.go index c4694370..476371db 100644 --- a/cyclops-ctrl/internal/modulecontroller/module_controller.go +++ b/cyclops-ctrl/internal/modulecontroller/module_controller.go @@ -50,10 +50,9 @@ type ModuleReconciler struct { client.Client Scheme *runtime.Scheme - templatesRepo templaterepo.ITemplateRepo - kubernetesClient k8sclient.IKubernetesClient - renderer *render.Renderer - skipReconciliation bool + templatesRepo templaterepo.ITemplateRepo + kubernetesClient k8sclient.IKubernetesClient + renderer *render.Renderer telemetryClient telemetry.Client monitor prometheus.Monitor @@ -66,20 +65,18 @@ func NewModuleReconciler( templatesRepo templaterepo.ITemplateRepo, kubernetesClient k8sclient.IKubernetesClient, renderer *render.Renderer, - skipReconciliation bool, telemetryClient telemetry.Client, monitor prometheus.Monitor, ) *ModuleReconciler { return &ModuleReconciler{ - Client: client, - Scheme: scheme, - templatesRepo: templatesRepo, - kubernetesClient: kubernetesClient, - renderer: renderer, - telemetryClient: telemetryClient, - monitor: monitor, - skipReconciliation: skipReconciliation, - logger: ctrl.Log.WithName("reconciler"), + Client: client, + Scheme: scheme, + templatesRepo: templatesRepo, + kubernetesClient: kubernetesClient, + renderer: renderer, + telemetryClient: telemetryClient, + monitor: monitor, + logger: ctrl.Log.WithName("reconciler"), } } @@ -97,11 +94,6 @@ func NewModuleReconciler( // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.4/pkg/reconcile func (r *ModuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - if r.skipReconciliation { - r.logger.Info("skipping reconciliation", "namespaced name", req.NamespacedName) - return ctrl.Result{}, nil - } - _ = log.FromContext(ctx) r.telemetryClient.ModuleReconciliation() r.monitor.OnReconciliation() From 36bfa69ff032ca444954e22113b235ee33e46ace Mon Sep 17 00:00:00 2001 From: petar-cvit Date: Mon, 4 Nov 2024 12:32:01 +0100 Subject: [PATCH 5/6] sort imports --- cyclops-ctrl/cmd/main/main.go | 24 ++++++++++++------------ cyclops-ctrl/internal/handler/handler.go | 10 ++++++---- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cyclops-ctrl/cmd/main/main.go b/cyclops-ctrl/cmd/main/main.go index 43f4614d..a7aae1ab 100644 --- a/cyclops-ctrl/cmd/main/main.go +++ b/cyclops-ctrl/cmd/main/main.go @@ -4,33 +4,33 @@ import ( "context" "flag" "fmt" - "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/modulecontroller" "os" + "strconv" + "time" + + _ "github.com/joho/godotenv/autoload" + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + _ "k8s.io/client-go/plugin/pkg/client/auth" + ctrl "sigs.k8s.io/controller-runtime" ctrlCache "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" + "sigs.k8s.io/controller-runtime/pkg/log/zap" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - "strconv" - "time" + cyclopsv1alpha1 "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/auth" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/handler" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/integrations/helm" + "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/modulecontroller" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/prometheus" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/telemetry" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template/cache" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template/render" "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient" - _ "github.com/joho/godotenv/autoload" - "k8s.io/apimachinery/pkg/runtime" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - clientgoscheme "k8s.io/client-go/kubernetes/scheme" - _ "k8s.io/client-go/plugin/pkg/client/auth" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/log/zap" - - cyclopsv1alpha1 "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1" ) var ( diff --git a/cyclops-ctrl/internal/handler/handler.go b/cyclops-ctrl/internal/handler/handler.go index 78531b2e..0007ef1a 100644 --- a/cyclops-ctrl/internal/handler/handler.go +++ b/cyclops-ctrl/internal/handler/handler.go @@ -2,6 +2,12 @@ package handler import ( "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" @@ -10,10 +16,6 @@ import ( templaterepo "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template/render" "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient" - "github.com/gin-gonic/gin" - "net/http" - "os/signal" - "syscall" ) type Handler struct { From 89c55c0e9023ec4c61ed04c8484aabbca581a738 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 4 Nov 2024 15:13:15 +0000 Subject: [PATCH 6/6] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20update=20cyclops=20to?= =?UTF-8?q?=20v0.15.2-rc.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install/cyclops-install.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/cyclops-install.yaml b/install/cyclops-install.yaml index a2a17a29..ce28c3ce 100644 --- a/install/cyclops-install.yaml +++ b/install/cyclops-install.yaml @@ -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: @@ -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: