|
| 1 | +/* |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | +package v2alpha1 |
| 17 | + |
| 18 | +import ( |
| 19 | + corev1 "k8s.io/api/core/v1" |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// OperatorSpec defines the desired state of Operator |
| 24 | +type OperatorSpec struct{} |
| 25 | + |
| 26 | +// OperatorStatus describes the observed state of an operator and its components. |
| 27 | +type OperatorStatus struct { |
| 28 | + // Components describes resources that compose the operator. |
| 29 | + // +optional |
| 30 | + Components *Components `json:"components,omitempty"` |
| 31 | +} |
| 32 | + |
| 33 | +// ConditionType codifies a condition's type. |
| 34 | +type ConditionType string |
| 35 | + |
| 36 | +// Condition represent the latest available observations of an component's state. |
| 37 | +type Condition struct { |
| 38 | + // Type of condition. |
| 39 | + Type ConditionType `json:"type"` |
| 40 | + // Status of the condition, one of True, False, Unknown. |
| 41 | + Status corev1.ConditionStatus `json:"status"` |
| 42 | + // The reason for the condition's last transition. |
| 43 | + // +optional |
| 44 | + Reason string `json:"reason,omitempty"` |
| 45 | + // A human readable message indicating details about the transition. |
| 46 | + // +optional |
| 47 | + Message string `json:"message,omitempty"` |
| 48 | + // Last time the condition was probed |
| 49 | + // +optional |
| 50 | + LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"` |
| 51 | + // Last time the condition transitioned from one status to another. |
| 52 | + // +optional |
| 53 | + LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"` |
| 54 | +} |
| 55 | + |
| 56 | +// Components tracks the resources that compose an operator. |
| 57 | +type Components struct { |
| 58 | + // LabelSelector is a label query over a set of resources used to select the operator's components |
| 59 | + LabelSelector *metav1.LabelSelector `json:"labelSelector"` |
| 60 | + // Refs are a set of references to the operator's component resources, selected with LabelSelector. |
| 61 | + // +optional |
| 62 | + Refs []RichReference `json:"refs,omitempty"` |
| 63 | +} |
| 64 | + |
| 65 | +// RichReference is a reference to a resource, enriched with its status conditions. |
| 66 | +type RichReference struct { |
| 67 | + *corev1.ObjectReference `json:",inline"` |
| 68 | + // Conditions represents the latest state of the component. |
| 69 | + // +optional |
| 70 | + // +patchMergeKey=type |
| 71 | + // +patchStrategy=merge |
| 72 | + Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` |
| 73 | +} |
| 74 | + |
| 75 | +// +kubebuilder:object:root=true |
| 76 | +// +kubebuilder:resource:scope=Cluster |
| 77 | +// +kubebuilder:storageversion |
| 78 | + |
| 79 | +// Operator represents a cluster operator. |
| 80 | +type Operator struct { |
| 81 | + metav1.TypeMeta `json:",inline"` |
| 82 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 83 | + |
| 84 | + Spec OperatorSpec `json:"spec,omitempty"` |
| 85 | + Status OperatorStatus `json:"status,omitempty"` |
| 86 | +} |
| 87 | + |
| 88 | +// +kubebuilder:object:root=true |
| 89 | + |
| 90 | +// OperatorList contains a list of Operators. |
| 91 | +type OperatorList struct { |
| 92 | + metav1.TypeMeta `json:",inline"` |
| 93 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 94 | + Items []Operator `json:"items"` |
| 95 | +} |
| 96 | + |
| 97 | +func init() { |
| 98 | + SchemeBuilder.Register(&Operator{}, &OperatorList{}) |
| 99 | +} |
0 commit comments