From 3ed10edf94e099b6857c6685214764652ee42cb5 Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Thu, 28 Sep 2023 21:31:32 -0400 Subject: [PATCH] make deploy operator syncs conditional when local flag is set --- cmd/main.go | 2 ++ pkg/sync/constants.go | 12 ++++++++++++ pkg/sync/loop.go | 15 +++++---------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 0c4ae091..5df89449 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -8,6 +8,7 @@ import ( "github.com/go-logr/logr" "github.com/pluralsh/deployment-operator/pkg/agent" + "github.com/pluralsh/deployment-operator/pkg/sync" "github.com/spf13/cobra" "k8s.io/client-go/tools/clientcmd" "k8s.io/klog/v2/klogr" @@ -59,6 +60,7 @@ func newCmd(log logr.Logger) *cobra.Command { cmd.Flags().StringVar(&refreshInterval, "refresh-interval", "1m", "Refresh interval duration") cmd.Flags().StringVar(&consoleUrl, "console-url", "", "the url of the console api to fetch services from") cmd.Flags().StringVar(&deployToken, "deploy-token", "", "the deploy token to auth to console api with") + cmd.Flags().BoolVar(&sync.Local, "local", false, "whether you're running the agent locally (and should avoid recreating the deploy operator)") return &cmd } diff --git a/pkg/sync/constants.go b/pkg/sync/constants.go index 110f51d9..e73f39b9 100644 --- a/pkg/sync/constants.go +++ b/pkg/sync/constants.go @@ -1,7 +1,19 @@ package sync +import ( + "time" + + "k8s.io/klog/v2/klogr" +) + const ( SyncShaAnnotation = "deployments.plural.sh/sync-sha" SyncAnnotation = "deployments.plural.sh/service-id" SSAManager = "plural-deployment-agent" + syncDelay = 5 * time.Second +) + +var ( + Local = false + log = klogr.New() ) diff --git a/pkg/sync/loop.go b/pkg/sync/loop.go index 6440ae49..3e85a08c 100644 --- a/pkg/sync/loop.go +++ b/pkg/sync/loop.go @@ -9,16 +9,6 @@ import ( "github.com/argoproj/gitops-engine/pkg/sync" "github.com/argoproj/gitops-engine/pkg/sync/common" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - - "k8s.io/klog/v2/klogr" -) - -var ( - log = klogr.New() -) - -const ( - syncDelay = 5 * time.Second ) func (engine *Engine) ControlLoop() { @@ -66,6 +56,11 @@ func (engine *Engine) processItem(item interface{}) error { fmt.Printf("failed to fetch service from cache: %s, ignoring for now", err) return err } + + if Local && svc.Name == "deploy-operator" { + return nil + } + log.Info("syncing service", "name", svc.Name, "namespace", svc.Namespace) var manErr error