@@ -20,85 +20,227 @@ import (
20
20
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
21
)
22
22
23
- // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24
- // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25
-
26
23
// ImageUpdaterSpec defines the desired state of ImageUpdater
24
+ // It specifies which applications to target, default update strategies,
25
+ // and a list of images to manage.
27
26
type ImageUpdaterSpec struct {
28
- // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29
- // Important: Run "make" to regenerate code after modifying this file
30
-
31
- // Foo is an example field of ImageUpdater. Edit imageupdater_types.go to remove/update
32
- // Foo string `json:"foo,omitempty"`
33
-
34
- // ApplicationRef indicates the set of applications to be managed
35
- ApplicationRefs []ApplicationRef `json:"applicationRefs,omitempty"`
36
-
37
- // Images contains a list of configurations that how images should be updated
38
- Images []ImageUpdateConfig `json:"images,omitempty"`
27
+ // Namespace indicates the target namespace of the applications.
28
+ // This is the namespace where the controller will look for Argo CD Applications
29
+ // matching the criteria in ApplicationRefs.
30
+ // +kubebuilder:validation:Required
31
+ Namespace string `json:"namespace"`
32
+
33
+ // CommonUpdateSettings provides global default settings for update strategies,
34
+ // tag filtering, pull secrets, etc., for all applications matched by this CR.
35
+ // These can be overridden at the ApplicationRef or ImageConfig level.
36
+ // +optional
37
+ * CommonUpdateSettings `json:"commonUpdateSettings,omitempty"`
38
+
39
+ // WriteBackConfig provides global default settings for how and where to write back image updates.
40
+ // This can be overridden at the ApplicationRef level.
41
+ // +optional
42
+ * WriteBackConfig `json:"writeBackConfig,omitempty"`
43
+
44
+ // ApplicationRefs indicates the set of applications to be managed.
45
+ // ApplicationRefs is a list of rules to select Argo CD Applications within the `spec.namespace`.
46
+ // Each reference can also provide specific overrides for the global settings defined above.
47
+ // +kubebuilder:validation:MinItems=1
48
+ ApplicationRefs []ApplicationRef `json:"applicationRefs"`
49
+
50
+ // Images contains a list of configurations that how images should be updated.
51
+ // These rules apply to all applications selected by ApplicationRefs, and each
52
+ // image can override global/ApplicationRef settings.
53
+ // +kubebuilder:validation:MinItems=1
54
+ Images []ImageConfig `json:"images"`
39
55
}
40
56
41
- // ImageUpdaterStatus defines the observed state of ImageUpdater
42
- type ImageUpdaterStatus struct {
43
- // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
44
- // Important: Run "make" to regenerate code after modifying this file
57
+ // ApplicationRef contains various criteria by which to include applications for managing by image updater
58
+ type ApplicationRef struct {
59
+ // NamePattern indicates the glob pattern for application name
60
+ // +kubebuilder:validation:Required
61
+ NamePattern string `json:"namePattern"`
45
62
46
- // LastUpdatedAt indicates when the image updater last ran
47
- LastUpdatedAt * metav1.Time `json:"reconciledAt,omitempty"`
63
+ // LabelSelectors indicates the label selectors to apply for application selection
64
+ // +optional
65
+ LabelSelectors * metav1.LabelSelector `json:"labelSelectors,omitempty"`
48
66
49
- // ImageStatus indicates the detailed status for the list of managed images
50
- ImageStatus []ImageStatus `json:"imageStatus,omitempty"`
51
- }
67
+ // --- Overrides for spec-level settings, specific to THIS ApplicationRef ---
52
68
53
- // +kubebuilder:object:root=true
54
- // +kubebuilder:subresource:status
69
+ // CommonUpdateSettings overrides the global CommonUpdateSettings for applications
70
+ // matched by this selector.
71
+ // +optional
72
+ * CommonUpdateSettings `json:"commonUpdateSettings,omitempty"`
55
73
56
- // ImageUpdater is the Schema for the imageupdaters API
57
- type ImageUpdater struct {
58
- metav1.TypeMeta `json:",inline"`
59
- metav1.ObjectMeta `json:"metadata,omitempty"`
74
+ // WriteBackConfig overrides the global WriteBackConfig settings for applications
75
+ // matched by this selector.
76
+ // +optional
77
+ * WriteBackConfig `json:"writeBackConfig,omitempty"`
78
+ }
60
79
61
- Spec ImageUpdaterSpec `json:"spec,omitempty"`
62
- Status ImageUpdaterStatus `json:"status,omitempty"`
80
+ // GitConfig defines parameters for Git interaction when `writeBackMethod` involves Git.
81
+ type GitConfig struct {
82
+ // Repository URL to commit changes to.
83
+ // If not specified here or at the spec level, the controller MUST infer it from the
84
+ // Argo CD Application's `spec.source.repoURL`. This field allows overriding that.
85
+ // +optional
86
+ Repository string `json:"repository,omitempty"`
87
+
88
+ // Branch to commit updates to.
89
+ // Required if write-back method is Git and this is not specified at the spec level.
90
+ // +optional
91
+ Branch string `json:"branch,omitempty"`
92
+
93
+ // WriteBackTarget defines the path and type of file to update in the Git repository.
94
+ // Examples: "helmvalues:./helm/values.yaml", "kustomization:./kustomize/overlays/production".
95
+ // For ApplicationSet usage, `{{ .app.path.path }}` should be resolved by ApplicationSet
96
+ // before this CR is generated, resulting in a concrete path here.
97
+ // Required if write-back method is Git and this is not specified at the spec level.
98
+ // +optional
99
+ WriteBackTarget string `json:"writeBackTarget,omitempty"`
63
100
}
64
101
65
- // +kubebuilder:object:root=true
102
+ // ImageConfig defines how a specific container image should be discovered, updated,
103
+ // and how those updates should be reflected in application manifests.
104
+ type ImageConfig struct {
105
+ // Alias is a short, user-defined name for this image configuration.
106
+ // This field is mandatory.
107
+ // +kubebuilder:validation:Required
108
+ Alias string `json:"alias"`
109
+
110
+ // ImageName is the full identifier of the image to be tracked,
111
+ // including the registry (if not Docker Hub), the image name, and an initial/current tag or version.
112
+ // This is the string used to query the container registry and also as a base for finding updates.
113
+ // Example: "docker.io/library/nginx:1.17.10", "quay.io/prometheus/node-exporter:v1.5.0".
114
+ // This field is mandatory.
115
+ // +kubebuilder:validation:Required
116
+ ImageName string `json:"imageName"`
117
+
118
+ // --- Overrides for spec-level or ApplicationRef-level defaults, specific to THIS image ---
119
+
120
+ // CommonUpdateSettings overrides the effective default CommonUpdateSettings for this specific image.
121
+ // +optional
122
+ * CommonUpdateSettings `json:"commonUpdateSettings,omitempty"`
123
+
124
+ // Platforms specifies a list of target platforms (e.g., "linux/amd64", "linux/arm64").
125
+ // If specified, the image updater will consider these platforms when checking for new versions or digests.
126
+ // +listType=atomic
127
+ // +optional
128
+ Platforms []string `json:"platforms,omitempty"`
129
+
130
+ // ManifestTarget defines how and where to update this image in Kubernetes manifests.
131
+ // Only one of Helm or Kustomize should be specified within this block.
132
+ // This whole block is optional if the image update isn't written to a manifest in a structured way.
133
+ // +optional
134
+ * ManifestTarget `json:"manifestTargets,omitempty"`
135
+ }
66
136
67
- // ImageUpdaterList contains a list of ImageUpdater
68
- type ImageUpdaterList struct {
69
- metav1.TypeMeta `json:",inline"`
70
- metav1.ListMeta `json:"metadata,omitempty"`
71
- Items []ImageUpdater `json:"items"`
137
+ // CommonUpdateSettings groups common update strategy settings that can be applied
138
+ // globally, per ApplicationRef, or per ImageConfig.
139
+ type CommonUpdateSettings struct {
140
+ // UpdateStrategy defines the update strategy to apply.
141
+ // Examples: "semver", "latest", "digest", "name".
142
+ // This acts as the default if not overridden at a more specific level.
143
+ // +optional
144
+ // +kubebuilder:default:="semver"
145
+ UpdateStrategy string `json:"updateStrategy,omitempty"`
146
+
147
+ // ForceUpdate specifies whether updates should be forced.
148
+ // This acts as the default if not overridden.
149
+ // +optional
150
+ // +kubebuilder:default:=false
151
+ ForceUpdate bool `json:"forceUpdate,omitempty"`
152
+
153
+ // AllowTags is a regex pattern for tags to allow.
154
+ // This acts as the default if not overridden.
155
+ // +optional
156
+ AllowTags string `json:"allowTags,omitempty"`
157
+
158
+ // IgnoreTags is a list of glob-like patterns of tags to ignore.
159
+ // This acts as the default and can be overridden at more specific levels.
160
+ // +listType=atomic
161
+ // +optional
162
+ IgnoreTags []string `json:"ignoreTags,omitempty"`
163
+
164
+ // PullSecret is the pull secret to use for images.
165
+ // This acts as the default if not overridden.
166
+ // +optional
167
+ PullSecret string `json:"pullSecret,omitempty"`
72
168
}
73
169
74
- // ApplicationRef contains various criteria by which to include applications for managing by image updater
75
- type ApplicationRef struct {
76
- // DestinationPattern indicates the glob pattern for destination cluster
77
- DestinationPattern string `json:"destinationPattern,omitempty"`
170
+ // WriteBackConfig defines how and where to write back image updates.
171
+ // It includes the method (e.g., git, direct Application update) and
172
+ // specific configurations for that method, like Git settings.
173
+ type WriteBackConfig struct {
174
+ // Method defines the method for writing back updated image versions.
175
+ // This acts as the default if not overridden.
176
+ // +optional
177
+ // +kubebuilder:default:="argocd"
178
+ Method string `json:"method,omitempty"`
179
+
180
+ // GitConfig provides Git configuration settings if the write-back method involves Git.
181
+ // +optional
182
+ * GitConfig `json:"gitConfig,omitempty"`
183
+ }
78
184
79
- // Namespace indicates the target namespace of the application
80
- Namespace * string `json:"namespace,omitempty"`
185
+ // ManifestTarget specifies the mechanism and details for updating image references in application manifests.
186
+ // Only one of the fields (Helm, Kustomize) should be set, dictating the update method.
187
+ // +kubebuilder:validation:XValidation:rule="has(self.helm) ? !has(self.kustomize) : has(self.kustomize)",message="Exactly one of helm or kustomize must be specified within manifestTargets if the block is present."
188
+ type ManifestTarget struct {
189
+ // Helm specifies update parameters if the target manifest is managed by Helm
190
+ // and updates are to be made to Helm values files.
191
+ // +optional
192
+ Helm * HelmTarget `json:"helm,omitempty"`
193
+
194
+ // Kustomize specifies update parameters if the target manifest is managed by Kustomize
195
+ // and updates involve changing image tags in Kustomize configurations.
196
+ // +optional
197
+ Kustomize * KustomizeTarget `json:"kustomize,omitempty"`
198
+ }
81
199
82
- // NamePattern indicates the glob pattern for application name
83
- NamePattern * string `json:"namePattern,omitempty"`
200
+ // HelmTarget defines parameters for updating image references within Helm values.
201
+ type HelmTarget struct {
202
+ // Name is the dot-separated path to the Helm key for the image repository/name part.
203
+ // Example: "image.repository", "frontend.deployment.image.name".
204
+ // This field is required if the Helm target is used.
205
+ Name string `json:"name"`
84
206
85
- // LabelSelectors indicates the label selectors to apply for application selection
86
- LabelSelectors * metav1.LabelSelector `json:"labelSelectors,omitempty"`
207
+ // Tag is the dot-separated path to the Helm key for the image tag part.
208
+ // Example: "image.tag", "frontend.deployment.image.version".
209
+ // This field is required if the Helm target is used.
210
+ Tag string `json:"tag"`
211
+
212
+ // Spec is an optional dot-separated path to a Helm key where the full image string
213
+ // (e.g., "image/name:1.0") should be written.
214
+ // Use this if your Helm chart expects the entire image reference in a single field,
215
+ // rather than separate name/tag fields. If this is set, other Helm parameter-related
216
+ // options will be ignored.
217
+ // +optional
218
+ Spec string `json:"spec,omitempty"`
87
219
}
88
220
89
- // ImageUpdateConfig specifies how a particular image should be updated
90
- type ImageUpdateConfig struct {
91
- // Name indicates the image name
221
+ // KustomizeTarget defines parameters for updating image references within Kustomize configurations.
222
+ type KustomizeTarget struct {
223
+ // Name is the image name (which can include the registry and an initial tag)
224
+ // as it appears in the `images` list of a kustomization.yaml file that needs to be updated.
225
+ // The updater will typically change the tag or add a digest to this entry.
226
+ // Example: "docker.io/library/nginx".
227
+ // This field is required if the Kustomize target is used.
92
228
Name string `json:"name"`
229
+ }
93
230
94
- // Version indicates the version constraint for the update
95
- Version string `json:"version"`
231
+ //------------------------Status---------------------------------------------//
96
232
97
- // Path indicates the path to the image in the workload spec
98
- Path string `json:"path"`
233
+ // ImageUpdaterStatus defines the observed state of ImageUpdater
234
+ type ImageUpdaterStatus struct {
235
+ // Important: Run "make" to regenerate code after modifying this file
99
236
100
- // Strategy indicates the update strategy for this image
101
- Strategy string `json:"strategy"`
237
+ // LastUpdatedAt indicates when the image updater last ran
238
+ LastUpdatedAt * metav1.Time `json:"reconciledAt,omitempty"`
239
+
240
+ // ImageStatus indicates the detailed status for the list of managed images
241
+ ImageStatus []ImageStatus `json:"imageStatus,omitempty"`
242
+
243
+ Conditions []metav1.Condition `json:"conditions,omitempty"`
102
244
}
103
245
104
246
// ImageStatus contains information for an image:version and its update status in hosting applications
@@ -122,6 +264,27 @@ type ImageApplicationLastUpdated struct {
122
264
LastUpdatedAt metav1.Time `json:"lastUpdatedAt,omitempty"`
123
265
}
124
266
267
+ // +kubebuilder:object:root=true
268
+ // +kubebuilder:subresource:status
269
+
270
+ // ImageUpdater is the Schema for the imageupdaters API
271
+ type ImageUpdater struct {
272
+ metav1.TypeMeta `json:",inline"`
273
+ metav1.ObjectMeta `json:"metadata,omitempty"`
274
+
275
+ Spec ImageUpdaterSpec `json:"spec,omitempty"`
276
+ Status ImageUpdaterStatus `json:"status,omitempty"`
277
+ }
278
+
279
+ // +kubebuilder:object:root=true
280
+
281
+ // ImageUpdaterList contains a list of ImageUpdater
282
+ type ImageUpdaterList struct {
283
+ metav1.TypeMeta `json:",inline"`
284
+ metav1.ListMeta `json:"metadata,omitempty"`
285
+ Items []ImageUpdater `json:"items"`
286
+ }
287
+
125
288
func init () {
126
289
SchemeBuilder .Register (& ImageUpdater {}, & ImageUpdaterList {})
127
290
}
0 commit comments