|
| 1 | +/* |
| 2 | +Copyright 2025 The KubeFleet Authors. |
| 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 v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + "k8s.io/apimachinery/pkg/runtime" |
| 22 | +) |
| 23 | + |
| 24 | +// +genclient |
| 25 | +// +genclient:nonNamespaced |
| 26 | +// +kubebuilder:object:root=true |
| 27 | +// +kubebuilder:resource:scope="Cluster",categories={fleet,fleet-placement} |
| 28 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 29 | + |
| 30 | +// ClusterResourceEnvelope wraps cluster-scoped resources for placement. |
| 31 | +type ClusterResourceEnvelope struct { |
| 32 | + metav1.TypeMeta `json:",inline"` |
| 33 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 34 | + |
| 35 | + // The desired state of ClusterResourceEnvelope. |
| 36 | + // +kubebuilder:validation:Required |
| 37 | + Spec EnvelopeSpec `json:"spec"` |
| 38 | + |
| 39 | + // The observed status of ClusterResourceEnvelope. |
| 40 | + // +kubebuilder:validation:Optional |
| 41 | + Status ClusterResourceEnvelopeStatus `json:"status,omitempty"` |
| 42 | +} |
| 43 | + |
| 44 | +// EnvelopeSpec helps wrap resources for placement. |
| 45 | +type EnvelopeSpec struct { |
| 46 | + // A map of wrapped manifests. |
| 47 | + // |
| 48 | + // Each manifest is uniquely identified by a string key, typically a filename that represents |
| 49 | + // the manifest. |
| 50 | + // +kubebuilder:validation:Required |
| 51 | + // +kubebuilder:validation:MinProperties=1 |
| 52 | + // +kubebuilder:validation:MaxProperties=50 |
| 53 | + Manifests map[string]Manifest `json:"manifests"` |
| 54 | +} |
| 55 | + |
| 56 | +// Manifest is a wrapped resource. |
| 57 | +type Manifest struct { |
| 58 | + // The resource data. |
| 59 | + // +kubebuilder:validation:Required |
| 60 | + // +kubebuilder:validation:EmbeddedResource |
| 61 | + // +kubebuilder:pruning:PreserveUnknownFields |
| 62 | + Data runtime.RawExtension `json:"data"` |
| 63 | +} |
| 64 | + |
| 65 | +// ClusterResourceEnvelopeStatus is the observed status of a ClusterResourceEnvelope. |
| 66 | +type ClusterResourceEnvelopeStatus struct { |
| 67 | + // +patchMergeKey=type |
| 68 | + // +patchStrategy=merge |
| 69 | + // +listType=map |
| 70 | + // +listMapKey=type |
| 71 | + // |
| 72 | + // Conditions is an array of current observed conditions for ClusterResourceEnvelope. |
| 73 | + // +kubebuilder:validation:Optional |
| 74 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 75 | + |
| 76 | + // ManifestConditions is an array of current observed conditions for each manifest in the envelope. |
| 77 | + // +kubebuilder:validation:Optional |
| 78 | + ManifestConditions []ManifestCondition `json:"manifestConditions,omitempty"` |
| 79 | +} |
| 80 | + |
| 81 | +// ManifestCondition is the observed conditions of a wrapped manifest. |
| 82 | +type ManifestCondition struct { |
| 83 | + // The name of the manifest. |
| 84 | + // +kubebuilder:validation:Required |
| 85 | + Name string `json:"name"` |
| 86 | + |
| 87 | + // +patchMergeKey=type |
| 88 | + // +patchStrategy=merge |
| 89 | + // +listType=map |
| 90 | + // +listMapKey=type |
| 91 | + // |
| 92 | + // Conditions is an array of current observed conditions for a wrapped manifest. |
| 93 | + // +kubebuilder:validation:Optional |
| 94 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 95 | +} |
| 96 | + |
| 97 | +// +genclient |
| 98 | +// +genclient:Namespaced |
| 99 | +// +kubebuilder:object:root=true |
| 100 | +// +kubebuilder:resource:scope="Namespaced",categories={fleet,fleet-placement} |
| 101 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 102 | +type ResourceEnvelope struct { |
| 103 | + metav1.TypeMeta `json:",inline"` |
| 104 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 105 | + |
| 106 | + // The desired state of ResourceEnvelope. |
| 107 | + // +kubebuilder:validation:Required |
| 108 | + Spec EnvelopeSpec `json:"spec"` |
| 109 | + |
| 110 | + // The observed status of ResourceEnvelope. |
| 111 | + // +kubebuilder:validation:Optional |
| 112 | + Status ResourceEnvelopeStatus `json:"status,omitempty"` |
| 113 | +} |
| 114 | + |
| 115 | +// ResourceEnvelopeStatus is the observed status of a ResourceEnvelope. |
| 116 | +type ResourceEnvelopeStatus struct { |
| 117 | + // +patchMergeKey=type |
| 118 | + // +patchStrategy=merge |
| 119 | + // +listType=map |
| 120 | + // +listMapKey=type |
| 121 | + // |
| 122 | + // Conditions is an array of current observed conditions for ResourceEnvelope. |
| 123 | + // +kubebuilder:validation:Optional |
| 124 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 125 | + |
| 126 | + // ManifestConditions is an array of current observed conditions for each manifest in the envelope. |
| 127 | + // +kubebuilder:validation:Optional |
| 128 | + ManifestConditions []ManifestCondition `json:"manifestConditions,omitempty"` |
| 129 | +} |
0 commit comments