11package v1alpha1
22
33import (
4+ "path"
5+ "strings"
6+
47 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
58)
69
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-
1010// ImageSetMirrorSpec defines the desired state of ImageSetMirror.
1111type ImageSetMirrorSpec 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 ImageSetMirror. Edit imagesetmirror_types.go to remove/update
16- Foo string `json:"foo,omitempty"`
12+ ImageMatcher string `json:"imageMatcher,omitempty"`
13+ Cleanup Cleanup `json:"cleanup,omitempty"`
14+ Mirrors Mirrors `json:"mirrors,omitempty"`
1715}
1816
1917// ImageSetMirrorStatus defines the observed state of ImageSetMirror.
2018type ImageSetMirrorStatus struct {
21- // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
22- // Important: Run "make" to regenerate code after modifying this file
19+ // +listType=map
20+ // +listMapKey=image
21+ MatchedImages []MatchedImage `json:"matchedImages,omitempty"`
2322}
2423
2524// +kubebuilder:object:root=true
2625// +kubebuilder:subresource:status
26+ // +kubebuilder:resource:shortName=ism
2727
2828// ImageSetMirror is the Schema for the imagesetmirrors API.
2929type ImageSetMirror struct {
@@ -43,6 +43,54 @@ type ImageSetMirrorList struct {
4343 Items []ImageSetMirror `json:"items"`
4444}
4545
46+ // Cleanup defines a cleanup strategy
47+ type Cleanup struct {
48+ Enabled bool `json:"enabled,omitempty"`
49+ Retention metav1.Duration `json:"retention,omitempty"`
50+ }
51+
52+ type Mirror struct {
53+ Registry string `json:"registry,omitempty"`
54+ Path string `json:"path,omitempty"`
55+ CredentialSecret * CredentialSecret `json:"credentialSecret,omitempty"`
56+ Cleanup * Cleanup `json:"cleanup,omitempty"`
57+ }
58+
59+ type Mirrors []Mirror
60+
61+ type CredentialSecret struct {
62+ // Name is the name of the secret
63+ Name string `json:"name,omitempty"`
64+ // Namespace is the namespace where the secret is located.
65+ // This value is ignored for namespaced resources and the namespace of the parent object is used instead.
66+ Namespace string `json:"namespace,omitempty"` // TODO: make this field required for ClusterImageSetMirrors and prohibited for ImageSetMirrors
67+ }
68+
69+ type MatchedImage struct {
70+ Image string `json:"image"`
71+ // +listType=map
72+ // +listMapKey=image
73+ Mirrors []MirrorStatus `json:"mirrors,omitempty"`
74+ UnusedSince * metav1.Duration `json:"unusedSince,omitempty"`
75+ }
76+
77+ type MirrorStatus struct {
78+ Image string `json:"image"`
79+ MirroredAt * metav1.Time `json:"mirroredAt,omitempty"`
80+ }
81+
4682func init () {
4783 SchemeBuilder .Register (& ImageSetMirror {}, & ImageSetMirrorList {})
4884}
85+
86+ func (m Mirrors ) GetCredentialSecretForImage (image string ) (cred * CredentialSecret ) {
87+ longestPrefixLen := 0
88+ for _ , mirror := range m {
89+ prefix := path .Join (mirror .Registry , mirror .Path )
90+ if strings .HasPrefix (image , prefix ) && len (prefix ) > longestPrefixLen {
91+ cred = mirror .CredentialSecret
92+ longestPrefixLen = len (prefix )
93+ }
94+ }
95+ return
96+ }
0 commit comments