Skip to content

Commit

Permalink
apis: add Recommendation crd
Browse files Browse the repository at this point in the history
Signed-off-by: 佑祎 <zzw261520@alibaba-inc.com>
  • Loading branch information
zwzhang0107 committed Mar 4, 2024
1 parent 07e51fa commit 80ab2b3
Show file tree
Hide file tree
Showing 29 changed files with 1,517 additions and 31 deletions.
14 changes: 1 addition & 13 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,7 @@ aliases:
- FillZpp
- eahydra

yarn-approvers:
prediction-approvers:
- zwzhang0107
- saintube

yarn-controller-approvers:
- zwzhang0107
- saintube
- FillZpp
- songzh215

yarn-copilot-approvers:
- zwzhang0107
- saintube
- FillZpp
- songzh215

32 changes: 32 additions & 0 deletions apis/analysis/v1alpha1/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

const (
// LowConfidenceCondition indicates the low confidence for the current forecasting result.
LowConfidenceCondition string = "LowConfidence"
// NoObjectsMatchedCondition indicates that the current description didn't match any objects.
NoObjectsMatchedCondition string = "NoObjectsMatched"
// FetchingHistoryCondition indicates that forecaster is in the process of loading additional
// history samples.
FetchingHistoryCondition string = "FetchingHistory"
// ConfigDeprecatedCondition indicates that this configuration is deprecated and will stop being
// supported soon.
ConfigDeprecatedCondition string = "ConfigDeprecated"
// ConfigUnsupportedCondition indicates that this configuration is unsupported and will not be provided for it.
ConfigUnsupportedCondition string = "ConfigUnsupported"
)
43 changes: 43 additions & 0 deletions apis/analysis/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the analysis v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=analysis.koordinator.sh
package v1alpha1

import (
"github.com/koordinator-sh/koordinator/apis/scheme"
"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "analysis.koordinator.sh", Version: "v1alpha1"}

SchemeGroupVersion = GroupVersion

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
109 changes: 109 additions & 0 deletions apis/analysis/v1alpha1/recommendation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// RecommendationTargetType defines the type of analysis target
type RecommendationTargetType string

const (
// RecommendationTargetWorkload defines the k8s workload type
RecommendationTargetWorkload RecommendationTargetType = "workload"
// RecommendationPodSelector defines the pod selector type
RecommendationPodSelector RecommendationTargetType = "podSelector"
)

// RecommendationTarget defines the target of analysis, which can be a k8s workload or a series of pods
type RecommendationTarget struct {
// Type indicates the type of target
Type RecommendationTargetType `json:"type"`
// Workload indicates the target is a k8s workload, which is effective when Type is "workload"
Workload *CrossVersionObjectReference `json:"workload,omitempty"`
// PodSelector defines the reference of a series of pods, which is effective when Type is "podSelector"
PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"`
}

// CrossVersionObjectReference contains enough information to let you identify the referred resource.
type CrossVersionObjectReference struct {
// Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"
Kind string `json:"kind"`
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
Name string `json:"name"`
// API version of the referent
APIVersion string `json:"apiVersion,omitempty"`
}

// RecommendationSpec is the specification of the client object.
type RecommendationSpec struct {
// Target is the object to be analyzed, which can be a workload or a series of pods
Target RecommendationTarget `json:"target"`
}

// RecommendedPodStatus defines the observed state of pod
type RecommendedPodStatus struct {
// ContainerStatuses records the most recently computed amount of resources recommended
ContainerStatuses []RecommendedContainerStatus `json:"containerStatuses,omitempty"`
}

// RecommendedContainerStatus defines the observed state of container
type RecommendedContainerStatus struct {
// Name of the container.
ContainerName string `json:"containerName,omitempty"`
// Recommended resources of container
Resources corev1.ResourceList `json:"resources,omitempty"`
}

// RecommendationStatus defines the observed state of Recommendation
type RecommendationStatus struct {
// PodStatus records the most recently computed amount of resources recommended
PodStatus RecommendedPodStatus `json:"podStatus,omitempty"`
// UpdateTime is the update time of the distribution
UpdateTime *metav1.Time `json:"updateTime,omitempty"`
// Conditions is the list of conditions representing the status of the distribution
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=recom

// Recommendation is the Schema for the recommendations API
type Recommendation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec RecommendationSpec `json:"spec,omitempty"`
Status RecommendationStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// RecommendationList contains a list of Recommendation
type RecommendationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Recommendation `json:"items"`
}

func init() {
SchemeBuilder.Register(&Recommendation{}, &RecommendationList{})
}
Loading

0 comments on commit 80ab2b3

Please sign in to comment.