Skip to content

Commit 0c92b47

Browse files
committed
feat: add support for sourcing images from a configmap
1 parent c2433ea commit 0c92b47

14 files changed

+909
-139
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ image-cache-daemon [flags]
2222
### Options
2323

2424
```
25+
--configmap-selector string The selector to use when monitoring for ConfigMap sources (default "app.kubernetes.io/part-of=image-cache-daemon")
2526
-h, --help help for image-cache-daemon
2627
--image stringArray Images that should be pre-fetched
2728
--node-name string The node name to pull to
@@ -33,4 +34,28 @@ image-cache-daemon [flags]
3334
--watch-argo-cluster-workflow-templates Whether or not to watch cluster workflow templates (default true)
3435
--watch-argo-cron-workflows Whether or not to watch cron workflows (default true)
3536
--watch-argo-workflow-templates Whether or not to watch workflow templates (default true)
37+
--watch-configmaps Whether or not to watch ConfigMaps for images to pull. Must match the --config-map-selector (default true)
38+
```
39+
40+
## Sources
41+
42+
### ConfigMap
43+
44+
The ConfigMap source is useful when you want to separate the list of images that you're pulling from the installation of the cache daemon. It's also useful if you have a dynamic list
45+
of images to pull that aren't part of one of the other sources.
46+
47+
By default, all ConfigMaps that match the label selector `"app.kubernetes.io/part-of=image-cache-daemon"` will be considered as a source for the cache daemon in any namespace that it has privileges to read. If you would like to restrict the set of ConfigMaps that it reads, you can so do by changing the selector, or restricting the namespaces that the cache daemon can read via RBAC.
48+
49+
Example Usage:
50+
51+
```yaml
52+
apiVersion: v1
53+
kind: ConfigMap
54+
metadata:
55+
name: my-image-configmap
56+
labels:
57+
app.kubernetes.io/part-of: image-cache-daemon
58+
data:
59+
images: |
60+
["alpine", "debian"]
3661
```

cmd/image-cache-daemon.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"syscall"
3030
"time"
3131

32-
argoclientset "github.com/argoproj/argo/pkg/client/clientset/versioned"
32+
argoclientset "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned"
3333
"github.com/sirupsen/logrus"
3434
"github.com/spf13/cobra"
3535
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -44,16 +44,18 @@ import (
4444

4545
func NewImageCacheDaemonCommand() *cobra.Command {
4646
var (
47-
images []string
48-
nodeName string
49-
podName string
50-
podUUID string
51-
podNamespace string
47+
images []string
48+
configmapSelector string
49+
nodeName string
50+
podName string
51+
podUUID string
52+
podNamespace string
5253

5354
wardenImage string
5455
watchArgoWorkflowTemplates bool
5556
watchArgoClusterWorkflowTemplates bool
5657
watchArgoCronWorkflows bool
58+
watchConfigMaps bool
5759
resyncPeriod time.Duration
5860
)
5961

@@ -126,6 +128,13 @@ func NewImageCacheDaemonCommand() *cobra.Command {
126128
go workflowTemplateSource.Run(ctx)
127129
}
128130

131+
if watchConfigMaps {
132+
logrus.Info("watching configmaps for images to pull")
133+
configmapSource := source.NewConfigMapSource(kubeclient, resyncPeriod, source.WithConfigMapSelector(configmapSelector))
134+
ip.AddSource(ctx, configmapSource)
135+
go configmapSource.Run(ctx)
136+
}
137+
129138
go ip.Run(ctx)
130139

131140
stopCh := make(chan os.Signal, 1)
@@ -147,9 +156,11 @@ func NewImageCacheDaemonCommand() *cobra.Command {
147156
rootCmd.Flags().StringVar(&podUUID, "pod-uid", os.Getenv("POD_UUD"), "The owning pod UID")
148157
rootCmd.Flags().StringVar(&podNamespace, "pod-namespace", os.Getenv("POD_NAMESPACE"), "The namespace this pod is running in")
149158
rootCmd.Flags().StringVar(&wardenImage, "warden-image", "exiges/image-cache-warden:latest", "The image that copies a binary to pulled containers to replace the entrypoint")
159+
rootCmd.Flags().StringVar(&configmapSelector, "configmap-selector", "app.kubernetes.io/part-of=image-cache-daemon", "The selector to use when monitoring for ConfigMap sources")
150160
rootCmd.Flags().BoolVar(&watchArgoWorkflowTemplates, "watch-argo-workflow-templates", true, "Whether or not to watch workflow templates")
151161
rootCmd.Flags().BoolVar(&watchArgoClusterWorkflowTemplates, "watch-argo-cluster-workflow-templates", true, "Whether or not to watch cluster workflow templates")
152162
rootCmd.Flags().BoolVar(&watchArgoCronWorkflows, "watch-argo-cron-workflows", true, "Whether or not to watch cron workflows")
163+
rootCmd.Flags().BoolVar(&watchConfigMaps, "watch-configmaps", true, "Whether or not to watch ConfigMaps for images to pull. Must match the --config-map-selector")
153164
rootCmd.Flags().DurationVar(&resyncPeriod, "resync-period", time.Minute*15, "How often the daemon should re-pull images from all of the sources. Set to 0 to disable.")
154165

155166
return rootCmd

go.mod

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ module github.com/dcherman/image-cache-daemon
33
go 1.16
44

55
require (
6-
github.com/argoproj/argo v0.0.0-20201121022849-310e099f8252
6+
github.com/argoproj/argo-workflows/v3 v3.1.6
77
github.com/benbjohnson/clock v1.1.0
8-
github.com/imdario/mergo v0.3.11 // indirect
9-
github.com/sirupsen/logrus v1.7.0
8+
github.com/google/uuid v1.2.0 // indirect
9+
github.com/onsi/gomega v1.10.3 // indirect
10+
github.com/sirupsen/logrus v1.8.1
1011
github.com/spf13/cobra v1.1.3
1112
github.com/stretchr/testify v1.7.0
12-
golang.org/x/sys v0.0.0-20210113181707-4bcb84eeeb78 // indirect
13-
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
14-
google.golang.org/appengine v1.6.7 // indirect
15-
k8s.io/api v0.17.17
16-
k8s.io/apimachinery v0.17.17
17-
k8s.io/client-go v0.17.17
13+
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 // indirect
14+
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
15+
google.golang.org/grpc v1.33.2 // indirect
16+
google.golang.org/protobuf v1.26.0 // indirect
17+
k8s.io/api v0.21.0
18+
k8s.io/apimachinery v0.21.0
19+
k8s.io/client-go v0.21.0
20+
sigs.k8s.io/yaml v1.2.0
1821
)
1922

2023
replace sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.2.9

0 commit comments

Comments
 (0)