|
| 1 | +/* |
| 2 | +Copyright 2025. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1beta1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +type ImageState string |
| 24 | + |
| 25 | +const ( |
| 26 | + // ImageExists means that image exists in the specified repo |
| 27 | + ImageExists ImageState = "Exists" |
| 28 | + // ImageNotExists means that image does not exist in the specified repo |
| 29 | + ImageDoesNotExist ImageState = "DoesNotExist" |
| 30 | +) |
| 31 | + |
| 32 | +// ModuleImageSpec describes the image whose state needs to be queried |
| 33 | +type ModuleImageSpec struct { |
| 34 | + // image |
| 35 | + Image string `json:"image"` |
| 36 | + // generation counter of the image config |
| 37 | + Generation int `json:"generation"` |
| 38 | +} |
| 39 | + |
| 40 | +// ModuleImagesConfigSpec describes the images of the Module whose status needs to be verified |
| 41 | +// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 42 | +// +kubebuilder:validation:Required |
| 43 | +type ModuleImagesConfigSpec struct { |
| 44 | + Images []ModuleImageSpec `json:"images"` |
| 45 | +} |
| 46 | + |
| 47 | +type ModuleImageState struct { |
| 48 | + // image |
| 49 | + Image string `json:"image"` |
| 50 | + // status of the image |
| 51 | + // one of: Exists, notExists |
| 52 | + Status ImageState `json:"status"` |
| 53 | + // observedGeneration counter is updated on each status update |
| 54 | + ObservedGeneration int `json:"observedGeneration"` |
| 55 | +} |
| 56 | + |
| 57 | +// ModuleImagesConfigStatus describes the status of the images that need to be verified (defined in the spec) |
| 58 | +// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 59 | +// +kubebuilder:validation:Required |
| 60 | +type ModuleImagesConfigStatus struct { |
| 61 | + ImagesStates []ModuleImageState `json:"imagesStates"` |
| 62 | +} |
| 63 | + |
| 64 | +// +kubebuilder:object:root=true |
| 65 | +// +kubebuilder:subresource:status |
| 66 | + |
| 67 | +// ModuleImagesConfig keeps the request for images' state for a KMM Module. |
| 68 | +// +kubebuilder:resource:path=moduleimagesconfigs,scope=Namespaced,shortName=mic |
| 69 | +// +operator-sdk:csv:customresourcedefinitions:displayName="Module Images Config" |
| 70 | +type ModuleImagesConfig struct { |
| 71 | + metav1.TypeMeta `json:",inline"` |
| 72 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 73 | + |
| 74 | + Spec ModuleImagesConfigSpec `json:"spec,omitempty"` |
| 75 | + Status ModuleImagesConfigStatus `json:"status,omitempty"` |
| 76 | +} |
| 77 | + |
| 78 | +// +kubebuilder:object:root=true |
| 79 | + |
| 80 | +// ModuleImagesConfigList is a list of ModuleImagesConfig objects. |
| 81 | +type ModuleImagesConfigList struct { |
| 82 | + metav1.TypeMeta `json:",inline"` |
| 83 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 84 | + |
| 85 | + // List of ModuleImagesConfig. More info: |
| 86 | + // https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md |
| 87 | + Items []ModuleImagesConfig `json:"items"` |
| 88 | +} |
| 89 | + |
| 90 | +func init() { |
| 91 | + SchemeBuilder.Register(&ModuleImagesConfig{}, &ModuleImagesConfigList{}) |
| 92 | +} |
0 commit comments