-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: scaleobject ready condition 'False/Unknow' to 'True' requeue (#3097
- Loading branch information
Showing
7 changed files
with
246 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package scalers | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"sync/atomic" | ||
|
||
"k8s.io/api/autoscaling/v2beta2" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/metrics/pkg/apis/external_metrics" | ||
) | ||
|
||
const ( | ||
MockExternalServerStatusOffline int32 = 0 | ||
MockExternalServerStatusOnline int32 = 1 | ||
) | ||
|
||
var ( | ||
MockExternalServerStatus = MockExternalServerStatusOnline | ||
ErrMock = errors.New("mock error") | ||
MockMetricName = "mockMetricName" | ||
MockMetricTarget int64 = 50 | ||
MockMetricValue int64 = 100 | ||
) | ||
|
||
type externalMockScaler struct{} | ||
|
||
func NewExternalMockScaler(config *ScalerConfig) (Scaler, error) { | ||
return &externalMockScaler{}, nil | ||
} | ||
|
||
// IsActive implements Scaler | ||
func (*externalMockScaler) IsActive(ctx context.Context) (bool, error) { | ||
if atomic.LoadInt32(&MockExternalServerStatus) != MockExternalServerStatusOnline { | ||
return false, ErrMock | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
// Close implements Scaler | ||
func (*externalMockScaler) Close(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
// GetMetricSpecForScaling implements Scaler | ||
func (*externalMockScaler) GetMetricSpecForScaling(ctx context.Context) []v2beta2.MetricSpec { | ||
if atomic.LoadInt32(&MockExternalServerStatus) != MockExternalServerStatusOnline { | ||
return nil | ||
} | ||
|
||
return getMockMetricsSpecs() | ||
} | ||
|
||
// GetMetrics implements Scaler | ||
func (*externalMockScaler) GetMetrics(ctx context.Context, metricName string, metricSelector labels.Selector) ([]external_metrics.ExternalMetricValue, error) { | ||
if atomic.LoadInt32(&MockExternalServerStatus) != MockExternalServerStatusOnline { | ||
return nil, ErrMock | ||
} | ||
|
||
return getMockExternalMetricsValue(), nil | ||
} | ||
|
||
func getMockMetricsSpecs() []v2beta2.MetricSpec { | ||
return []v2beta2.MetricSpec{ | ||
{ | ||
Type: v2beta2.ExternalMetricSourceType, | ||
External: &v2beta2.ExternalMetricSource{ | ||
Metric: v2beta2.MetricIdentifier{ | ||
Name: MockMetricName, | ||
}, | ||
Target: v2beta2.MetricTarget{ | ||
Type: v2beta2.ValueMetricType, | ||
Value: resource.NewQuantity(MockMetricValue, resource.DecimalSI), | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func getMockExternalMetricsValue() []external_metrics.ExternalMetricValue { | ||
return []external_metrics.ExternalMetricValue{ | ||
{ | ||
MetricName: MockMetricName, | ||
Value: *resource.NewQuantity(MockMetricValue, resource.DecimalSI), | ||
Timestamp: metav1.Now(), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters