Skip to content

Commit

Permalink
Support custom/external metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Aug 24, 2023
1 parent 01c3c6c commit 2291e20
Show file tree
Hide file tree
Showing 63 changed files with 4,763 additions and 13 deletions.
23 changes: 22 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,24 @@ require (
k8s.io/client-go v0.28.0
k8s.io/code-generator v0.28.0
k8s.io/cri-api v0.28.0
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9
k8s.io/kubelet v0.28.0
k8s.io/metrics v0.28.0
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.16.0
sigs.k8s.io/controller-tools v0.13.0
sigs.k8s.io/custom-metrics-apiserver v1.27.0
sigs.k8s.io/kustomize/kustomize/v5 v5.1.1
sigs.k8s.io/yaml v1.3.0
)

require github.com/gorilla/handlers v1.5.1

require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containernetworking/cni v1.1.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
Expand All @@ -51,8 +58,10 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand All @@ -64,6 +73,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
Expand All @@ -89,6 +99,15 @@ require (
github.com/wzshiming/trie v0.1.1 // indirect
github.com/wzshiming/winseq v0.0.0-20200112104235-db357dc107ae // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
Expand All @@ -97,6 +116,7 @@ require (
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.54.0 // indirect
Expand All @@ -106,9 +126,10 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.28.0 // indirect
k8s.io/component-base v0.28.0 // indirect
k8s.io/gengo v0.0.0-20220902162205-c0856e24416d // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.14.0 // indirect
sigs.k8s.io/kustomize/cmd/config v0.11.3 // indirect
Expand Down
389 changes: 389 additions & 0 deletions go.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions kustomize/apiservice/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

commonLabels:
kwok.x-k8s.io/dependency: "apiservice"

resources:
- v1beta1.custom.metrics.k8s.io.yaml
- v1beta2.custom.metrics.k8s.io.yaml
- v1beta1.external.metrics.k8s.io.yaml
15 changes: 15 additions & 0 deletions kustomize/apiservice/v1beta1.custom.metrics.k8s.io.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.custom.metrics.k8s.io
namespace: kube-system
spec:
group: custom.metrics.k8s.io
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: kwok-controller
namespace: kube-system
port: 10247
version: v1beta1
versionPriority: 100
15 changes: 15 additions & 0 deletions kustomize/apiservice/v1beta1.external.metrics.k8s.io.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.external.metrics.k8s.io
namespace: kube-system
spec:
group: external.metrics.k8s.io
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: kwok-controller
namespace: kube-system
port: 10247
version: v1beta1
versionPriority: 100
15 changes: 15 additions & 0 deletions kustomize/apiservice/v1beta2.custom.metrics.k8s.io.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta2.custom.metrics.k8s.io
namespace: kube-system
spec:
group: custom.metrics.k8s.io
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: kwok-controller
namespace: kube-system
port: 10247
version: v1beta2
versionPriority: 100
151 changes: 151 additions & 0 deletions kustomize/crd/bases/kwok.x-k8s.io_custommetrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.1
name: custommetrics.kwok.x-k8s.io
spec:
group: kwok.x-k8s.io
names:
kind: CustomMetric
listKind: CustomMetricList
plural: custommetrics
singular: custommetric
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: CustomMetric provides resource usage for a single pod.
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 holds spec for resource usage.
properties:
metrics:
description: Metrics is a list of custom metric.
items:
description: CustomMetricItem holds spec for custom metric item.
properties:
name:
description: Name is the name for custom metric.
type: string
value:
anyOf:
- type: integer
- type: string
description: Value is the value for custom metric.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
required:
- name
type: object
type: array
resourceRef:
description: ResourceRef specifies the Kind and version of the resource.
properties:
apiGroup:
default: v1
description: APIGroup of the referent.
type: string
kind:
description: Kind of the referent.
type: string
required:
- kind
type: object
selector:
description: Selector is a selector to filter pods to configure.
properties:
matchNames:
description: MatchNames is a list of names to match. if not set,
all names will be matched.
items:
type: string
type: array
matchNamespaces:
description: MatchNamespaces is a list of namespaces to match.
if not set, all namespaces will be matched.
items:
type: string
type: array
type: object
required:
- resourceRef
type: object
status:
description: Status holds status for resource usage
properties:
conditions:
description: Conditions holds conditions for custom metric.
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
properties:
lastTransitionTime:
description: LastTransitionTime is the last time the condition
transitioned from one status to another. This should be when
the underlying condition changed. If that is not known, then
using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: Message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
reason:
description: Reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values and
meanings for this field, and whether the values are considered
a guaranteed API. The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: Status of the condition
type: string
type:
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
type: object
required:
- metadata
- spec
type: object
served: true
storage: true
subresources:
status: {}
Loading

0 comments on commit 2291e20

Please sign in to comment.