Skip to content

Commit 9a1dddc

Browse files
committed
feat: create ImageMirrors for Images that match a strategy from the configuration
1 parent b48efbb commit 9a1dddc

File tree

14 files changed

+369
-133
lines changed

14 files changed

+369
-133
lines changed

api/kuik/v1alpha1/imagemirror_types.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@ import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
55
)
66

7-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
8-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
9-
107
// ImageMirrorSpec defines the desired state of ImageMirror.
8+
// +required
119
type ImageMirrorSpec struct {
12-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
13-
// Important: Run "make" to regenerate code after modifying this file
14-
15-
// Foo is an example field of ImageMirror. Edit imagemirror_types.go to remove/update
16-
Foo string `json:"foo,omitempty"`
10+
// ImageReference is the reference of the image to mirror
11+
ImageReference `json:",inline"`
12+
// TargetRegistry is the registry on which the image should be mirrored
13+
TargetRegistry string `json:"targetRegistry"`
1714
}
1815

1916
// ImageMirrorStatus defines the observed state of ImageMirror.
2017
type ImageMirrorStatus struct {
21-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
22-
// Important: Run "make" to regenerate code after modifying this file
18+
// Digest is the digest of the mirrored image
19+
Digest string `json:"digest,omitempty"`
20+
Conditions []metav1.Condition `json:"conditions,omitempty"`
2321
}
2422

2523
// +kubebuilder:object:root=true
2624
// +kubebuilder:subresource:status
27-
// +kubebuilder:resource:scope=Cluster
25+
// +kubebuilder:resource:scope=Cluster,shortName=imgmir
26+
// +kubebuilder:printcolumn:name="Image",type="string",JSONPath=".spec.path"
27+
// +kubebuilder:printcolumn:name="From",type="string",JSONPath=".spec.registry"
28+
// +kubebuilder:printcolumn:name="To",type="string",JSONPath=".spec.targetRegistry"
29+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
2830

2931
// ImageMirror is the Schema for the imagemirrors API.
3032
type ImageMirror struct {

api/kuik/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,25 +231,25 @@ func main() {
231231
Client: mgr.GetClient(),
232232
Scheme: mgr.GetScheme(),
233233
UnusedImageTTL: time.Hour * time.Duration(unusedImageTTL),
234+
Config: configuration,
234235
}).SetupWithManager(mgr); err != nil {
235236
setupLog.Error(err, "unable to create controller", "controller", "Image")
236237
os.Exit(1)
237238
}
238239
if err = (&kuikcontroller.RegistryMonitorReconciler{
239-
Client: mgr.GetClient(),
240-
Scheme: mgr.GetScheme(),
241-
MonitorPools: map[string]pond.Pool{},
242-
Routing: &configuration.Routing,
243-
MonitoringEnabled: configuration.Monitoring.Enabled,
240+
Client: mgr.GetClient(),
241+
Scheme: mgr.GetScheme(),
242+
MonitorPools: map[string]pond.Pool{},
243+
Config: configuration,
244244
}).SetupWithManager(mgr); err != nil {
245245
setupLog.Error(err, "unable to create controller", "controller", "RegistryMonitor")
246246
os.Exit(1)
247247
}
248248
// nolint:goconst
249249
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
250250
podDefaulter := webhookcorev1.PodCustomDefaulter{
251-
Client: mgr.GetClient(),
252-
Routing: &configuration.Routing,
251+
Client: mgr.GetClient(),
252+
Config: configuration,
253253
}
254254
if err = webhookcorev1.SetupPodWebhookWithManager(mgr, &podDefaulter); err != nil {
255255
setupLog.Error(err, "unable to create webhook", "webhook", "Pod")

config/crd/bases/kuik.enix.io_imagemirrors.yaml

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@ spec:
1111
kind: ImageMirror
1212
listKind: ImageMirrorList
1313
plural: imagemirrors
14+
shortNames:
15+
- imgmir
1416
singular: imagemirror
1517
scope: Cluster
1618
versions:
17-
- name: v1alpha1
19+
- additionalPrinterColumns:
20+
- jsonPath: .spec.path
21+
name: Image
22+
type: string
23+
- jsonPath: .spec.registry
24+
name: From
25+
type: string
26+
- jsonPath: .spec.targetRegistry
27+
name: To
28+
type: string
29+
- jsonPath: .metadata.creationTimestamp
30+
name: Age
31+
type: date
32+
name: v1alpha1
1833
schema:
1934
openAPIV3Schema:
2035
description: ImageMirror is the Schema for the imagemirrors API.
@@ -39,13 +54,83 @@ spec:
3954
spec:
4055
description: ImageMirrorSpec defines the desired state of ImageMirror.
4156
properties:
42-
foo:
43-
description: Foo is an example field of ImageMirror. Edit imagemirror_types.go
44-
to remove/update
57+
path:
58+
description: Path is a string identifying the image in a registry
4559
type: string
60+
registry:
61+
description: Registry is the registry where the image is located
62+
type: string
63+
targetRegistry:
64+
description: TargetRegistry is the registry on which the image should
65+
be mirrored
66+
type: string
67+
required:
68+
- path
69+
- registry
70+
- targetRegistry
4671
type: object
4772
status:
4873
description: ImageMirrorStatus defines the observed state of ImageMirror.
74+
properties:
75+
conditions:
76+
items:
77+
description: Condition contains details for one aspect of the current
78+
state of this API Resource.
79+
properties:
80+
lastTransitionTime:
81+
description: |-
82+
lastTransitionTime is the last time the condition transitioned from one status to another.
83+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
84+
format: date-time
85+
type: string
86+
message:
87+
description: |-
88+
message is a human readable message indicating details about the transition.
89+
This may be an empty string.
90+
maxLength: 32768
91+
type: string
92+
observedGeneration:
93+
description: |-
94+
observedGeneration represents the .metadata.generation that the condition was set based upon.
95+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
96+
with respect to the current state of the instance.
97+
format: int64
98+
minimum: 0
99+
type: integer
100+
reason:
101+
description: |-
102+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
103+
Producers of specific condition types may define expected values and meanings for this field,
104+
and whether the values are considered a guaranteed API.
105+
The value should be a CamelCase string.
106+
This field may not be empty.
107+
maxLength: 1024
108+
minLength: 1
109+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
110+
type: string
111+
status:
112+
description: status of the condition, one of True, False, Unknown.
113+
enum:
114+
- "True"
115+
- "False"
116+
- Unknown
117+
type: string
118+
type:
119+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
120+
maxLength: 316
121+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
122+
type: string
123+
required:
124+
- lastTransitionTime
125+
- message
126+
- reason
127+
- status
128+
- type
129+
type: object
130+
type: array
131+
digest:
132+
description: Digest is the digest of the mirrored image
133+
type: string
49134
type: object
50135
type: object
51136
served: true

helm/kube-image-keeper/crds/kuik.enix.io_imagemirrors.yaml

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ spec:
1010
kind: ImageMirror
1111
listKind: ImageMirrorList
1212
plural: imagemirrors
13+
shortNames:
14+
- imgmir
1315
singular: imagemirror
1416
scope: Cluster
1517
versions:
16-
- name: v1alpha1
18+
- additionalPrinterColumns:
19+
- jsonPath: .spec.path
20+
name: Image
21+
type: string
22+
- jsonPath: .spec.registry
23+
name: From
24+
type: string
25+
- jsonPath: .spec.targetRegistry
26+
name: To
27+
type: string
28+
- jsonPath: .metadata.creationTimestamp
29+
name: Age
30+
type: date
31+
name: v1alpha1
1732
schema:
1833
openAPIV3Schema:
1934
description: ImageMirror is the Schema for the imagemirrors API.
@@ -38,13 +53,83 @@ spec:
3853
spec:
3954
description: ImageMirrorSpec defines the desired state of ImageMirror.
4055
properties:
41-
foo:
42-
description: Foo is an example field of ImageMirror. Edit imagemirror_types.go
43-
to remove/update
56+
path:
57+
description: Path is a string identifying the image in a registry
4458
type: string
59+
registry:
60+
description: Registry is the registry where the image is located
61+
type: string
62+
targetRegistry:
63+
description: TargetRegistry is the registry on which the image should
64+
be mirrored
65+
type: string
66+
required:
67+
- path
68+
- registry
69+
- targetRegistry
4570
type: object
4671
status:
4772
description: ImageMirrorStatus defines the observed state of ImageMirror.
73+
properties:
74+
conditions:
75+
items:
76+
description: Condition contains details for one aspect of the current
77+
state of this API Resource.
78+
properties:
79+
lastTransitionTime:
80+
description: |-
81+
lastTransitionTime is the last time the condition transitioned from one status to another.
82+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
83+
format: date-time
84+
type: string
85+
message:
86+
description: |-
87+
message is a human readable message indicating details about the transition.
88+
This may be an empty string.
89+
maxLength: 32768
90+
type: string
91+
observedGeneration:
92+
description: |-
93+
observedGeneration represents the .metadata.generation that the condition was set based upon.
94+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
95+
with respect to the current state of the instance.
96+
format: int64
97+
minimum: 0
98+
type: integer
99+
reason:
100+
description: |-
101+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
102+
Producers of specific condition types may define expected values and meanings for this field,
103+
and whether the values are considered a guaranteed API.
104+
The value should be a CamelCase string.
105+
This field may not be empty.
106+
maxLength: 1024
107+
minLength: 1
108+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
109+
type: string
110+
status:
111+
description: status of the condition, one of True, False, Unknown.
112+
enum:
113+
- "True"
114+
- "False"
115+
- Unknown
116+
type: string
117+
type:
118+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
119+
maxLength: 316
120+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
121+
type: string
122+
required:
123+
- lastTransitionTime
124+
- message
125+
- reason
126+
- status
127+
- type
128+
type: object
129+
type: array
130+
digest:
131+
description: Digest is the digest of the mirrored image
132+
type: string
48133
type: object
49134
type: object
50135
served: true

helm/kube-image-keeper/templates/mutatingwebhookconfiguration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if gt (len .Values.configuration.routing.strategies) 0 }}
1+
{{- if gt (len .Values.configuration.strategies) 0 }}
22
apiVersion: admissionregistration.k8s.io/v1
33
kind: MutatingWebhookConfiguration
44
metadata:

helm/kube-image-keeper/values.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ metrics:
140140
configuration:
141141
monitoring:
142142
enabled: true
143-
routing:
144-
activeCheck:
145-
enabled: true
146-
timeout: 1s
147-
strategies: []
148-
# - paths:
149-
# - enix/x509-certificate-exporter
150-
# registries:
151-
# - docker.io
152-
# - quay.io
143+
activeCheck:
144+
enabled: true
145+
timeout: 1s
146+
strategies: []
147+
# - paths:
148+
# - enix/x509-certificate-exporter
149+
# registries:
150+
# - url: docker.io
151+
# - url: quay.io
152+
# mirroringEnabled: true
153153

0 commit comments

Comments
 (0)