Unverified Commit a3f4a11b authored by Jason Liu's avatar Jason Liu Committed by GitHub
Browse files

:sparkles: Add NodeMetric API (#1)


* Setup NodeMetric API
Signed-off-by: default avatarJason Liu <jasonliu747@gmail.com>

* implement Watches for SetupWithManager
Signed-off-by: default avatarJason Liu <jasonliu747@gmail.com>

* add test for nodemetric controller
Signed-off-by: default avatarJason Liu <jasonliu747@gmail.com>
parent ac0d7894
main dependabot/go_modules/github.com/docker/docker-20.10.16incompatible dependabot/go_modules/github.com/docker/docker-20.10.17incompatible dependabot/go_modules/github.com/docker/docker-20.10.18incompatible dependabot/go_modules/github.com/docker/docker-20.10.19incompatible dependabot/go_modules/github.com/docker/docker-20.10.20incompatible dependabot/go_modules/github.com/docker/docker-20.10.21incompatible dependabot/go_modules/github.com/evanphx/json-patch-5.6.0incompatible dependabot/go_modules/github.com/fsnotify/fsnotify-1.5.4 dependabot/go_modules/github.com/go-logr/logr-1.2.3 dependabot/go_modules/github.com/google/go-cmp-0.5.9 dependabot/go_modules/github.com/google/uuid-1.3.0 dependabot/go_modules/github.com/jedib0t/go-pretty/v6-6.4.0 dependabot/go_modules/github.com/openkruise/kruise-1.3.0 dependabot/go_modules/github.com/openkruise/kruise-api-1.3.0 dependabot/go_modules/github.com/prometheus/client_golang-1.12.2 dependabot/go_modules/github.com/prometheus/client_golang-1.13.0 dependabot/go_modules/github.com/spf13/cobra-1.4.0 dependabot/go_modules/github.com/spf13/cobra-1.5.0 dependabot/go_modules/github.com/spf13/cobra-1.6.1 dependabot/go_modules/github.com/stretchr/testify-1.7.4 dependabot/go_modules/github.com/stretchr/testify-1.8.0 dependabot/go_modules/github.com/stretchr/testify-1.8.1 dependabot/go_modules/go.uber.org/atomic-1.10.0 dependabot/go_modules/google.golang.org/grpc-1.47.0 dependabot/go_modules/google.golang.org/grpc-1.48.0 dependabot/go_modules/google.golang.org/grpc-1.49.0 dependabot/go_modules/google.golang.org/grpc-1.50.0 dependabot/go_modules/google.golang.org/grpc-1.50.1 dependabot/go_modules/google.golang.org/grpc-1.51.0 dependabot/go_modules/google.golang.org/protobuf-1.28.0 dependabot/go_modules/google.golang.org/protobuf-1.28.1 dependabot/go_modules/gorm.io/driver/sqlite-1.3.4 dependabot/go_modules/gorm.io/driver/sqlite-1.3.5 dependabot/go_modules/gorm.io/driver/sqlite-1.3.6 dependabot/go_modules/gorm.io/gorm-1.23.10 dependabot/go_modules/gorm.io/gorm-1.23.5 dependabot/go_modules/gorm.io/gorm-1.23.6 dependabot/go_modules/gorm.io/gorm-1.23.7 dependabot/go_modules/gorm.io/gorm-1.23.8 dependabot/go_modules/gorm.io/gorm-1.23.9 dependabot/go_modules/gorm.io/gorm-1.24.0 dependabot/go_modules/gorm.io/gorm-1.24.1 dependabot/go_modules/gorm.io/gorm-1.24.2 dependabot/go_modules/k8s.io/klog/v2-2.70.0 dependabot/go_modules/k8s.io/klog/v2-2.80.0 dependabot/go_modules/k8s.io/klog/v2-2.80.1 dependabot/go_modules/sigs.k8s.io/controller-runtime-0.12.1 dependabot/go_modules/sigs.k8s.io/controller-runtime-0.13.0 dependabot/go_modules/sigs.k8s.io/yaml-1.3.0 feat/qos-manager hormes-patch-1 release-0.1 release-0.2 release-0.3 release-0.4 release-0.5 release-0.6 release-0.7 release-1.0 revert-656-update-device-crd v1.0.0 v0.7.0 v0.6.2 v0.6.1 v0.6.0 v0.5.0 v0.4.1 v0.4.0 v0.3.1 v0.3.0 v0.2.0 v0.1.0
No related merge requests found
Showing with 770 additions and 306 deletions
+770 -306
......@@ -4,4 +4,14 @@ layout:
multigroup: true
projectName: koordinator
repo: github.com/koordinator-sh/koordinator
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: koordinator.sh
group: slo
kind: NodeMetric
path: github.com/koordinator-sh/koordinator/apis/slo/v1alpha1
version: v1alpha1
version: "3"
/*
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 slo v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=slo.koordinator.sh
package v1alpha1
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)
var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "slo.koordinator.sh", Version: "v1alpha1"}
// 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
)
/*
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"
)
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
type NodeMetricInfo struct {
NodeUsage ResourceMap `json:"nodeUsage,omitempty"`
}
type PodMetricInfo struct {
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
PodUsage ResourceMap `json:"podUsage,omitempty"`
}
type ResourceMap struct {
corev1.ResourceList `json:"resources,omitempty"`
}
// NodeMetricSpec defines the desired state of NodeMetric
type NodeMetricSpec struct{}
// NodeMetricStatus defines the observed state of NodeMetric
type NodeMetricStatus struct {
// UpdateTime is the last time this NodeMetric was updated.
UpdateTime *metav1.Time `json:"updateTime,omitempty"`
// NodeMetric contains the metrics for this node.
NodeMetric *NodeMetricInfo `json:"nodeMetric,omitempty"`
// PodsMetric contains the metrics for pods belong to this node.
PodsMetric []*PodMetricInfo `json:"podsMetric,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// NodeMetric is the Schema for the nodemetrics API
type NodeMetric struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec NodeMetricSpec `json:"spec,omitempty"`
Status NodeMetricStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// NodeMetricList contains a list of NodeMetric
type NodeMetricList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NodeMetric `json:"items"`
}
func init() {
SchemeBuilder.Register(&NodeMetric{}, &NodeMetricList{})
}
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*
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.
*/
// Code generated by controller-gen. DO NOT EDIT.
package v1alpha1
import (
"k8s.io/api/core/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NodeMetric) DeepCopyInto(out *NodeMetric) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
in.Status.DeepCopyInto(&out.Status)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetric.
func (in *NodeMetric) DeepCopy() *NodeMetric {
if in == nil {
return nil
}
out := new(NodeMetric)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *NodeMetric) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NodeMetricInfo) DeepCopyInto(out *NodeMetricInfo) {
*out = *in
in.NodeUsage.DeepCopyInto(&out.NodeUsage)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricInfo.
func (in *NodeMetricInfo) DeepCopy() *NodeMetricInfo {
if in == nil {
return nil
}
out := new(NodeMetricInfo)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NodeMetricList) DeepCopyInto(out *NodeMetricList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]NodeMetric, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricList.
func (in *NodeMetricList) DeepCopy() *NodeMetricList {
if in == nil {
return nil
}
out := new(NodeMetricList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *NodeMetricList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NodeMetricSpec) DeepCopyInto(out *NodeMetricSpec) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricSpec.
func (in *NodeMetricSpec) DeepCopy() *NodeMetricSpec {
if in == nil {
return nil
}
out := new(NodeMetricSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NodeMetricStatus) DeepCopyInto(out *NodeMetricStatus) {
*out = *in
if in.UpdateTime != nil {
in, out := &in.UpdateTime, &out.UpdateTime
*out = (*in).DeepCopy()
}
if in.NodeMetric != nil {
in, out := &in.NodeMetric, &out.NodeMetric
*out = new(NodeMetricInfo)
(*in).DeepCopyInto(*out)
}
if in.PodsMetric != nil {
in, out := &in.PodsMetric, &out.PodsMetric
*out = make([]*PodMetricInfo, len(*in))
for i := range *in {
if (*in)[i] != nil {
in, out := &(*in)[i], &(*out)[i]
*out = new(PodMetricInfo)
(*in).DeepCopyInto(*out)
}
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricStatus.
func (in *NodeMetricStatus) DeepCopy() *NodeMetricStatus {
if in == nil {
return nil
}
out := new(NodeMetricStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PodMetricInfo) DeepCopyInto(out *PodMetricInfo) {
*out = *in
in.PodUsage.DeepCopyInto(&out.PodUsage)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetricInfo.
func (in *PodMetricInfo) DeepCopy() *PodMetricInfo {
if in == nil {
return nil
}
out := new(PodMetricInfo)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ResourceMap) DeepCopyInto(out *ResourceMap) {
*out = *in
if in.ResourceList != nil {
in, out := &in.ResourceList, &out.ResourceList
*out = make(v1.ResourceList, len(*in))
for key, val := range *in {
(*out)[key] = val.DeepCopy()
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceMap.
func (in *ResourceMap) DeepCopy() *ResourceMap {
if in == nil {
return nil
}
out := new(ResourceMap)
in.DeepCopyInto(out)
return out
}
......@@ -14,6 +14,30 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package slo_agent
package main
// TODO
import (
"flag"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"github.com/koordinator-sh/koordinator/cmd/slo-agent/options"
)
func main() {
klog.InitFlags(flag.CommandLine)
flag.Parse()
// Default klog flush interval is 5 seconds, set to LogFlushFreq.
go wait.Until(klog.Flush, *options.LogFlushFreq, wait.NeverStop)
defer klog.Flush()
go func() {
klog.Info("starting prometheus server on %v", *options.PromAddr)
http.Handle("/metrics", promhttp.Handler())
klog.Fatalf("failed to start prometheus, error: %v", http.ListenAndServe(*options.PromAddr, nil))
}()
}
/*
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 options
import (
"flag"
"time"
)
var (
PromAddr = flag.String("prom-addr", ":9316", "Port of prometheus server")
LogFlushFreq = flag.Duration("log-flush-freq", 5*time.Second, "Maximum duration between log flushes")
)
......@@ -14,6 +14,91 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package slo_controller
package main
// TODO
import (
"flag"
"os"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
"github.com/koordinator-sh/koordinator/pkg/slo-controller/nodemetric"
// +kubebuilder:scaffold:imports
)
var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(slov1alpha1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}
func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "d441524d.koordinator.sh",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}
if err = (&nodemetric.NodeMetricReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "NodeMetric")
os.Exit(1)
}
// +kubebuilder:scaffold:builder
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: nodemetrics.slo.koordinator.sh
spec:
group: slo.koordinator.sh
names:
kind: NodeMetric
listKind: NodeMetricList
plural: nodemetrics
singular: nodemetric
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: NodeMetric is the Schema for the nodemetrics API
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: NodeMetricSpec defines the desired state of NodeMetric
type: object
status:
description: NodeMetricStatus defines the observed state of NodeMetric
properties:
nodeMetric:
description: NodeMetric contains the metrics for this node.
properties:
nodeUsage:
properties:
resources:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: ResourceList is a set of (resource name, quantity)
pairs.
type: object
type: object
type: object
podsMetric:
description: PodsMetric contains the metrics for pods belong to this
node.
items:
properties:
name:
type: string
namespace:
type: string
podUsage:
properties:
resources:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: ResourceList is a set of (resource name, quantity)
pairs.
type: object
type: object
type: object
type: array
updateTime:
description: UpdateTime is the last time this NodeMetric was updated.
format: date-time
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/slo.koordinator.sh_nodemetrics.yaml
#+kubebuilder:scaffold:crdkustomizeresource
patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_nodemetrics.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_nodemetrics.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name
namespace:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/namespace
create: false
varReference:
- path: metadata/annotations
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: nodemetrics.slo.koordinator.sh
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: nodemetrics.slo.koordinator.sh
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
# permissions for end users to edit nodemetrics.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: nodemetric-editor-role
rules:
- apiGroups:
- slo.koordinator.sh
resources:
- nodemetrics
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- slo.koordinator.sh
resources:
- nodemetrics/status
verbs:
- get
# permissions for end users to view nodemetrics.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: nodemetric-viewer-role
rules:
- apiGroups:
- slo.koordinator.sh
resources:
- nodemetrics
verbs:
- get
- list
- watch
- apiGroups:
- slo.koordinator.sh
resources:
- nodemetrics/status
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- slo.koordinator.sh
resources:
- nodemetrics
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- slo.koordinator.sh
resources:
- nodemetrics/finalizers
verbs:
- update
- apiGroups:
- slo.koordinator.sh
resources:
- nodemetrics/status
verbs:
- get
- patch
- update
apiVersion: slo.koordinator.sh/v1alpha1
kind: NodeMetric
metadata:
name: nodemetric-sample
spec:
# TODO(user): Add fields here
......@@ -3,14 +3,19 @@ module github.com/koordinator-sh/koordinator
go 1.17
require (
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.15.0
github.com/prometheus/client_golang v1.11.0
k8s.io/api v0.22.6
k8s.io/apimachinery v0.22.6
k8s.io/client-go v0.22.6
k8s.io/code-generator v0.22.6
k8s.io/klog/v2 v2.9.0
sigs.k8s.io/controller-runtime v0.10.2
)
require (
cloud.google.com/go v0.81.0 // indirect
cloud.google.com/go v0.54.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
......@@ -23,11 +28,11 @@ require (
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-logr/zapr v0.4.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
......@@ -40,51 +45,44 @@ require (
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
go.uber.org/zap v1.19.0 // indirect
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/tools v0.1.2 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.23.0 // indirect
k8s.io/apiextensions-apiserver v0.23.0 // indirect
k8s.io/component-base v0.23.0 // indirect
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
k8s.io/apiextensions-apiserver v0.22.2 // indirect
k8s.io/component-base v0.22.6 // indirect
k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 // indirect
k8s.io/kube-openapi v0.0.0-20211109043538-20434351676c // indirect
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
replace (
github.com/go-logr/logr => github.com/go-logr/logr v0.4.0
github.com/go-logr/zapr => github.com/go-logr/zapr v0.4.0
k8s.io/klog/v2 => k8s.io/klog/v2 v2.9.0
sigs.k8s.io/yaml v1.2.0 // indirect
)
replace (
......
This diff is collapsed.
/*
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 main
import (
"flag"
"os"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
//+kubebuilder:scaffold:imports
)
var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}
func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "d441524d.koordinator.sh",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}
package common
const (
ConfigNameSpace = "kube-system"
SLOConfigMapName = "slo-manager-config"
ColocationConfigKey = "colocation-config"
)
const (
DomainPrefix = "koordinator.sh"
LabelAnnotationPrefix = DomainPrefix + "/"
LabelPodQoS = LabelAnnotationPrefix + "qosClass"
LabelPodPriority = LabelAnnotationPrefix + "priority"
BatchCPU = LabelAnnotationPrefix + "batch-cpu"
BatchMemory = LabelAnnotationPrefix + "batch-memory"
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment