Skip to content

Commit

Permalink
feat(npd): npd definition
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzhhb committed May 11, 2024
1 parent 0f4045c commit d07b050
Show file tree
Hide file tree
Showing 15 changed files with 908 additions and 2 deletions.
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:
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).
format: int64
type: integer
required:
- aggregator
- metricLabels
- metricName
- timestamp
- value
type: object
type: array
podMetrics:
description: PodMetrics contains the pod-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).
format: int64
type: integer
required:
- aggregator
- metricLabels
- metricName
- timestamp
- value
type: object
type: array
name:
type: string
namespace:
type: string
required:
- metrics
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
95 changes: 94 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,96 @@ 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 []MetricValue `json:"nodeMetrics,omitempty"`

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

type PodMetric struct {
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`

Metrics []MetricValue `json:"metrics"`
}

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
MetricName string `json:"metricName"`

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

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

// the aggregator of the metric
Aggregator *Aggregator `json:"aggregator"`

// 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).
WindowSeconds *int64 `json:"window,omitempty"`

// the value of the metric
Value resource.Quantity `json:"value"`
}

// +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

0 comments on commit d07b050

Please sign in to comment.