Skip to content

Commit 6e89a2a

Browse files
committed
support namespaced operation
1 parent 7d93c7a commit 6e89a2a

File tree

11 files changed

+61
-27
lines changed

11 files changed

+61
-27
lines changed

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type ImageUpdaterConfig struct {
4545
GitCommitMail string
4646
GitCommitMessage *template.Template
4747
DisableKubeEvents bool
48+
Namespaced bool
4849
}
4950

5051
// newRootCommand implements the root command of argocd-image-updater

cmd/run.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"github.com/argoproj-labs/argocd-image-updater/pkg/registry"
2020
"github.com/argoproj-labs/argocd-image-updater/pkg/version"
2121

22+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
2224
"github.com/spf13/cobra"
2325

2426
"golang.org/x/sync/semaphore"
@@ -108,7 +110,11 @@ func newRunCommand() *cobra.Command {
108110
var err error
109111
if !disableKubernetes {
110112
ctx := context.Background()
111-
cfg.KubeClient, err = getKubeConfig(ctx, cfg.ArgocdNamespace, kubeConfig)
113+
ns := cfg.ArgocdNamespace
114+
if !cfg.Namespaced {
115+
ns = v1.NamespaceAll
116+
}
117+
cfg.KubeClient, err = getKubeConfig(ctx, ns, cfg.Namespaced, kubeConfig)
112118
if err != nil {
113119
log.Fatalf("could not create K8s client: %v", err)
114120
}
@@ -125,13 +131,15 @@ func newRunCommand() *cobra.Command {
125131
cfg.ClientOpts.AuthToken = token
126132
}
127133

128-
log.Infof("ArgoCD configuration: [apiKind=%s, server=%s, auth_token=%v, insecure=%v, grpc_web=%v, plaintext=%v]",
134+
log.Infof("ArgoCD configuration: [apiKind=%s, server=%s, auth_token=%v, insecure=%v, grpc_web=%v, plaintext=%v, namespaced=%v, namespace=%v]",
129135
cfg.ApplicationsAPIKind,
130136
cfg.ClientOpts.ServerAddr,
131137
cfg.ClientOpts.AuthToken != "",
132138
cfg.ClientOpts.Insecure,
133139
cfg.ClientOpts.GRPCWeb,
134140
cfg.ClientOpts.Plaintext,
141+
cfg.Namespaced,
142+
cfg.ArgocdNamespace,
135143
)
136144

137145
// Health server will start in a go routine and run asynchronously

cmd/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ argocd-image-updater test nginx --allow-tags '^1.19.\d+(\-.*)*$' --update-strate
6868
var err error
6969
if !disableKubernetes {
7070
ctx := context.Background()
71-
kubeClient, err = getKubeConfig(ctx, "", kubeConfig)
71+
kubeClient, err = getKubeConfig(ctx, "", true, kubeConfig)
7272
if err != nil {
7373
log.Fatalf("could not create K8s client: %v", err)
7474
}

cmd/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func getPrintableHealthPort(port int) string {
2626
}
2727
}
2828

29-
func getKubeConfig(ctx context.Context, namespace string, kubeConfig string) (*kube.KubernetesClient, error) {
29+
func getKubeConfig(ctx context.Context, namespace string, namespaced bool, kubeConfig string) (*kube.KubernetesClient, error) {
3030
var fullKubeConfigPath string
3131
var kubeClient *kube.KubernetesClient
3232
var err error
@@ -39,12 +39,12 @@ func getKubeConfig(ctx context.Context, namespace string, kubeConfig string) (*k
3939
}
4040

4141
if fullKubeConfigPath != "" {
42-
log.Debugf("Creating Kubernetes client from %s", fullKubeConfigPath)
42+
log.Debugf("Creating Kubernetes client from %s for namespace %s", fullKubeConfigPath, namespace)
4343
} else {
44-
log.Debugf("Creating in-cluster Kubernetes client")
44+
log.Debugf("Creating in-cluster Kubernetes client for namespace %s", namespace)
4545
}
4646

47-
kubeClient, err = kube.NewKubernetesClientFromConfig(ctx, namespace, fullKubeConfigPath)
47+
kubeClient, err = kube.NewKubernetesClientFromConfig(ctx, namespace, namespaced, fullKubeConfigPath)
4848
if err != nil {
4949
return nil, err
5050
}

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/argoproj-labs/argocd-image-updater
22

3-
go 1.20
3+
go 1.21
4+
5+
toolchain go1.21.3
46

57
require (
68
github.com/Masterminds/semver/v3 v3.2.1

go.sum

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,11 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
454454
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
455455
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
456456
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
457+
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
457458
github.com/alicebob/miniredis/v2 v2.30.3 h1:hrqDB4cHFSHQf4gO3xu6YKQg8PqJpNjLYsQAFYHstqw=
459+
github.com/alicebob/miniredis/v2 v2.30.3/go.mod h1:b25qWj4fCEsBeAAR2mlb0ufImGC6uH3VlUfb/HS5zKg=
458460
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
461+
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
459462
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
460463
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
461464
github.com/argoproj/argo-cd/v2 v2.8.4 h1:V3jBZdWsgIB/bhpsGcRo4ryGSYELnXZMYZ2taAwH0+o=
@@ -498,7 +501,9 @@ github.com/bradleyfalzon/ghinstallation v1.1.1/go.mod h1:vyCmHTciHx/uuyN82Zc3rXN
498501
github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 h1:yaYcGQ7yEIGbsJfW/9z7v1sLiZg/5rSNNXwmMct5XaE=
499502
github.com/bradleyfalzon/ghinstallation/v2 v2.5.0/go.mod h1:amcvPQMrRkWNdueWOjPytGL25xQGzox7425qMgzo+Vo=
500503
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
504+
github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
501505
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
506+
github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
502507
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
503508
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
504509
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
@@ -595,6 +600,7 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
595600
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
596601
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
597602
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0=
603+
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
598604
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
599605
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
600606
github.com/emicklei/go-restful/v3 v3.8.0 h1:eCZ8ulSerjdAiaNpF7GxXIE7ZCMo1moN1qX+S609eVw=
@@ -628,13 +634,15 @@ github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM
628634
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
629635
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
630636
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
637+
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
631638
github.com/fvbommel/sortorder v1.0.1 h1:dSnXLt4mJYH25uDDGa3biZNQsozaUWDSWeKJ0qqFfzE=
632639
github.com/fvbommel/sortorder v1.0.1/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
633640
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
634641
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
635642
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
636643
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
637644
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
645+
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
638646
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
639647
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
640648
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
@@ -643,6 +651,7 @@ github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmS
643651
github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4=
644652
github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg=
645653
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f h1:Pz0DHeFij3XFhoBRGUDPzSJ+w2UcK5/0JvF8DRI58r8=
654+
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f/go.mod h1:8LHG1a3SRW71ettAD/jW13h8c6AqjVSeL11RAdgaqpo=
646655
github.com/go-git/go-git/v5 v5.8.1 h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A=
647656
github.com/go-git/go-git/v5 v5.8.1/go.mod h1:FHFuoD6yGz5OSKEBK+aWN9Oah0q54Jxl0abmj6GnqAo=
648657
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
@@ -765,6 +774,7 @@ github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIG
765774
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
766775
github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk=
767776
github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw=
777+
github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk=
768778
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
769779
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
770780
github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
@@ -919,6 +929,7 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
919929
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
920930
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
921931
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
932+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
922933
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
923934
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
924935
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -1107,6 +1118,7 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
11071118
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
11081119
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
11091120
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
1121+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
11101122
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
11111123
github.com/rubiojr/go-vhd v0.0.0-20200706105327-02e210299021/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto=
11121124
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
@@ -1218,6 +1230,7 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
12181230
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
12191231
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
12201232
github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE=
1233+
github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
12211234
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
12221235
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
12231236
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
@@ -1942,6 +1955,7 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24
19421955
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
19431956
gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
19441957
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
1958+
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
19451959
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
19461960
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
19471961
gopkg.in/warnings.v0 v0.1.1/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=

pkg/argocd/argocd.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,41 +176,41 @@ func FilterApplicationsForUpdate(apps []v1alpha1.Application, patterns []string,
176176
var appsForUpdate = make(map[string]ApplicationImages)
177177

178178
for _, app := range apps {
179-
logCtx := log.WithContext().AddField("application", app.GetName())
179+
logCtx := log.WithContext().AddField("application", app.GetName()).AddField("namespace", app.GetNamespace())
180180

181181
sourceType := getApplicationSourceType(&app)
182182

183183
// Check whether application has our annotation set
184184
annotations := app.GetAnnotations()
185185
if _, ok := annotations[common.ImageUpdaterAnnotation]; !ok {
186-
logCtx.Tracef("skipping app '%s' of type '%s' because required annotation is missing", app.GetName(), sourceType)
186+
logCtx.Tracef("skipping app '%s' of type '%s' because required annotation is missing", app.QualifiedName(), sourceType)
187187
continue
188188
}
189189

190190
// Check for valid application type
191191
if !IsValidApplicationType(&app) {
192-
logCtx.Warnf("skipping app '%s' of type '%s' because it's not of supported source type", app.GetName(), sourceType)
192+
logCtx.Warnf("skipping app '%s' of type '%s' because it's not of supported source type", app.QualifiedName(), sourceType)
193193
continue
194194
}
195195

196196
// Check if application name matches requested patterns
197197
if !nameMatchesPattern(app.GetName(), patterns) {
198-
logCtx.Debugf("Skipping app '%s' because it does not match requested patterns", app.GetName())
198+
logCtx.Debugf("Skipping app '%s' because it does not match requested patterns", app.QualifiedName())
199199
continue
200200
}
201201

202202
// Check if application carries requested label
203203
if !matchAppLabels(app.GetName(), app.GetLabels(), appLabel) {
204-
logCtx.Debugf("Skipping app '%s' because it does not carry requested label", app.GetName())
204+
logCtx.Debugf("Skipping app '%s' because it does not carry requested label", app.QualifiedName())
205205
continue
206206
}
207207

208-
logCtx.Tracef("processing app '%s' of type '%v'", app.GetName(), sourceType)
208+
logCtx.Tracef("processing app '%s' of type '%v'", app.QualifiedName(), sourceType)
209209
imageList := parseImageList(annotations)
210210
appImages := ApplicationImages{}
211211
appImages.Application = app
212212
appImages.Images = *imageList
213-
appsForUpdate[app.GetName()] = appImages
213+
appsForUpdate[app.QualifiedName()] = appImages
214214
}
215215

216216
return appsForUpdate, nil
@@ -388,6 +388,7 @@ func SetHelmImage(app *v1alpha1.Application, newImage *image.ContainerImage) err
388388
}
389389

390390
appName := app.GetName()
391+
appNamespace := app.GetNamespace()
391392

392393
var hpImageName, hpImageTag, hpImageSpec string
393394

@@ -407,6 +408,7 @@ func SetHelmImage(app *v1alpha1.Application, newImage *image.ContainerImage) err
407408
log.WithContext().
408409
AddField("application", appName).
409410
AddField("image", newImage.GetFullNameWithoutTag()).
411+
AddField("namespace", appNamespace).
410412
Debugf("target parameters: image-spec=%s image-name=%s, image-tag=%s", hpImageSpec, hpImageName, hpImageTag)
411413

412414
mergeParams := make([]v1alpha1.HelmParameter, 0)

pkg/argocd/argocd_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ func Test_FilterApplicationsForUpdate(t *testing.T) {
435435
filtered, err := FilterApplicationsForUpdate(applicationList, []string{}, "")
436436
require.NoError(t, err)
437437
require.Len(t, filtered, 1)
438-
require.Contains(t, filtered, "app1")
439-
assert.Len(t, filtered["app1"].Images, 2)
438+
require.Contains(t, filtered, "argocd/app1")
439+
assert.Len(t, filtered["argocd/app1"].Images, 2)
440440
})
441441

442442
t.Run("Filter for applications with patterns", func(t *testing.T) {
@@ -487,9 +487,9 @@ func Test_FilterApplicationsForUpdate(t *testing.T) {
487487
filtered, err := FilterApplicationsForUpdate(applicationList, []string{"app*"}, "")
488488
require.NoError(t, err)
489489
require.Len(t, filtered, 2)
490-
require.Contains(t, filtered, "app1")
491-
require.Contains(t, filtered, "app2")
492-
assert.Len(t, filtered["app1"].Images, 2)
490+
require.Contains(t, filtered, "argocd/app1")
491+
require.Contains(t, filtered, "argocd/app2")
492+
assert.Len(t, filtered["argocd/app1"].Images, 2)
493493
})
494494

495495
t.Run("Filter for applications with label", func(t *testing.T) {
@@ -529,8 +529,8 @@ func Test_FilterApplicationsForUpdate(t *testing.T) {
529529
filtered, err := FilterApplicationsForUpdate(applicationList, []string{}, "custom.label/name=xyz")
530530
require.NoError(t, err)
531531
require.Len(t, filtered, 1)
532-
require.Contains(t, filtered, "app1")
533-
assert.Len(t, filtered["app1"].Images, 2)
532+
require.Contains(t, filtered, "argocd/app1")
533+
assert.Len(t, filtered["argocd/app1"].Images, 2)
534534
})
535535

536536
}

pkg/argocd/update.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
141141

142142
result := ImageUpdaterResult{}
143143
app := updateConf.UpdateApp.Application.GetName()
144+
namespace := updateConf.UpdateApp.Application.GetNamespace()
144145
changeList := make([]ChangeEntry, 0)
145146

146147
// Get all images that are deployed with the current application
@@ -157,7 +158,10 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
157158
for _, applicationImage := range updateConf.UpdateApp.Images {
158159
updateableImage := applicationImages.ContainsImage(applicationImage, false)
159160
if updateableImage == nil {
160-
log.WithContext().AddField("application", app).Debugf("Image '%s' seems not to be live in this application, skipping", applicationImage.ImageName)
161+
log.WithContext().
162+
AddField("application", app).
163+
AddField("namespace", namespace).
164+
Debugf("Image '%s' seems not to be live in this application, skipping", applicationImage.ImageName)
161165
result.NumSkipped += 1
162166
continue
163167
}
@@ -173,6 +177,7 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
173177

174178
imgCtx := log.WithContext().
175179
AddField("application", app).
180+
AddField("namespace", namespace).
176181
AddField("registry", updateableImage.RegistryURL).
177182
AddField("image_name", updateableImage.ImageName).
178183
AddField("image_tag", updateableImage.ImageTag).

pkg/kube/kubernetes.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"time"
1010

11+
"github.com/argoproj-labs/argocd-image-updater/pkg/log"
1112
"github.com/argoproj-labs/argocd-image-updater/pkg/metrics"
1213

1314
appv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
@@ -38,7 +39,7 @@ func NewKubernetesClient(ctx context.Context, client kubernetes.Interface, appli
3839
// NewKubernetesClient creates a new Kubernetes client object from given
3940
// configuration file. If configuration file is the empty string, in-cluster
4041
// client will be created.
41-
func NewKubernetesClientFromConfig(ctx context.Context, namespace string, kubeconfig string) (*KubernetesClient, error) {
42+
func NewKubernetesClientFromConfig(ctx context.Context, namespace string, namespaced bool, kubeconfig string) (*KubernetesClient, error) {
4243
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
4344
loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig
4445
loadingRules.ExplicitPath = kubeconfig
@@ -50,7 +51,7 @@ func NewKubernetesClientFromConfig(ctx context.Context, namespace string, kubeco
5051
return nil, err
5152
}
5253

53-
if namespace == "" {
54+
if namespace == "" && namespaced {
5455
namespace, _, err = clientConfig.Namespace()
5556
if err != nil {
5657
return nil, err
@@ -67,6 +68,7 @@ func NewKubernetesClientFromConfig(ctx context.Context, namespace string, kubeco
6768
return nil, err
6869
}
6970

71+
log.Debugf("Creating kubernetes client for ns '%s'", namespace)
7072
return NewKubernetesClient(ctx, clientset, applicationsClientset, namespace), nil
7173
}
7274

0 commit comments

Comments
 (0)