metrics and specs clients package refactoring
This commit is contained in:
parent
925791696c
commit
48c1eaa476
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package signals
|
package history
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package signals
|
package history
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package signals
|
package history
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package signals
|
package history
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package signals
|
package history
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package signals
|
package history
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package signals
|
package history
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cluster
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cluster
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cluster
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cluster
|
package spec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cluster
|
package spec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cluster
|
package spec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
kube_flag "k8s.io/apiserver/pkg/util/flag"
|
kube_flag "k8s.io/apiserver/pkg/util/flag"
|
||||||
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/signals"
|
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/input/history"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
kube_restclient "k8s.io/client-go/rest"
|
kube_restclient "k8s.io/client-go/rest"
|
||||||
)
|
)
|
||||||
|
|
@ -37,7 +37,7 @@ func main() {
|
||||||
glog.Infof("Running VPA Recommender")
|
glog.Infof("Running VPA Recommender")
|
||||||
|
|
||||||
config := createKubeConfig()
|
config := createKubeConfig()
|
||||||
recommender := NewRecommender(config, *metricsFetcherInterval, signals.NewPrometheusHistoryProvider(*prometheusAddress))
|
recommender := NewRecommender(config, *metricsFetcherInterval, history.NewPrometheusHistoryProvider(*prometheusAddress))
|
||||||
recommender.Run()
|
recommender.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,11 @@ import (
|
||||||
vpa_api "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned/typed/poc.autoscaling.k8s.io/v1alpha1"
|
vpa_api "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned/typed/poc.autoscaling.k8s.io/v1alpha1"
|
||||||
vpa_lister "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/listers/poc.autoscaling.k8s.io/v1alpha1"
|
vpa_lister "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/listers/poc.autoscaling.k8s.io/v1alpha1"
|
||||||
vpa_api_util "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/vpa"
|
vpa_api_util "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/vpa"
|
||||||
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/cluster"
|
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/input/history"
|
||||||
|
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/input/metrics"
|
||||||
|
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/input/spec"
|
||||||
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/logic"
|
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/logic"
|
||||||
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/model"
|
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/model"
|
||||||
"k8s.io/autoscaler/vertical-pod-autoscaler/recommender/signals"
|
|
||||||
kube_client "k8s.io/client-go/kubernetes"
|
kube_client "k8s.io/client-go/kubernetes"
|
||||||
v1lister "k8s.io/client-go/listers/core/v1"
|
v1lister "k8s.io/client-go/listers/core/v1"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
|
|
@ -47,10 +48,10 @@ type Recommender interface {
|
||||||
|
|
||||||
type recommender struct {
|
type recommender struct {
|
||||||
clusterState *model.ClusterState
|
clusterState *model.ClusterState
|
||||||
specClient cluster.SpecClient
|
specClient spec.SpecClient
|
||||||
metricsClient cluster.MetricsClient
|
metricsClient metrics.MetricsClient
|
||||||
metricsFetchingInterval time.Duration
|
metricsFetchingInterval time.Duration
|
||||||
historyProvider signals.HistoryProvider
|
historyProvider history.HistoryProvider
|
||||||
vpaClient vpa_api.VerticalPodAutoscalersGetter
|
vpaClient vpa_api.VerticalPodAutoscalersGetter
|
||||||
vpaLister vpa_lister.VerticalPodAutoscalerLister
|
vpaLister vpa_lister.VerticalPodAutoscalerLister
|
||||||
podResourceRecommender logic.PodResourceRecommender
|
podResourceRecommender logic.PodResourceRecommender
|
||||||
|
|
@ -130,7 +131,7 @@ func (r *recommender) loadPods() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Cannot get SimplePodSpecs. Reason: %+v", err)
|
glog.Errorf("Cannot get SimplePodSpecs. Reason: %+v", err)
|
||||||
}
|
}
|
||||||
pods := make(map[model.PodID]*cluster.BasicPodSpec)
|
pods := make(map[model.PodID]*spec.BasicPodSpec)
|
||||||
for n, spec := range podSpecs {
|
for n, spec := range podSpecs {
|
||||||
glog.V(3).Infof("SimplePodSpec #%v: %+v", n, spec)
|
glog.V(3).Infof("SimplePodSpec #%v: %+v", n, spec)
|
||||||
pods[spec.ID] = spec
|
pods[spec.ID] = spec
|
||||||
|
|
@ -165,7 +166,7 @@ func (r *recommender) loadRealTimeMetrics() {
|
||||||
glog.V(3).Infof("ClusterSpec fed with #%v ContainerUsageSamples for #%v containers", sampleCount, len(containersMetrics))
|
glog.V(3).Infof("ClusterSpec fed with #%v ContainerUsageSamples for #%v containers", sampleCount, len(containersMetrics))
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContainerUsageSamplesWithKey(metrics *cluster.ContainerMetricsSnapshot) []*model.ContainerUsageSampleWithKey {
|
func newContainerUsageSamplesWithKey(metrics *metrics.ContainerMetricsSnapshot) []*model.ContainerUsageSampleWithKey {
|
||||||
var samples []*model.ContainerUsageSampleWithKey
|
var samples []*model.ContainerUsageSampleWithKey
|
||||||
|
|
||||||
for metricName, resourceAmount := range metrics.Usage {
|
for metricName, resourceAmount := range metrics.Usage {
|
||||||
|
|
@ -252,7 +253,7 @@ func createPodResourceRecommender() logic.PodResourceRecommender {
|
||||||
// NewRecommender creates a new recommender instance,
|
// NewRecommender creates a new recommender instance,
|
||||||
// which can be run in order to provide continuous resource recommendations for containers.
|
// which can be run in order to provide continuous resource recommendations for containers.
|
||||||
// It requires cluster configuration object and duration between recommender intervals.
|
// It requires cluster configuration object and duration between recommender intervals.
|
||||||
func NewRecommender(config *rest.Config, metricsFetcherInterval time.Duration, historyProvider signals.HistoryProvider) Recommender {
|
func NewRecommender(config *rest.Config, metricsFetcherInterval time.Duration, historyProvider history.HistoryProvider) Recommender {
|
||||||
recommender := &recommender{
|
recommender := &recommender{
|
||||||
clusterState: model.NewClusterState(),
|
clusterState: model.NewClusterState(),
|
||||||
specClient: newSpecClient(config),
|
specClient: newSpecClient(config),
|
||||||
|
|
@ -268,15 +269,15 @@ func NewRecommender(config *rest.Config, metricsFetcherInterval time.Duration, h
|
||||||
return recommender
|
return recommender
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSpecClient(config *rest.Config) cluster.SpecClient {
|
func newSpecClient(config *rest.Config) spec.SpecClient {
|
||||||
kubeClient := kube_client.NewForConfigOrDie(config)
|
kubeClient := kube_client.NewForConfigOrDie(config)
|
||||||
podLister := newPodLister(kubeClient)
|
podLister := newPodLister(kubeClient)
|
||||||
return cluster.NewSpecClient(podLister)
|
return spec.NewSpecClient(podLister)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMetricsClient(config *rest.Config) cluster.MetricsClient {
|
func newMetricsClient(config *rest.Config) metrics.MetricsClient {
|
||||||
metricsGetter := resourceclient.NewForConfigOrDie(config)
|
metricsGetter := resourceclient.NewForConfigOrDie(config)
|
||||||
return cluster.NewMetricsClient(metricsGetter)
|
return metrics.NewMetricsClient(metricsGetter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates PodLister, listing only not terminated pods.
|
// Creates PodLister, listing only not terminated pods.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue