Merge pull request #1140 from schylek/r
VPA shouldn't store checkpoint if history is being loaded.
This commit is contained in:
commit
21c666e4e9
|
|
@ -21,6 +21,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/poc.autoscaling.k8s.io/v1alpha1"
|
||||
vpa_api "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned/typed/poc.autoscaling.k8s.io/v1alpha1"
|
||||
|
|
@ -47,8 +48,22 @@ func NewCheckpointWriter(cluster *model.ClusterState, vpaCheckpointClient vpa_ap
|
|||
}
|
||||
}
|
||||
|
||||
func isFetchingHistory(vpa *model.Vpa) bool {
|
||||
condition, found := vpa.Conditions[vpa_types.FetchingHistory]
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
return condition.Status == v1.ConditionTrue
|
||||
}
|
||||
|
||||
func (writer *checkpointWriter) StoreCheckpoints(now time.Time) {
|
||||
for _, vpa := range writer.cluster.Vpas {
|
||||
|
||||
if isFetchingHistory(vpa) {
|
||||
glog.V(3).Infof("VPA %s/%s is loading history, skipping checkpoints", vpa.ID.Namespace, vpa.ID.VpaName)
|
||||
continue
|
||||
}
|
||||
|
||||
aggregateContainerStateMap := buildAggregateContainerStateMap(vpa, writer.cluster, now)
|
||||
for container, aggregatedContainerState := range aggregateContainerStateMap {
|
||||
containerCheckpoint, err := aggregatedContainerState.SaveToCheckpoint()
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/api/core/v1"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/poc.autoscaling.k8s.io/v1alpha1"
|
||||
|
|
@ -74,3 +75,44 @@ func TestMergeContainerStateForCheckpointDropsRecentMemoryPeak(t *testing.T) {
|
|||
"Old peak should not be excluded from the aggregation.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsFetchingHistory(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
vpa model.Vpa
|
||||
isFetchingHistory bool
|
||||
}{
|
||||
{
|
||||
vpa: model.Vpa{},
|
||||
isFetchingHistory: false,
|
||||
},
|
||||
{
|
||||
vpa: model.Vpa{
|
||||
PodSelector: nil,
|
||||
Conditions: map[vpa_types.VerticalPodAutoscalerConditionType]vpa_types.VerticalPodAutoscalerCondition{
|
||||
vpa_types.FetchingHistory: {
|
||||
Type: vpa_types.FetchingHistory,
|
||||
Status: v1.ConditionFalse,
|
||||
},
|
||||
},
|
||||
},
|
||||
isFetchingHistory: false,
|
||||
},
|
||||
{
|
||||
vpa: model.Vpa{
|
||||
PodSelector: nil,
|
||||
Conditions: map[vpa_types.VerticalPodAutoscalerConditionType]vpa_types.VerticalPodAutoscalerCondition{
|
||||
vpa_types.FetchingHistory: {
|
||||
Type: vpa_types.FetchingHistory,
|
||||
Status: v1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
},
|
||||
isFetchingHistory: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
assert.Equalf(t, tc.isFetchingHistory, isFetchingHistory(&tc.vpa), "%+v should have %v as isFetchingHistoryResult", tc.vpa, tc.isFetchingHistory)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue