Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(npd): npd definition #84

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ spec:
schema:
openAPIV3Schema:
description: CustomNodeResource captures information about a custom defined
node resource CustomNodeResource objects are non-namespaced.
node resource, mainly focus on static attributes and resources CustomNodeResource
objects are non-namespaced.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: nodeprofiledescriptors.node.katalyst.kubewharf.io
spec:
group: node.katalyst.kubewharf.io
names:
kind: NodeProfileDescriptor
listKind: NodeProfileDescriptorList
plural: nodeprofiledescriptors
shortNames:
- npd
singular: nodeprofiledescriptor
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: NodeProfileDescriptor captures information about node, such as
node-related metrics NodeProfileDescriptor objects are non-namespaced.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec defines the behavior of a NodeProfileDescriptor.
type: object
status:
description: Status represents the current information about a NodeProfileDescriptor.
This data may not be up-to-date.
properties:
nodeMetrics:
description: NodeMetrics contains the node-related metrics
items:
properties:
metrics:
items:
properties:
aggregator:
description: the aggregator of the metric
type: string
metricLabels:
additionalProperties:
type: string
description: a set of labels that identify a single time
series for the metric
type: object
metricName:
description: the name of the metric
type: string
timestamp:
description: indicates the time at which the metrics were
produced
format: date-time
type: string
value:
anyOf:
- type: integer
- type: string
description: the value of the metric
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
window:
description: indicates the window ([Timestamp-Window,
Timestamp]) from which these metrics were calculated,
when returning rate metrics calculated from cumulative
metrics (or zero for non-calculated instantaneous metrics).
type: string
type: object
type: array
scope:
type: string
type: object
type: array
podMetrics:
description: PodMetrics contains the pod-related metrics
items:
properties:
podMetrics:
items:
properties:
metrics:
items:
properties:
aggregator:
description: the aggregator of the metric
type: string
metricLabels:
additionalProperties:
type: string
description: a set of labels that identify a single
time series for the metric
type: object
metricName:
description: the name of the metric
type: string
timestamp:
description: indicates the time at which the metrics
were produced
format: date-time
type: string
value:
anyOf:
- type: integer
- type: string
description: the value of the metric
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
window:
description: indicates the window ([Timestamp-Window,
Timestamp]) from which these metrics were calculated,
when returning rate metrics calculated from cumulative
metrics (or zero for non-calculated instantaneous
metrics).
type: string
type: object
type: array
name:
type: string
namespace:
type: string
type: object
type: array
scope:
type: string
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 3 additions & 0 deletions pkg/apis/node/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha
// ResourceNameKatalystCNR is used to construct standard gvr
const (
ResourceNameKatalystCNR = "customnoderesources"
ResourceNameKatalystNPD = "nodeprofiledescriptor"
)

// Resource takes an unqualified resource and returns a Group qualified GroupResource
Expand All @@ -52,6 +53,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&CustomNodeResource{},
&CustomNodeResourceList{},
&NodeProfileDescriptor{},
&NodeProfileDescriptorList{},
)

v1.AddToGroupVersion(scheme, SchemeGroupVersion)
Expand Down
121 changes: 120 additions & 1 deletion pkg/apis/node/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// +kubebuilder:resource:scope=Cluster,shortName=kcnr
// +kubebuilder:subresource:status

// CustomNodeResource captures information about a custom defined node resource
// CustomNodeResource captures information about a custom defined node resource, mainly focus on static attributes and resources
// CustomNodeResource objects are non-namespaced.
type CustomNodeResource struct {
metav1.TypeMeta `json:",inline"`
Expand Down Expand Up @@ -326,3 +326,122 @@ type NUMAMetricInfo struct {
// Usage contains the real-time resource usage for this NUMA node
Usage *ResourceMetric `json:"usage"`
}

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:scope=Cluster,shortName=npd
// +kubebuilder:subresource:status

// NodeProfileDescriptor captures information about node, such as node-related metrics
// NodeProfileDescriptor objects are non-namespaced.
type NodeProfileDescriptor struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec defines the behavior of a NodeProfileDescriptor.
// +optional
Spec NodeProfileDescriptorSpec `json:"spec,omitempty"`

// Status represents the current information about a NodeProfileDescriptor.
// This data may not be up-to-date.
// +optional
Status NodeProfileDescriptorStatus `json:"status,omitempty"`
}

type NodeProfileDescriptorSpec struct {
}

type NodeProfileDescriptorStatus struct {
// NodeMetrics contains the node-related metrics
// +optional
NodeMetrics []ScopedNodeMetrics `json:"nodeMetrics,omitempty"`

// PodMetrics contains the pod-related metrics
// +optional
PodMetrics []ScopedPodMetrics `json:"podMetrics,omitempty"`
}

type ScopedNodeMetrics struct {
// +optional
Scope string `json:"scope,omitempty"`

// +optional
Metrics []MetricValue `json:"metrics,omitempty"`
}

type ScopedPodMetrics struct {
// +optional
Scope string `json:"scope,omitempty"`

// +optional
PodMetrics []PodMetric `json:"podMetrics,omitempty"`
}

type PodMetric struct {
// +optional
Namespace string `json:"namespace,omitempty"`

// +optional
Name string `json:"name,omitempty"`

// +optional
Metrics []MetricValue `json:"metrics,omitempty"`
}

type Aggregator string

const (
AggregatorAvg Aggregator = "avg"
AggregatorMax Aggregator = "max"
AggregatorMin Aggregator = "min"
AggregatorCount Aggregator = "count"
AggregatorP99 Aggregator = "p99"
AggregatorP95 Aggregator = "p95"
AggregatorP90 Aggregator = "p90"
)

type MetricValue struct {
// the name of the metric
// +optional
MetricName string `json:"metricName,omitempty"`

// a set of labels that identify a single time series for the metric
// +optional
MetricLabels map[string]string `json:"metricLabels,omitempty"`

// indicates the time at which the metrics were produced
// +optional
Timestamp metav1.Time `json:"timestamp,omitempty"`

// the aggregator of the metric
// +optional
Aggregator *Aggregator `json:"aggregator,omitempty"`

// indicates the window ([Timestamp-Window, Timestamp]) from
// which these metrics were calculated, when returning rate
// metrics calculated from cumulative metrics (or zero for
// non-calculated instantaneous metrics).
// +optional
Window *metav1.Duration `json:"window,omitempty"`

// the value of the metric
// +optional
Value resource.Quantity `json:"value,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeProfileDescriptorList is a collection of NodeProfileDescriptor objects.
type NodeProfileDescriptorList struct {
metav1.TypeMeta `json:",inline"`

// Standard list metadata
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ListMeta `json:"metadata,omitempty"`

// items is the list of CNRs
Items []NodeProfileDescriptor `json:"items"`
}
Loading
Loading