@@ -10,6 +10,7 @@ import (
1010 apimeta "k8s.io/apimachinery/pkg/api/meta"
1111 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212 "k8s.io/apimachinery/pkg/runtime"
13+ utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1314
1415 "go.datum.net/workload-operator/api/v1alpha"
1516 "go.datum.net/workload-operator/internal/controller/instancecontrol"
@@ -20,14 +21,14 @@ var (
2021)
2122
2223func init () {
23- v1alpha .AddToScheme (scheme )
24+ utilruntime . Must ( v1alpha .AddToScheme (scheme ) )
2425}
2526
2627func TestFreshDeployment (t * testing.T ) {
2728 ctx := context .Background ()
2829 control := NewStatefulControl ()
2930
30- deployment := getWorkloadDeployment ("test-deploy" , "default " , 2 )
31+ deployment := getWorkloadDeployment ("test-fresh- deploy" , 2 )
3132
3233 // No instances
3334 var currentInstances []v1alpha.Instance
@@ -49,7 +50,7 @@ func TestUpdateWithAllReadyInstances(t *testing.T) {
4950 ctx := context .Background ()
5051 control := NewStatefulControl ()
5152
52- deployment := getWorkloadDeployment ("test-deploy" , "default" , 2 )
53+ deployment := getWorkloadDeployment ("test-deploy" , 2 )
5354
5455 var currentInstances []v1alpha.Instance
5556 currentInstances = append (currentInstances , * getInstanceForDeployment (deployment , 0 ))
@@ -75,7 +76,7 @@ func TestScaleUpWithNotReadyInstance(t *testing.T) {
7576 ctx := context .Background ()
7677 control := NewStatefulControl ()
7778
78- deployment := getWorkloadDeployment ("test-deploy" , "default" , 3 )
79+ deployment := getWorkloadDeployment ("test-deploy" , 3 )
7980
8081 var currentInstances []v1alpha.Instance
8182 currentInstances = append (currentInstances , * getInstanceForDeployment (deployment , 0 ))
@@ -105,7 +106,7 @@ func TestScaleDownWithAllReadyInstances(t *testing.T) {
105106 ctx := context .Background ()
106107 control := NewStatefulControl ()
107108
108- deployment := getWorkloadDeployment ("test-deploy" , "default" , 1 )
109+ deployment := getWorkloadDeployment ("test-deploy" , 1 )
109110
110111 var currentInstances []v1alpha.Instance
111112 currentInstances = append (currentInstances , * getInstanceForDeployment (deployment , 0 ))
@@ -123,12 +124,12 @@ func TestScaleDownWithAllReadyInstances(t *testing.T) {
123124
124125// Add more test functions below for different scenarios.
125126
126- func getWorkloadDeployment (name , namespace string , minReplicas int32 ) * v1alpha.WorkloadDeployment {
127- instance := getInstanceTemplate (name , namespace , 0 )
127+ func getWorkloadDeployment (name string , minReplicas int32 ) * v1alpha.WorkloadDeployment {
128+ instance := getInstanceTemplate (name , 0 )
128129 deployment := & v1alpha.WorkloadDeployment {
129130 ObjectMeta : metav1.ObjectMeta {
130131 Name : name ,
131- Namespace : namespace ,
132+ Namespace : "default" ,
132133 },
133134 Spec : v1alpha.WorkloadDeploymentSpec {
134135 ScaleSettings : v1alpha.HorizontalScaleSettings {
@@ -146,16 +147,16 @@ func getWorkloadDeployment(name, namespace string, minReplicas int32) *v1alpha.W
146147}
147148
148149func getInstanceForDeployment (deployment * v1alpha.WorkloadDeployment , ordinal int ) * v1alpha.Instance {
149- instance := getInstance (deployment .Name , deployment . Namespace , ordinal )
150+ instance := getInstance (deployment .Name , ordinal )
150151 instance .Spec .Controller = & v1alpha.InstanceController {
151152 TemplateHash : instancecontrol .ComputeHash (deployment .Spec .Template ),
152153 }
153154
154155 return instance
155156}
156157
157- func getInstance (name , namespace string , ordinal int ) * v1alpha.Instance {
158- instance := getInstanceTemplate (name , namespace , ordinal )
158+ func getInstance (name string , ordinal int ) * v1alpha.Instance {
159+ instance := getInstanceTemplate (name , ordinal )
159160 instance .CreationTimestamp = metav1 .Now ()
160161 instance .Labels = map [string ]string {
161162 v1alpha .InstanceIndexLabel : strconv .Itoa (ordinal ),
@@ -176,12 +177,12 @@ func getInstance(name, namespace string, ordinal int) *v1alpha.Instance {
176177 return instance
177178}
178179
179- func getInstanceTemplate (name , namespace string , ordinal int ) * v1alpha.Instance {
180+ func getInstanceTemplate (name string , ordinal int ) * v1alpha.Instance {
180181 instanceName := fmt .Sprintf ("%s-%d" , name , ordinal )
181182 instance := & v1alpha.Instance {
182183 ObjectMeta : metav1.ObjectMeta {
183184 Name : instanceName ,
184- Namespace : namespace ,
185+ Namespace : "default" ,
185186 },
186187 Spec : v1alpha.InstanceSpec {
187188 Runtime : v1alpha.InstanceRuntimeSpec {
0 commit comments