Skip to content

Commit 6d7c38d

Browse files
dkarpelechansukechengfangdependabot[bot]cjcocokrisp
authored
Rebase crd branch onto master branch (#1192)
Signed-off-by: Denis Karpelevich <56302307+dkarpele@users.noreply.github.com> Signed-off-by: chansuke <moonset20@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Christopher Coco <chriscoco1205@gmail.com> Signed-off-by: Jongwon Youn <eatingcookieman@gmail.com> Signed-off-by: Binh Nguyen <binh.nguyen@encapital.io> Signed-off-by: Cheng Fang <cfang@redhat.com> Co-authored-by: Yusuke Abe <moonset20@gmail.com> Co-authored-by: Cheng Fang <cfang@redhat.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Christopher Coco <chriscoco1205@gmail.com> Co-authored-by: Jongwon Youn <eatingcookieman@gmail.com> Co-authored-by: Binh Nguyen <37066217+binhnguyenduc@users.noreply.github.com> Co-authored-by: Binh Nguyen <binh.nguyen@encapital.io>
1 parent 1fc03d4 commit 6d7c38d

29 files changed

+2808
-95
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23 AS builder
1+
FROM golang:1.24 AS builder
22

33
RUN mkdir -p /src/argocd-image-updater
44
WORKDIR /src/argocd-image-updater

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ supported yet (and maybe never will).
2222
Read
2323
[the documentation](https://argocd-image-updater.readthedocs.io/en/stable/)
2424
for more information on how to setup and run Argo CD Image Updater and to get
25-
known to it's features and limitations.
25+
known to its features and limitations.
2626

2727
Above URL points to the documentation for the current release. If you are
2828
interested in documentation of upcoming features, check out the

cmd/ask_pass.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"google.golang.org/grpc"
1313
"google.golang.org/grpc/credentials/insecure"
1414

15-
"github.com/argoproj/argo-cd/v2/reposerver/askpass"
15+
"github.com/argoproj/argo-cd/v2/util/askpass"
1616
"github.com/argoproj/argo-cd/v2/util/errors"
1717
grpc_util "github.com/argoproj/argo-cd/v2/util/grpc"
1818
"github.com/argoproj/argo-cd/v2/util/io"

cmd/ask_pass_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/argoproj/argo-cd/v2/reposerver/askpass"
12+
"github.com/argoproj/argo-cd/v2/util/askpass"
1313
"github.com/spf13/cobra"
1414
"github.com/stretchr/testify/assert"
1515
"google.golang.org/grpc"

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func newRootCommand() error {
4444
rootCmd.AddCommand(newVersionCommand())
4545
rootCmd.AddCommand(newTestCommand())
4646
rootCmd.AddCommand(newTemplateCommand())
47+
rootCmd.AddCommand(NewWebhookCommand())
4748
err := rootCmd.Execute()
4849
return err
4950
}

cmd/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
"github.com/argoproj-labs/argocd-image-updater/internal/controller"
1818

19-
"github.com/argoproj/argo-cd/v2/reposerver/askpass"
19+
"github.com/argoproj/argo-cd/v2/util/askpass"
2020

2121
"github.com/sirupsen/logrus"
2222
"github.com/spf13/cobra"
@@ -44,7 +44,6 @@ func newRunCommand() *cobra.Command {
4444
var probeAddr string
4545
var secureMetrics bool
4646
var enableHTTP2 bool
47-
var enableWebhooks bool
4847
var cfg = &controller.ImageUpdaterConfig{}
4948
var once bool
5049
var kubeConfig string
@@ -207,7 +206,7 @@ This enables a CRD-driven approach to automated image updates with Argo CD.
207206

208207
var webhookServer webhook.Server
209208

210-
if enableWebhooks {
209+
if cfg.EnableWebhook && cfg.WebhookPort > 0 {
211210
setupLogger.Info("enabling webhook server")
212211
webhookServer = webhook.NewServer(webhook.Options{
213212
TLSOpts: tlsOpts,
@@ -324,7 +323,6 @@ This enables a CRD-driven approach to automated image updates with Argo CD.
324323
controllerCmd.Flags().StringVar(&leaderElectionNamespace, "leader-election-namespace", "", "The namespace used for the leader election lease. If empty, the controller will use the namespace of the pod it is running in. When running locally this value must be set.")
325324
controllerCmd.Flags().BoolVar(&secureMetrics, "metrics-secure", true, "If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
326325
controllerCmd.Flags().BoolVar(&enableHTTP2, "enable-http2", false, "If set, HTTP/2 will be enabled for the metrics and webhook servers")
327-
controllerCmd.Flags().BoolVar(&enableWebhooks, "enable-webhooks", false, "Enable admission webhooks. Requires a valid TLS certificate.")
328326
controllerCmd.Flags().StringVar(&cfg.ApplicationsAPIKind, "applications-api", env.GetStringVal("APPLICATIONS_API", common.ApplicationsAPIKindK8S), "API kind that is used to manage Argo CD applications ('kubernetes' or 'argocd')")
329327
controllerCmd.Flags().StringVar(&cfg.ClientOpts.ServerAddr, "argocd-server-addr", env.GetStringVal("ARGOCD_SERVER", ""), "address of ArgoCD API server")
330328
controllerCmd.Flags().BoolVar(&cfg.ClientOpts.GRPCWeb, "argocd-grpc-web", env.GetBoolVal("ARGOCD_GRPC_WEB", false), "use grpc-web for connection to ArgoCD")
@@ -352,6 +350,8 @@ This enables a CRD-driven approach to automated image updates with Argo CD.
352350
controllerCmd.Flags().BoolVar(&cfg.GitCommitSignOff, "git-commit-sign-off", env.GetBoolVal("GIT_COMMIT_SIGN_OFF", false), "Whether to sign-off git commits")
353351
controllerCmd.Flags().StringVar(&commitMessagePath, "git-commit-message-path", common.DefaultCommitTemplatePath, "Path to a template to use for Git commit messages")
354352
controllerCmd.Flags().BoolVar(&cfg.DisableKubeEvents, "disable-kube-events", env.GetBoolVal("IMAGE_UPDATER_KUBE_EVENTS", false), "Disable kubernetes events")
353+
controllerCmd.Flags().IntVar(&cfg.WebhookPort, "webhook-port", env.ParseNumFromEnv("WEBHOOK_PORT", 8082, 0, 65535), "Port to start the webhook server on, 0 to disable")
354+
controllerCmd.Flags().BoolVar(&cfg.EnableWebhook, "enable-webhook", env.GetBoolVal("ENABLE_WEBHOOK", false), "Enable webhook server for receiving registry events")
355355

356356
return controllerCmd
357357
}

cmd/webhook.go

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"os"
6+
"os/signal"
7+
"syscall"
8+
9+
"github.com/argoproj-labs/argocd-image-updater/pkg/argocd"
10+
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
11+
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
12+
"github.com/argoproj-labs/argocd-image-updater/pkg/webhook"
13+
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
14+
15+
"github.com/spf13/cobra"
16+
ctrl "sigs.k8s.io/controller-runtime"
17+
"sigs.k8s.io/controller-runtime/pkg/client"
18+
)
19+
20+
// WebhookOptions holds the options for the webhook server
21+
type WebhookOptions struct {
22+
Port int
23+
DockerSecret string
24+
GHCRSecret string
25+
UpdateOnEvent bool
26+
ApplicationsAPIKind string
27+
AppNamespace string
28+
ServerAddr string
29+
Insecure bool
30+
Plaintext bool
31+
GRPCWeb bool
32+
AuthToken string
33+
}
34+
35+
var webhookOpts WebhookOptions
36+
37+
// NewWebhookCommand creates a new webhook command
38+
func NewWebhookCommand() *cobra.Command {
39+
var webhookCmd = &cobra.Command{
40+
Use: "webhook",
41+
Short: "Start webhook server to receive registry events",
42+
Long: `
43+
The webhook command starts a server that listens for webhook events from
44+
container registries. When an event is received, it can trigger an image
45+
update check for the affected images.
46+
47+
Supported registries:
48+
- Docker Hub
49+
- GitHub Container Registry (GHCR)
50+
`,
51+
Run: func(cmd *cobra.Command, args []string) {
52+
runWebhook()
53+
},
54+
}
55+
56+
webhookCmd.Flags().IntVar(&webhookOpts.Port, "port", 8080, "Port to listen on for webhook events")
57+
webhookCmd.Flags().StringVar(&webhookOpts.DockerSecret, "docker-secret", "", "Secret for validating Docker Hub webhooks")
58+
webhookCmd.Flags().StringVar(&webhookOpts.GHCRSecret, "ghcr-secret", "", "Secret for validating GitHub Container Registry webhooks")
59+
webhookCmd.Flags().BoolVar(&webhookOpts.UpdateOnEvent, "update-on-event", true, "Whether to trigger image update checks when webhook events are received")
60+
webhookCmd.Flags().StringVar(&webhookOpts.ApplicationsAPIKind, "applications-api", common.ApplicationsAPIKindK8S, "API kind that is used to manage Argo CD applications ('kubernetes' or 'argocd')")
61+
webhookCmd.Flags().StringVar(&webhookOpts.AppNamespace, "application-namespace", "", "namespace where Argo Image Updater will manage applications")
62+
webhookCmd.Flags().StringVar(&webhookOpts.ServerAddr, "argocd-server-addr", "", "address of ArgoCD API server")
63+
webhookCmd.Flags().BoolVar(&webhookOpts.Insecure, "argocd-insecure", false, "(INSECURE) ignore invalid TLS certs for ArgoCD server")
64+
webhookCmd.Flags().BoolVar(&webhookOpts.Plaintext, "argocd-plaintext", false, "(INSECURE) connect without TLS to ArgoCD server")
65+
webhookCmd.Flags().BoolVar(&webhookOpts.GRPCWeb, "argocd-grpc-web", false, "use grpc-web for connection to ArgoCD")
66+
webhookCmd.Flags().StringVar(&webhookOpts.AuthToken, "argocd-auth-token", "", "use token for authenticating to ArgoCD")
67+
68+
return webhookCmd
69+
}
70+
71+
// runWebhook starts the webhook server
72+
func runWebhook() {
73+
log.Infof("Starting webhook server on port %d", webhookOpts.Port)
74+
75+
// Initialize the ArgoCD client
76+
var argoClient argocd.ArgoCD
77+
var err error
78+
79+
// Create Kubernetes client
80+
var kubeClient *kube.ImageUpdaterKubernetesClient
81+
kubeClient, err = argocd.GetKubeConfig(context.TODO(), "", "")
82+
if err != nil {
83+
log.Fatalf("Could not create Kubernetes client: %v", err)
84+
}
85+
86+
// Set up based on application API kind
87+
if webhookOpts.ApplicationsAPIKind == common.ApplicationsAPIKindK8S {
88+
// Create a new controller-runtime client, which is what the refactored
89+
// NewK8SClient function expects.
90+
config, err := ctrl.GetConfig()
91+
if err != nil {
92+
log.Fatalf("could not get k8s config: %v", err)
93+
}
94+
ctrlClient, err := client.New(config, client.Options{Scheme: scheme})
95+
if err != nil {
96+
log.Fatalf("could not create controller-runtime client: %v", err)
97+
}
98+
argoClient, err = argocd.NewK8SClient(ctrlClient)
99+
if err != nil {
100+
log.Fatalf("Could not create ArgoCD K8s client: %v", err)
101+
}
102+
} else {
103+
// Use defaults if not specified
104+
serverAddr := webhookOpts.ServerAddr
105+
if serverAddr == "" {
106+
serverAddr = common.DefaultArgoCDServerAddr
107+
}
108+
109+
// Check for auth token from environment if not provided
110+
authToken := webhookOpts.AuthToken
111+
if authToken == "" {
112+
if token := os.Getenv("ARGOCD_TOKEN"); token != "" {
113+
authToken = token
114+
}
115+
}
116+
117+
clientOpts := argocd.ClientOptions{
118+
ServerAddr: serverAddr,
119+
Insecure: webhookOpts.Insecure,
120+
Plaintext: webhookOpts.Plaintext,
121+
GRPCWeb: webhookOpts.GRPCWeb,
122+
AuthToken: authToken,
123+
}
124+
argoClient, err = argocd.NewAPIClient(&clientOpts)
125+
}
126+
127+
if err != nil {
128+
log.Fatalf("Could not create ArgoCD client: %v", err)
129+
}
130+
131+
// Create webhook handler
132+
handler := webhook.NewWebhookHandler()
133+
134+
// Register supported webhook handlers
135+
dockerHandler := webhook.NewDockerHubWebhook(webhookOpts.DockerSecret)
136+
handler.RegisterHandler(dockerHandler)
137+
138+
ghcrHandler := webhook.NewGHCRWebhook(webhookOpts.GHCRSecret)
139+
handler.RegisterHandler(ghcrHandler)
140+
141+
// Create webhook server
142+
server := webhook.NewWebhookServer(webhookOpts.Port, handler, kubeClient, argoClient)
143+
144+
// Set up graceful shutdown
145+
stop := make(chan os.Signal, 1)
146+
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
147+
148+
// Start the server in a separate goroutine
149+
go func() {
150+
if err := server.Start(); err != nil {
151+
log.Fatalf("Failed to start webhook server: %v", err)
152+
}
153+
}()
154+
155+
// Wait for interrupt signal
156+
<-stop
157+
158+
// Gracefully shut down the server
159+
log.Infof("Shutting down webhook server")
160+
if err := server.Stop(); err != nil {
161+
log.Errorf("Error stopping webhook server: %v", err)
162+
}
163+
}

docs/basics/update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The workflow of Argo CD Image Updater can be described as follows:
1414
whose name match a given pattern, or match a given label.
1515

1616
* It then goes through the list of `Applications` found and inspects each
17-
for the the annotation `argocd-image-updater.argoproj.io/image-list`. This
17+
for the annotation `argocd-image-updater.argoproj.io/image-list`. This
1818
annotation holds a list of image names that should be updated, and is a
1919
mandatory annotation for Argo CD Image Updater to indicate it should
2020
process this `Application`. Read more about the syntax expected in this

docs/configuration/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ following:
3232
argocd-image-updater.argoproj.io/image-list: nginx
3333
```
3434

35-
The above example would specify to update the image `nginx` to it's most recent
35+
The above example would specify to update the image `nginx` to its most recent
3636
version found in the container registry, without taking any version constraints
3737
into consideration.
3838

docs/install/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ kubectl -n argocd-image-updater rollout restart deployment argocd-image-updater
165165

166166
When installed from the manifests into a Kubernetes cluster, the Argo CD Image
167167
Updater reads the token required for accessing Argo CD API from an environment
168-
variable named `ARGOCD_TOKEN`, which is set from a a field named
168+
variable named `ARGOCD_TOKEN`, which is set from a field named
169169
`argocd.token` in a secret named `argocd-image-updater-secret`.
170170

171171
The value for `argocd.token` should be set to the *base64 encoded* value of the
172-
access token you have generated above. As a short-cut, you can use generate the
172+
access token you have generated above. As a short-cut, you can use generate
173173
secret with `kubectl` and apply it over the existing resource:
174174

175175
```shell

0 commit comments

Comments
 (0)