|
| 1 | +package v1 |
| 2 | + |
| 3 | +import ( |
| 4 | + corev1 "k8s.io/api/core/v1" |
| 5 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 6 | +) |
| 7 | + |
| 8 | +// NodeImageSetSpec defines the desired state of NodeImageSet |
| 9 | +type NodeImageSetSpec struct { |
| 10 | + // ImageSet is a list of image sets to be downloaded. |
| 11 | + ImageSet []ImageSet `json:"imageSet"` |
| 12 | + |
| 13 | + // NodeName is the name of the node where the image is downloaded. |
| 14 | + NodeName string `json:"nodeName"` |
| 15 | + |
| 16 | + // ImagePullSecrets is a list of secret names that contain credentials for authenticating with container registries |
| 17 | + // +optional |
| 18 | + ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` |
| 19 | + |
| 20 | + // ImageDownloadRetryLimit specifies the maximum number of retry attempts for image downloads |
| 21 | + // +optional |
| 22 | + // +kubebuilder:default:=3 |
| 23 | + ImageDownloadRetryLimit int32 `json:"imageDownloadRetryLimit,omitempty"` |
| 24 | +} |
| 25 | + |
| 26 | +type ImageSet struct { |
| 27 | + // image is the name of the image. |
| 28 | + Image string `json:"image"` |
| 29 | + |
| 30 | + // Registry Policy is the policy for downloading images from the registry. |
| 31 | + RegistryPolicy RegistryPolicy `json:"registryPolicy"` |
| 32 | +} |
| 33 | + |
| 34 | +type RegistryPolicy string |
| 35 | + |
| 36 | +const ( |
| 37 | + // RegistryPolicyDefault download images according to containerd host configuration. |
| 38 | + // If registry mirror are configured, it attempts to download images from registry mirror first, |
| 39 | + // then falls back to upstream registry. |
| 40 | + RegistryPolicyDefault RegistryPolicy = "Default" |
| 41 | + |
| 42 | + // RegistryPolicyMirrorOnly downloads images only from registry mirrors defined in the containerd host configuration. |
| 43 | + RegistryPolicyMirrorOnly RegistryPolicy = "MirrorOnly" |
| 44 | +) |
| 45 | + |
| 46 | +// NodeImageSetStatus defines the observed state of NodeImageSet |
| 47 | +type NodeImageSetStatus struct { |
| 48 | + // The generation observed by the controller. |
| 49 | + // +optional |
| 50 | + ObservedGeneration int64 `json:"observedGeneration,omitempty"` |
| 51 | + |
| 52 | + // Conditions represent the latest available observations of an object's state |
| 53 | + // +listType=map |
| 54 | + // +listMapKey=type |
| 55 | + // +optional |
| 56 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 57 | + |
| 58 | + // DesiredImages is the number of images that need to be downloaded. |
| 59 | + // +optional |
| 60 | + //+kubebuilder:default:=0 |
| 61 | + DesiredImages int `json:"desiredImages,omitempty"` |
| 62 | + |
| 63 | + // AvailableImages is the number of images that have completed downloading. |
| 64 | + // +optional |
| 65 | + //+kubebuilder:default:=0 |
| 66 | + AvailableImages int `json:"availableImages,omitempty"` |
| 67 | + |
| 68 | + // DownloadFailedImages is the number of images that failed to download. |
| 69 | + // +optional |
| 70 | + //+kubebuilder:default:=0 |
| 71 | + DownloadFailedImages int `json:"downloadFailedImages,omitempty"` |
| 72 | +} |
| 73 | + |
| 74 | +const ( |
| 75 | + ConditionImageAvailable = "ImageAvailable" |
| 76 | + ConditionImageDownloadComplete = "ImageDownloadComplete" |
| 77 | + ConditionImageDownloadFailed = "ImageDownloadFailed" |
| 78 | +) |
| 79 | + |
| 80 | +// +kubebuilder:object:root=true |
| 81 | +// +kubebuilder:subresource:status |
| 82 | +// +kubebuilder:resource:scope=Cluster |
| 83 | + |
| 84 | +// NodeImageSet is the Schema for the nodeimagesets API |
| 85 | +type NodeImageSet struct { |
| 86 | + metav1.TypeMeta `json:",inline"` |
| 87 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 88 | + |
| 89 | + Spec NodeImageSetSpec `json:"spec,omitempty"` |
| 90 | + Status NodeImageSetStatus `json:"status,omitempty"` |
| 91 | +} |
| 92 | + |
| 93 | +// +kubebuilder:object:root=true |
| 94 | + |
| 95 | +// NodeImageSetList contains a list of NodeImageSet |
| 96 | +type NodeImageSetList struct { |
| 97 | + metav1.TypeMeta `json:",inline"` |
| 98 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 99 | + Items []NodeImageSet `json:"items"` |
| 100 | +} |
| 101 | + |
| 102 | +func init() { |
| 103 | + SchemeBuilder.Register(&NodeImageSet{}, &NodeImageSetList{}) |
| 104 | +} |
0 commit comments