Skip to content

Commit

Permalink
store: add verticalpodautoscaler metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
milesbxf committed Jun 17, 2019
1 parent 5d9ecd2 commit ef2e5f4
Show file tree
Hide file tree
Showing 49 changed files with 6,405 additions and 24 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
gopkg.in/inf.v0 v0.9.0 // indirect
k8s.io/api v0.0.0-20190313235455-40a48860b5ab
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1
k8s.io/autoscaler v0.0.0-20190612121530-8bb2354d9af9
k8s.io/client-go v2.0.0-alpha.0.0.20190313235726-6ee68ca5fd83+incompatible
k8s.io/klog v0.3.0
k8s.io/kube-openapi v0.0.0-20190320154901-5e45bb682580 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ k8s.io/api v0.0.0-20190313235455-40a48860b5ab h1:DG9A67baNpoeweOy2spF1OWHhnVY5KR
k8s.io/api v0.0.0-20190313235455-40a48860b5ab/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1 h1:IS7K02iBkQXpCeieSiyJjGoLSdVOv2DbPaWHJ+ZtgKg=
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
k8s.io/autoscaler v0.0.0-20190612121530-8bb2354d9af9 h1:+GB3VH3tw7T8PZw4RPa9XLmYdqTnSB3qa/Zern1bhOk=
k8s.io/autoscaler v0.0.0-20190612121530-8bb2354d9af9/go.mod h1:QEXezc9uKPT91dwqhSJq3GNI3B1HxFRQHiku9kmrsSA=
k8s.io/client-go v2.0.0-alpha.0.0.20190313235726-6ee68ca5fd83+incompatible h1:+SiikveGdttGGsPhWZsGg+RD1ziNvr+PL8zKqLDIrbE=
k8s.io/client-go v2.0.0-alpha.0.0.20190313235726-6ee68ca5fd83+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/klog v0.3.0 h1:0VPpR+sizsiivjIfIAQH/rl8tan6jvWkS7lU+0di3lE=
Expand Down
13 changes: 13 additions & 0 deletions internal/store/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (
extensions "k8s.io/api/extensions/v1beta1"
policy "k8s.io/api/policy/v1beta1"
storagev1 "k8s.io/api/storage/v1"
vpaautoscaling "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/kube-state-metrics/pkg/metric"
metricsstore "k8s.io/kube-state-metrics/pkg/metrics_store"
Expand All @@ -48,6 +50,7 @@ type whiteBlackLister interface {
// (https://en.wikipedia.org/wiki/Builder_pattern).
type Builder struct {
kubeClient clientset.Interface
kubeCfg *rest.Config
namespaces options.NamespaceList
ctx context.Context
enabledResources []string
Expand Down Expand Up @@ -83,6 +86,11 @@ func (b *Builder) WithKubeClient(c clientset.Interface) {
b.kubeClient = c
}

// WithKubeCfg sets the kubeCfg property of a Builder.
func (b *Builder) WithKubeCfg(c *rest.Config) {
b.kubeCfg = c
}

// WithWhiteBlackList configures the white or blacklisted metric to be exposed
// by the store build by the Builder.
func (b *Builder) WithWhiteBlackList(l whiteBlackLister) {
Expand Down Expand Up @@ -136,6 +144,7 @@ var availableStores = map[string]func(f *Builder) *metricsstore.MetricsStore{
"services": func(b *Builder) *metricsstore.MetricsStore { return b.buildServiceStore() },
"statefulsets": func(b *Builder) *metricsstore.MetricsStore { return b.buildStatefulSetStore() },
"storageclasses": func(b *Builder) *metricsstore.MetricsStore { return b.buildStorageClassStore() },
"verticalpodautoscalers": func(b *Builder) *metricsstore.MetricsStore { return b.buildVPAStore() },
}

func (b *Builder) buildConfigMapStore() *metricsstore.MetricsStore {
Expand Down Expand Up @@ -230,6 +239,10 @@ func (b *Builder) buildCsrStore() *metricsstore.MetricsStore {
return b.buildStore(csrMetricFamilies, &certv1beta1.CertificateSigningRequest{}, createCSRListWatch)
}

func (b *Builder) buildVPAStore() *metricsstore.MetricsStore {
return b.buildStore(vpaMetricFamilies, &vpaautoscaling.VerticalPodAutoscaler{}, createVPAListWatchFunc(b.kubeCfg))
}

func (b *Builder) buildStore(
metricFamilies []metric.FamilyGenerator,
expectedType interface{},
Expand Down
Loading

0 comments on commit ef2e5f4

Please sign in to comment.