Skip to content

Commit

Permalink
Merge branch 'master' into affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
jiamin13579 committed Mar 21, 2023
2 parents 1cf8fbd + 9c7f3ef commit 962dff8
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 28 deletions.
2 changes: 2 additions & 0 deletions docs/design/usage-based-scheduling.md
Expand Up @@ -60,6 +60,8 @@ metrics: # metrics server related configuration
type: prometheus # Optional, The metrics source type, prometheus by default, support prometheus and elasticsearch
address: http://192.168.0.10:9090 # mandatory, The metrics source address
interval: 30s # Optional, The scheduler pull metrics from Prometheus with this interval, 5s by default
tls: # Optional, The tls configuration
insecureSkipVerify: "false" # Optional, Skip the certificate verification, false by default
elasticsearch: # Optional, The elasticsearch configuration
index: "custom-index-name" # Optional, The elasticsearch index name, "metricbeat-*" by default
username: "" # Optional, The elasticsearch username
Expand Down
9 changes: 6 additions & 3 deletions hack/generate-yaml.sh
Expand Up @@ -62,16 +62,19 @@ esac
ARCH=$(go env GOARCH)

# Step1. install helm binary
if [[ ! -f "${HELM_BIN_DIR}/version.helm.${HELM_VER}" ]] ; then
if [[ ! -f "${HELM_BIN_DIR}/version.helm.${HELM_VER}" ]] || [[ ! -f "${HELM_BIN_DIR}/helm" ]] ; then
TD=$(mktemp -d)
cd "${TD}" && \
curl -Lo "${TD}/helm.tgz" "https://get.helm.sh/helm-${HELM_VER}-${LOCAL_OS}-${ARCH}.tar.gz" && \
tar xfz helm.tgz && \
mv ${LOCAL_OS}-${ARCH}/helm "${HELM_BIN_DIR}/helm-${HELM_VER}" && \
cp "${HELM_BIN_DIR}/helm-${HELM_VER}" "${HELM_BIN_DIR}/helm" && \
chmod +x ${HELM_BIN_DIR}/helm
rm -rf "${TD}" && \
touch "${HELM_BIN_DIR}/version.helm.${HELM_VER}"
rm -rf "${TD}"

if [[ ! -f "${HELM_BIN_DIR}/version.helm.${HELM_VER}" ]] ; then
touch "${HELM_BIN_DIR}/version.helm.${HELM_VER}"
fi
fi

# Step2. update helm templates from config dir
Expand Down
4 changes: 2 additions & 2 deletions installer/helm/chart/volcano/templates/admission.yaml
Expand Up @@ -97,7 +97,7 @@ spec:
- -v=4
- 2>&1
image: {{.Values.basic.admission_image_name}}:{{.Values.basic.image_tag_version}}
imagePullPolicy: IfNotPresent
imagePullPolicy: {{ .Values.basic.image_pull_policy }}
name: admission
volumeMounts:
- mountPath: /admission.local.config/certificates
Expand Down Expand Up @@ -153,7 +153,7 @@ spec:
containers:
- name: main
image: {{.Values.basic.admission_image_name}}:{{.Values.basic.image_tag_version}}
imagePullPolicy: IfNotPresent
imagePullPolicy: {{ .Values.basic.image_pull_policy }}
command: ["./gen-admission-secret.sh", "--service", "{{ .Release.Name }}-admission-service", "--namespace",
"{{ .Release.Namespace }}", "--secret", "{{.Values.basic.admission_secret_name}}"]
{{- end }}
4 changes: 2 additions & 2 deletions installer/helm/chart/volcano/templates/controllers.yaml
Expand Up @@ -108,5 +108,5 @@ spec:
- --enable-healthz=true
- -v=4
- 2>&1
imagePullPolicy: "IfNotPresent"
{{- end }}
imagePullPolicy: {{ .Values.basic.image_pull_policy }}
{{- end }}
14 changes: 7 additions & 7 deletions installer/helm/chart/volcano/templates/kubestatemetrics.yaml
Expand Up @@ -12,7 +12,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: kube-state-metrics
namespace: {{ .Release.Namespace }}
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -135,16 +135,16 @@ metadata:
apiVersion: apps/v1
kind: Deployment
metadata:
name: kube-state-metrics
name: kube-state-metrics
namespace: {{ .Release.Namespace }}
labels:
k8s-app: kube-state-metrics
k8s-app: kube-state-metrics
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
k8s-app: kube-state-metrics
k8s-app: kube-state-metrics
strategy:
rollingUpdate:
maxSurge: 25%
Expand All @@ -153,12 +153,12 @@ spec:
template:
metadata:
labels:
k8s-app: kube-state-metrics
k8s-app: kube-state-metrics
spec:
containers:
- image: quay.io/coreos/kube-state-metrics:v1.9.7
imagePullPolicy: IfNotPresent
name: kube-state-metrics
imagePullPolicy: {{ .Values.basic.image_pull_policy }}
name: kube-state-metrics
ports:
- name: http-metrics
containerPort: 8080
Expand Down
2 changes: 1 addition & 1 deletion installer/helm/chart/volcano/templates/scheduler.yaml
Expand Up @@ -127,7 +127,7 @@ spec:
- --enable-metrics=true
- -v=3
- 2>&1
imagePullPolicy: "IfNotPresent"
imagePullPolicy: {{ .Values.basic.image_pull_policy }}
volumeMounts:
- name: scheduler-config
mountPath: /volcano.scheduler
Expand Down
3 changes: 2 additions & 1 deletion installer/helm/chart/volcano/values.yaml
@@ -1,12 +1,13 @@
basic:
image_tag_version: "latest"
controller_image_name: "volcanosh/vc-controller-manager"
scheduler_image_name: "volcanosh/vc-scheduler"
admission_image_name: "volcanosh/vc-webhook-manager"
admission_secret_name: "volcano-admission-secret"
admission_config_file: "config/volcano-admission.conf"
scheduler_config_file: "config/volcano-scheduler.conf"
image_pull_secret: ""
image_pull_policy: "IfNotPresent"
image_tag_version: "latest"
admission_port: 8443
custom:
metrics_enable: false
Expand Down
4 changes: 2 additions & 2 deletions installer/volcano-development.yaml
Expand Up @@ -8616,7 +8616,7 @@ spec:
- --enable-healthz=true
- -v=4
- 2>&1
imagePullPolicy: "IfNotPresent"
imagePullPolicy: IfNotPresent
---
# Source: volcano/templates/scheduler.yaml
apiVersion: v1
Expand Down Expand Up @@ -8779,7 +8779,7 @@ spec:
- --enable-metrics=true
- -v=3
- 2>&1
imagePullPolicy: "IfNotPresent"
imagePullPolicy: IfNotPresent
volumeMounts:
- name: scheduler-config
mountPath: /volcano.scheduler
Expand Down
10 changes: 5 additions & 5 deletions installer/volcano-monitoring-latest.yaml
Expand Up @@ -411,16 +411,16 @@ spec:
apiVersion: apps/v1
kind: Deployment
metadata:
name: kube-state-metrics
name: kube-state-metrics
namespace: volcano-monitoring
labels:
k8s-app: kube-state-metrics
k8s-app: kube-state-metrics
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
k8s-app: kube-state-metrics
k8s-app: kube-state-metrics
strategy:
rollingUpdate:
maxSurge: 25%
Expand All @@ -429,12 +429,12 @@ spec:
template:
metadata:
labels:
k8s-app: kube-state-metrics
k8s-app: kube-state-metrics
spec:
containers:
- image: quay.io/coreos/kube-state-metrics:v1.9.7
imagePullPolicy: IfNotPresent
name: kube-state-metrics
name: kube-state-metrics
ports:
- name: http-metrics
containerPort: 8080
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/metrics/source/metrics_client.go
Expand Up @@ -39,5 +39,5 @@ func NewMetricsClient(metricsConf map[string]string) (MetricsClient, error) {
if metricsType == "elasticsearch" {
return NewElasticsearchMetricsClient(address, metricsConf)
}
return &PrometheusMetricsClient{address: address}, nil
return NewPrometheusMetricsClient(address, metricsConf)
}
8 changes: 8 additions & 0 deletions pkg/scheduler/metrics/source/metrics_client_elasticsearch.go
Expand Up @@ -19,8 +19,10 @@ package source
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"github.com/elastic/go-elasticsearch/v7"
"net/http"
)

const (
Expand All @@ -47,10 +49,16 @@ func NewElasticsearchMetricsClient(address string, conf map[string]string) (*Ela
e.indexName = indexName
}
var err error
insecureSkipVerify := conf["tls.insecureSkipVerify"] == "true"
e.es, err = elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{address},
Username: conf["elasticsearch.username"],
Password: conf["elasticsearch.password"],
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: insecureSkipVerify,
},
},
})
if err != nil {
return nil, err
Expand Down
20 changes: 16 additions & 4 deletions pkg/scheduler/metrics/source/metrics_client_prometheus.go
Expand Up @@ -18,11 +18,13 @@ package source

import (
"context"
"crypto/tls"
"fmt"
"github.com/prometheus/client_golang/api"
prometheusv1 "github.com/prometheus/client_golang/api/prometheus/v1"
pmodel "github.com/prometheus/common/model"
"k8s.io/klog/v2"
"net/http"
"strconv"
"strings"
"time"
Expand All @@ -37,16 +39,26 @@ const (

type PrometheusMetricsClient struct {
address string
conf map[string]string
}

func NewPrometheusMetricsClient(address string) (*PrometheusMetricsClient, error) {
return &PrometheusMetricsClient{address: address}, nil
func NewPrometheusMetricsClient(address string, conf map[string]string) (*PrometheusMetricsClient, error) {
return &PrometheusMetricsClient{address: address, conf: conf}, nil
}

func (p *PrometheusMetricsClient) NodeMetricsAvg(ctx context.Context, nodeName string, period string) (*NodeMetrics, error) {
klog.V(4).Infof("Get node metrics from Prometheus: %s", p.address)
client, err := api.NewClient(api.Config{
Address: p.address,
var client api.Client
var err error
insecureSkipVerify := p.conf["tls.insecureSkipVerify"] == "true"
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: insecureSkipVerify,
},
}
client, err = api.NewClient(api.Config{
Address: p.address,
RoundTripper: tr,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 962dff8

Please sign in to comment.