-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from doitintl/feature/cover
feat: Cover deprecated autoscaling/v2beta1 and autoscaling/v2beta2
- Loading branch information
Showing
6 changed files
with
120 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: autoscaling/v2beta1 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
name: php-apache | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: php-apache | ||
minReplicas: 1 | ||
maxReplicas: 10 | ||
metrics: | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
target: | ||
type: Utilization | ||
averageUtilization: 50 | ||
status: | ||
observedGeneration: 1 | ||
lastScaleTime: 12 | ||
currentReplicas: 1 | ||
desiredReplicas: 1 | ||
currentMetrics: | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
current: | ||
averageUtilization: 0 | ||
averageValue: 0 |
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,30 @@ | ||
apiVersion: autoscaling/v2beta2 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
name: php-apache | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: php-apache | ||
minReplicas: 1 | ||
maxReplicas: 10 | ||
metrics: | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
target: | ||
type: Utilization | ||
averageUtilization: 50 | ||
status: | ||
observedGeneration: 1 | ||
lastScaleTime: 12 | ||
currentReplicas: 1 | ||
desiredReplicas: 1 | ||
currentMetrics: | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
current: | ||
averageUtilization: 0 | ||
averageValue: 0 |
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,42 @@ | ||
package deprecated126 | ||
|
||
main[return] { | ||
resource := input[_] | ||
api := deprecated_resource(resource) | ||
return := { | ||
"Name": get_default(resource.metadata, "name", "<undefined>"), | ||
# Namespace does not have to be defined in case of local manifests | ||
"Namespace": get_default(resource.metadata, "namespace", "<undefined>"), | ||
"Kind": resource.kind, | ||
"ApiVersion": api.old, | ||
"ReplaceWith": api.new, | ||
"RuleSet": "Deprecated APIs removed in 1.26", | ||
"Since": api.since, | ||
} | ||
} | ||
|
||
deprecated_resource(r) = api { | ||
api := deprecated_api(r.kind, r.apiVersion) | ||
} | ||
|
||
deprecated_api(kind, api_version) = api { | ||
deprecated_apis = {"HorizontalPodAutoscaler": { | ||
"old": ["autoscaling/v2beta1", "autoscaling/v2beta2"], | ||
"new": "autoscaling/v2", | ||
"since": "1.23", | ||
}} | ||
|
||
deprecated_apis[kind].old[_] == api_version | ||
|
||
api := { | ||
"old": api_version, | ||
"new": deprecated_apis[kind].new, | ||
"since": deprecated_apis[kind].since, | ||
} | ||
} | ||
|
||
get_default(val, key, _) = val[key] | ||
|
||
get_default(val, key, fallback) = fallback { | ||
not val[key] | ||
} |
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,14 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRego126(t *testing.T) { | ||
testCases := []resourceFixtureTestCase{ | ||
{"AutoScaler-v2beta1", []string{"../fixtures/autoscaler-v2beta1.yaml"}, []string{"HorizontalPodAutoscaler"}}, | ||
{"AutoScaler-v2beta2", []string{"../fixtures/autoscaler-v2beta2.yaml"}, []string{"HorizontalPodAutoscaler"}}, | ||
} | ||
|
||
testResourcesUsingFixtures(t, testCases) | ||
} |