Skip to content

Commit

Permalink
refactor: file-based controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho committed Oct 6, 2023
1 parent 1753133 commit 54fe86f
Show file tree
Hide file tree
Showing 78 changed files with 3,549 additions and 2,288 deletions.
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = BeforeSuite(func() {

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases"), filepath.Join("testdata")},
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases"), filepath.Join("testdata", "crd")},
ErrorIfCRDPathMissing: true,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ metadata:
annotations:
api-approved.kubernetes.io: https://github.com/kubernetes/kubernetes/pull/63797
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: verticalpodautoscalercheckpoints.autoscaling.k8s.io
spec:
group: autoscaling.k8s.io
Expand Down Expand Up @@ -210,7 +209,6 @@ metadata:
annotations:
api-approved.kubernetes.io: https://github.com/kubernetes/kubernetes/pull/63797
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: verticalpodautoscalers.autoscaling.k8s.io
spec:
group: autoscaling.k8s.io
Expand Down
30 changes: 30 additions & 0 deletions controllers/testdata/deletion-no-delete/before/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
metadata:
creationTimestamp: null
name: mercari-app
namespace: default
spec:
selector:
matchLabels:
app: mercari
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mercari
spec:
containers:
- image: awesome-mercari-app-image
name: app
resources:
requests:
cpu: "10"
memory: 10Gi
- image: awesome-istio-proxy-image
name: istio-proxy
resources:
requests:
cpu: "4"
memory: 4Gi
status:
replicas: 10
46 changes: 46 additions & 0 deletions controllers/testdata/deletion-no-delete/before/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
tortoises.autoscaling.mercari.com/tortoise-name: mercari
creationTimestamp: null
name: tortoise-hpa-mercari
namespace: default
spec:
behavior:
scaleDown:
policies:
- periodSeconds: 90
type: Percent
value: 2
selectPolicy: Max
scaleUp:
policies:
- periodSeconds: 60
type: Percent
value: 100
selectPolicy: Max
stabilizationWindowSeconds: 0
maxReplicas: 100
metrics:
- containerResource:
container: app
name: cpu
target:
averageUtilization: 50
type: Utilization
type: ContainerResource
- containerResource:
container: istio-proxy
name: cpu
target:
averageUtilization: 50
type: Utilization
type: ContainerResource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
status:
currentMetrics: null
desiredReplicas: 0
88 changes: 88 additions & 0 deletions controllers/testdata/deletion-no-delete/before/tortoise.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
metadata:
creationTimestamp: null
name: mercari
namespace: default
spec:
deletionPolicy: NoDelete
resourcePolicy:
- autoscalingPolicy:
cpu: Horizontal
memory: Vertical
containerName: app
- autoscalingPolicy:
cpu: Horizontal
memory: Vertical
containerName: istio-proxy
targetRefs:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
status:
conditions:
containerRecommendationFromVPA:
- containerName: app
maxRecommendation:
cpu:
quantity: "0"
updatedAt: null
memory:
quantity: "0"
updatedAt: null
recommendation:
cpu:
quantity: "0"
updatedAt: null
memory:
quantity: "0"
updatedAt: null
- containerName: istio-proxy
maxRecommendation:
cpu:
quantity: "0"
updatedAt: null
memory:
quantity: "0"
updatedAt: null
recommendation:
cpu:
quantity: "0"
updatedAt: null
memory:
quantity: "0"
updatedAt: null
tortoiseConditions: null
recommendations:
horizontal:
maxReplicas:
- from: 0
timezone: Local
to: 24
updatedAt: "2023-10-06T01:32:21Z"
value: 15
weekday: Friday
minReplicas:
- from: 0
timezone: Local
to: 24
updatedAt: "2023-10-06T01:32:21Z"
value: 3
weekday: Friday
targetUtilizations:
- containerName: app
targetUtilization:
cpu: 50
- containerName: istio-proxy
targetUtilization:
cpu: 50
vertical:
containerResourceRecommendation: null
targets:
deployment: ""
horizontalPodAutoscaler: tortoise-hpa-mercari
verticalPodAutoscalers:
- name: tortoise-updater-mercari
role: Updater
- name: tortoise-monitor-mercari
role: Monitor
tortoisePhase: Working
45 changes: 45 additions & 0 deletions controllers/testdata/deletion-no-delete/before/vpa-Monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
tortoises.autoscaling.mercari.com/tortoise-name: mercari
creationTimestamp: null
name: tortoise-monitor-mercari
namespace: default
spec:
resourcePolicy:
containerPolicies:
- containerName: app
- containerName: istio-proxy
targetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
updatePolicy:
updateMode: "Off"
status:
conditions:
- lastTransitionTime: null
status: "True"
type: RecommendationProvided
recommendation:
containerRecommendations:
- containerName: app
lowerBound:
cpu: "3"
memory: 3Gi
target:
cpu: "3"
memory: 3Gi
upperBound:
cpu: "5"
memory: 5Gi
- containerName: istio-proxy
lowerBound:
cpu: "3"
memory: 3Gi
target:
cpu: "3"
memory: 3Gi
upperBound:
cpu: "5"
memory: 5Gi
21 changes: 21 additions & 0 deletions controllers/testdata/deletion-no-delete/before/vpa-Updater.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
tortoises.autoscaling.mercari.com/tortoise-name: mercari
creationTimestamp: null
name: tortoise-updater-mercari
namespace: default
spec:
recommenders:
- name: tortoise-controller
resourcePolicy:
containerPolicies:
- containerName: app
- containerName: istio-proxy
targetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
updatePolicy:
updateMode: Auto
status: {}
30 changes: 30 additions & 0 deletions controllers/testdata/deletion-policy-all/before/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
metadata:
creationTimestamp: null
name: mercari-app
namespace: default
spec:
selector:
matchLabels:
app: mercari
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mercari
spec:
containers:
- image: awesome-mercari-app-image
name: app
resources:
requests:
cpu: "10"
memory: 10Gi
- image: awesome-istio-proxy-image
name: istio-proxy
resources:
requests:
cpu: "4"
memory: 4Gi
status:
replicas: 10
46 changes: 46 additions & 0 deletions controllers/testdata/deletion-policy-all/before/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
metadata:
annotations:
tortoise.autoscaling.mercari.com/managed-by-tortoise: "true"
tortoises.autoscaling.mercari.com/tortoise-name: mercari
creationTimestamp: null
name: tortoise-hpa-mercari
namespace: default
spec:
behavior:
scaleDown:
policies:
- periodSeconds: 90
type: Percent
value: 2
selectPolicy: Max
scaleUp:
policies:
- periodSeconds: 60
type: Percent
value: 100
selectPolicy: Max
stabilizationWindowSeconds: 0
maxReplicas: 100
metrics:
- containerResource:
container: app
name: cpu
target:
averageUtilization: 50
type: Utilization
type: ContainerResource
- containerResource:
container: istio-proxy
name: cpu
target:
averageUtilization: 50
type: Utilization
type: ContainerResource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: mercari-app
status:
currentMetrics: null
desiredReplicas: 0
Loading

0 comments on commit 54fe86f

Please sign in to comment.