diff --git a/Dockerfile b/Dockerfile index 820f68e2..3f65acea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,12 +14,19 @@ RUN go mod download COPY /cmd/main.go main.go COPY /pkg pkg/ +ENV HELM_VERSION=v3.10.3 + +RUN apk add --update --no-cache curl ca-certificates unzip wget openssl build-base && \ + curl -L https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz | tar xvz && \ + mv linux-${TARGETARCH}/helm /usr/local/bin/helm + # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build -a -o deployment-agent main.go -FROM gcr.io/distroless/static:nonroot -WORKDIR / +FROM alpine:3.17 +WORKDIR /workspace +COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm COPY --from=builder /workspace/deployment-agent . USER 65532:65532 -ENTRYPOINT ["/deployment-agent"] \ No newline at end of file +ENTRYPOINT ["/workspace/deployment-agent"] \ No newline at end of file diff --git a/charts/deployment-operator/Chart.yaml b/charts/deployment-operator/Chart.yaml index 23651182..ab520674 100644 --- a/charts/deployment-operator/Chart.yaml +++ b/charts/deployment-operator/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: deployment-operator description: creates a new instance of the plural deployment operator type: application -version: 0.1.1 +version: 0.1.2 appVersion: "0.1.1" maintainers: - name: Plural diff --git a/charts/deployment-operator/templates/deployment.yaml b/charts/deployment-operator/templates/deployment.yaml index f151759d..c80d0c64 100644 --- a/charts/deployment-operator/templates/deployment.yaml +++ b/charts/deployment-operator/templates/deployment.yaml @@ -11,8 +11,9 @@ spec: {{- include "deployment-operator.selectorLabels" . | nindent 6 }} template: metadata: - {{- with .Values.podAnnotations }} annotations: + checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} labels: 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/go.mod b/go.mod index 1674cb06..eee91281 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/go-logr/logr v1.2.4 github.com/orcaman/concurrent-map/v2 v2.0.1 github.com/osteele/liquid v1.3.1 - github.com/pluralsh/console-client-go v0.0.8 + github.com/pluralsh/console-client-go v0.0.11 github.com/pluralsh/polly v0.1.4 github.com/samber/lo v1.38.1 github.com/spf13/cobra v1.7.0 diff --git a/go.sum b/go.sum index 531c5d3e..ef901fc7 100644 --- a/go.sum +++ b/go.sum @@ -545,6 +545,8 @@ github.com/pluralsh/console-client-go v0.0.5 h1:+L7I3QLMWNBiuZlWe/YJfUMMZGnpKhEA github.com/pluralsh/console-client-go v0.0.5/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU= github.com/pluralsh/console-client-go v0.0.8 h1:BwWOt1ggBX/fxzY2+01dk8sBTz1jqT57o2y1Iz9Zxzk= github.com/pluralsh/console-client-go v0.0.8/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU= +github.com/pluralsh/console-client-go v0.0.11 h1:2fchZE6qlSQmHTeuH54hAzJJpgKpx2Kbl8HhJNugbns= +github.com/pluralsh/console-client-go v0.0.11/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU= github.com/pluralsh/polly v0.1.4 h1:Kz90peCgvsfF3ERt8cujr5TR9z4wUlqQE60Eg09ZItY= github.com/pluralsh/polly v0.1.4/go.mod h1:Yo1/jcW+4xwhWG+ZJikZy4J4HJkMNPZ7sq5auL2c/tY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/pkg/manifests/template/raw.go b/pkg/manifests/template/raw.go index 79dece53..11b645a3 100644 --- a/pkg/manifests/template/raw.go +++ b/pkg/manifests/template/raw.go @@ -10,10 +10,12 @@ import ( "github.com/argoproj/gitops-engine/pkg/utils/kube" "github.com/osteele/liquid" console "github.com/pluralsh/console-client-go" + "github.com/samber/lo" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) var ( + extensions = []string{".json", ".yaml", ".yml", ".yaml.liquid", ".yml.liquid", ".json.liquid"} liquidEngine = liquid.NewEngine() sprigFunctions = map[string]string{ "toJson": "to_json", @@ -57,7 +59,7 @@ func (r *raw) Render(svc *console.ServiceDeploymentExtended) ([]*unstructured.Un if info.IsDir() { return nil } - if ext := strings.ToLower(filepath.Ext(info.Name())); ext != ".json" && ext != ".yml" && ext != ".yaml" { + if ext := strings.ToLower(filepath.Ext(info.Name())); !lo.Contains(extensions, ext) { return nil } rpath, err := filepath.Rel(r.dir, path) diff --git a/pkg/sync/constants.go b/pkg/sync/constants.go index 110f51d9..95fc4cf0 100644 --- a/pkg/sync/constants.go +++ b/pkg/sync/constants.go @@ -1,7 +1,20 @@ 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" + OperatorService = "deploy-operator" + syncDelay = 5 * time.Second +) + +var ( + Local = false + log = klogr.New() ) diff --git a/pkg/sync/loop.go b/pkg/sync/loop.go index 6440ae49..374115ec 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 == OperatorService { + return nil + } + log.Info("syncing service", "name", svc.Name, "namespace", svc.Namespace) var manErr error