Skip to content

Support namespaced operation #1

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

Open
wants to merge 21 commits into
base: master
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ RUN go mod download
COPY . .

RUN mkdir -p dist && \
make controller
make controller

FROM alpine:latest
FROM alpine:3.18

RUN apk update && \
apk upgrade && \
Expand Down
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ImageUpdaterConfig struct {
GitCommitMail string
GitCommitMessage *template.Template
DisableKubeEvents bool
Namespaced bool
}

// newRootCommand implements the root command of argocd-image-updater
Expand Down
19 changes: 13 additions & 6 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"text/template"
"time"

"github.com/spf13/cobra"
"golang.org/x/sync/semaphore"
v1 "k8s.io/api/core/v1"

"github.com/argoproj-labs/argocd-image-updater/pkg/argocd"
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/pkg/env"
Expand All @@ -18,10 +22,6 @@ import (
"github.com/argoproj-labs/argocd-image-updater/pkg/metrics"
"github.com/argoproj-labs/argocd-image-updater/pkg/registry"
"github.com/argoproj-labs/argocd-image-updater/pkg/version"

"github.com/spf13/cobra"

"golang.org/x/sync/semaphore"
)

// newRunCommand implements "run" command
Expand Down Expand Up @@ -108,7 +108,11 @@ func newRunCommand() *cobra.Command {
var err error
if !disableKubernetes {
ctx := context.Background()
cfg.KubeClient, err = getKubeConfig(ctx, cfg.ArgocdNamespace, kubeConfig)
ns := cfg.ArgocdNamespace
if !cfg.Namespaced {
ns = v1.NamespaceAll
}
cfg.KubeClient, err = getKubeConfig(ctx, ns, cfg.Namespaced, kubeConfig)
if err != nil {
log.Fatalf("could not create K8s client: %v", err)
}
Expand All @@ -125,13 +129,15 @@ func newRunCommand() *cobra.Command {
cfg.ClientOpts.AuthToken = token
}

log.Infof("ArgoCD configuration: [apiKind=%s, server=%s, auth_token=%v, insecure=%v, grpc_web=%v, plaintext=%v]",
log.Infof("ArgoCD configuration: [apiKind=%s, server=%s, auth_token=%v, insecure=%v, grpc_web=%v, plaintext=%v, namespaced=%v, namespace=%s]",
cfg.ApplicationsAPIKind,
cfg.ClientOpts.ServerAddr,
cfg.ClientOpts.AuthToken != "",
cfg.ClientOpts.Insecure,
cfg.ClientOpts.GRPCWeb,
cfg.ClientOpts.Plaintext,
cfg.Namespaced,
cfg.ArgocdNamespace,
)

// Health server will start in a go routine and run asynchronously
Expand Down Expand Up @@ -223,6 +229,7 @@ func newRunCommand() *cobra.Command {
runCmd.Flags().StringVar(&cfg.GitCommitMail, "git-commit-email", env.GetStringVal("GIT_COMMIT_EMAIL", "[email protected]"), "E-Mail address to use for Git commits")
runCmd.Flags().StringVar(&commitMessagePath, "git-commit-message-path", defaultCommitTemplatePath, "Path to a template to use for Git commit messages")
runCmd.Flags().BoolVar(&cfg.DisableKubeEvents, "disable-kube-events", env.GetBoolVal("IMAGE_UPDATER_KUBE_EVENTS", false), "Disable kubernetes events")
runCmd.Flags().BoolVar(&cfg.Namespaced, "namespaced", env.GetBoolVal("IMAGE_UPDATER_NAMESPACED", false), "Use namespace-scoped K8s client")

return runCmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ argocd-image-updater test nginx --allow-tags '^1.19.\d+(\-.*)*$' --update-strate
var err error
if !disableKubernetes {
ctx := context.Background()
kubeClient, err = getKubeConfig(ctx, "", kubeConfig)
kubeClient, err = getKubeConfig(ctx, "", true, kubeConfig)
if err != nil {
log.Fatalf("could not create K8s client: %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func getPrintableHealthPort(port int) string {
}
}

func getKubeConfig(ctx context.Context, namespace string, kubeConfig string) (*kube.KubernetesClient, error) {
func getKubeConfig(ctx context.Context, namespace string, namespaced bool, kubeConfig string) (*kube.KubernetesClient, error) {
var fullKubeConfigPath string
var kubeClient *kube.KubernetesClient
var err error
Expand All @@ -39,12 +39,12 @@ func getKubeConfig(ctx context.Context, namespace string, kubeConfig string) (*k
}

if fullKubeConfigPath != "" {
log.Debugf("Creating Kubernetes client from %s", fullKubeConfigPath)
log.Debugf("Creating Kubernetes client from %s for namespace '%s'", fullKubeConfigPath, namespace)
} else {
log.Debugf("Creating in-cluster Kubernetes client")
log.Debugf("Creating in-cluster Kubernetes client for namespace '%s'", namespace)
}

kubeClient, err = kube.NewKubernetesClientFromConfig(ctx, namespace, fullKubeConfigPath)
kubeClient, err = kube.NewKubernetesClientFromConfig(ctx, namespace, namespaced, fullKubeConfigPath)
if err != nil {
return nil, err
}
Expand Down
17 changes: 1 addition & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/bradleyfalzon/ghinstallation v1.1.1
github.com/distribution/distribution/v3 v3.0.0-20230722181636-7b502560cad4
github.com/go-git/go-git/v5 v5.8.1
github.com/miracl/conflate v1.3.2
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc.3
github.com/patrickmn/go-cache v2.1.0+incompatible
Expand All @@ -32,20 +31,6 @@ require (
)

require (
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/iam v1.1.0 // indirect
cloud.google.com/go/storage v1.33.0 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.132.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
)
Expand Down Expand Up @@ -168,7 +153,7 @@ require (
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/grpc v1.56.2 // indirect
Expand Down
Loading