|
| 1 | +/* |
| 2 | +Copyright 2022 The Koordinator 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 | + corev1 "k8s.io/api/core/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | +) |
| 23 | + |
| 24 | +// RecommendationTargetType defines the type of analysis target |
| 25 | +type RecommendationTargetType string |
| 26 | + |
| 27 | +const ( |
| 28 | + // RecommendationTargetWorkload defines the k8s workload type |
| 29 | + RecommendationTargetWorkload RecommendationTargetType = "workload" |
| 30 | + // RecommendationPodSelector defines the pod selector type |
| 31 | + RecommendationPodSelector RecommendationTargetType = "podSelector" |
| 32 | +) |
| 33 | + |
| 34 | +// RecommendationTarget defines the target of analysis, which can be a k8s workload or a series of pods |
| 35 | +type RecommendationTarget struct { |
| 36 | + // Type indicates the type of target |
| 37 | + Type RecommendationTargetType `json:"type"` |
| 38 | + // Workload indicates the target is a k8s workload, which is effective when Type is "workload" |
| 39 | + Workload *CrossVersionObjectReference `json:"workload,omitempty"` |
| 40 | + // PodSelector defines the reference of a series of pods, which is effective when Type is "podSelector" |
| 41 | + PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"` |
| 42 | +} |
| 43 | + |
| 44 | +// CrossVersionObjectReference contains enough information to let you identify the referred resource. |
| 45 | +type CrossVersionObjectReference struct { |
| 46 | + // Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds" |
| 47 | + Kind string `json:"kind"` |
| 48 | + // Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names |
| 49 | + Name string `json:"name"` |
| 50 | + // API version of the referent |
| 51 | + APIVersion string `json:"apiVersion,omitempty"` |
| 52 | +} |
| 53 | + |
| 54 | +// RecommendationSpec is the specification of the client object. |
| 55 | +type RecommendationSpec struct { |
| 56 | + // Target is the object to be analyzed, which can be a workload or a series of pods |
| 57 | + Target RecommendationTarget `json:"target"` |
| 58 | + // TODO add more tuning knobs about aggregation policy |
| 59 | +} |
| 60 | + |
| 61 | +// RecommendedPodStatus defines the observed state of pod |
| 62 | +type RecommendedPodStatus struct { |
| 63 | + // ContainerStatuses records the most recently computed amount of resources recommended |
| 64 | + ContainerStatuses []RecommendedContainerStatus `json:"containerStatuses,omitempty"` |
| 65 | +} |
| 66 | + |
| 67 | +// RecommendedContainerStatus defines the observed state of container |
| 68 | +type RecommendedContainerStatus struct { |
| 69 | + // Name of the container. |
| 70 | + ContainerName string `json:"containerName,omitempty"` |
| 71 | + // Recommended resources of container |
| 72 | + Resources corev1.ResourceList `json:"resources,omitempty"` |
| 73 | +} |
| 74 | + |
| 75 | +// RecommendationStatus defines the observed state of Recommendation |
| 76 | +type RecommendationStatus struct { |
| 77 | + // PodStatus records the most recently computed amount of resources recommended |
| 78 | + PodStatus *RecommendedPodStatus `json:"podStatus,omitempty"` |
| 79 | + // UpdateTime is the update time of the distribution |
| 80 | + UpdateTime *metav1.Time `json:"updateTime,omitempty"` |
| 81 | + // Conditions is the list of conditions representing the status of the distribution |
| 82 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 83 | +} |
| 84 | + |
| 85 | +// +genclient |
| 86 | +// +kubebuilder:object:root=true |
| 87 | +// +kubebuilder:subresource:status |
| 88 | +// +kubebuilder:resource:shortName=recom |
| 89 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 90 | +// +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".spec.target.type" |
| 91 | +// +kubebuilder:printcolumn:name="Kind",type="string",JSONPath=".spec.target.workload.kind" |
| 92 | +// +kubebuilder:printcolumn:name="Name",type="string",JSONPath=".spec.target.workload.name" |
| 93 | +// +kubebuilder:printcolumn:name="LastUpdateTime",type="date",JSONPath=".status.updateTime" |
| 94 | + |
| 95 | +// Recommendation is the Schema for the recommendations API |
| 96 | +type Recommendation struct { |
| 97 | + metav1.TypeMeta `json:",inline"` |
| 98 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 99 | + |
| 100 | + Spec RecommendationSpec `json:"spec,omitempty"` |
| 101 | + Status RecommendationStatus `json:"status,omitempty"` |
| 102 | +} |
| 103 | + |
| 104 | +// +kubebuilder:object:root=true |
| 105 | + |
| 106 | +// RecommendationList contains a list of Recommendation |
| 107 | +type RecommendationList struct { |
| 108 | + metav1.TypeMeta `json:",inline"` |
| 109 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 110 | + Items []Recommendation `json:"items"` |
| 111 | +} |
| 112 | + |
| 113 | +func init() { |
| 114 | + SchemeBuilder.Register(&Recommendation{}, &RecommendationList{}) |
| 115 | +} |
0 commit comments