Skip to content

Commit f189dce

Browse files
committed
Fix Depl Creation
1 parent 14030f2 commit f189dce

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

pkg/handlers/scheduler/batchjob/handler_manage_test.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ import (
2525

2626
"github.com/stretchr/testify/require"
2727
batch "k8s.io/api/batch/v1"
28+
core "k8s.io/api/core/v1"
2829
"k8s.io/apimachinery/pkg/types"
2930

3031
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
32+
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
33+
schedulerPodResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod/resources"
3134
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
3235
"github.com/arangodb/kube-arangodb/pkg/util"
3336
"github.com/arangodb/kube-arangodb/pkg/util/tests"
@@ -205,7 +208,20 @@ func Test_Handler_Profile(t *testing.T) {
205208
handler := newFakeHandler()
206209

207210
// Arrange
208-
profile := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test", tests.MarkArangoProfileAsReady)
211+
profile := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test", func(t *testing.T, obj *schedulerApi.ArangoProfile) {
212+
obj.Spec.Template = &schedulerApi.ProfileTemplate{
213+
Pod: &schedulerPodApi.Pod{
214+
Volumes: &schedulerPodResourcesApi.Volumes{
215+
Volumes: []core.Volume{
216+
{
217+
Name: "test",
218+
VolumeSource: core.VolumeSource{},
219+
},
220+
},
221+
},
222+
},
223+
}
224+
}, tests.MarkArangoProfileAsReady)
209225
extension := tests.NewMetaObject[*schedulerApi.ArangoSchedulerBatchJob](t, tests.FakeNamespace, "test",
210226
func(t *testing.T, obj *schedulerApi.ArangoSchedulerBatchJob) {
211227
obj.Spec.Profiles = []string{profile.GetName()}
@@ -227,4 +243,9 @@ func Test_Handler_Profile(t *testing.T) {
227243

228244
require.Len(t, extension.Status.Profiles, 1)
229245
require.Equal(t, profile.GetName(), extension.Status.Profiles[0])
246+
247+
require.Len(t, extension.Status.Profiles, 1)
248+
require.Equal(t, profile.GetName(), extension.Status.Profiles[0])
249+
require.Len(t, batchJob.Spec.Template.Spec.Volumes, 1)
250+
require.EqualValues(t, "test", batchJob.Spec.Template.Spec.Volumes[0].Name)
230251
}

pkg/handlers/scheduler/cronjob/handler_manage_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"k8s.io/apimachinery/pkg/types"
3030

3131
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
32+
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
33+
schedulerPodResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod/resources"
3234
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
3335
"github.com/arangodb/kube-arangodb/pkg/util"
3436
"github.com/arangodb/kube-arangodb/pkg/util/tests"
@@ -206,7 +208,20 @@ func Test_Handler_Profile(t *testing.T) {
206208
handler := newFakeHandler()
207209

208210
// Arrange
209-
profile := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test", tests.MarkArangoProfileAsReady)
211+
profile := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test", func(t *testing.T, obj *schedulerApi.ArangoProfile) {
212+
obj.Spec.Template = &schedulerApi.ProfileTemplate{
213+
Pod: &schedulerPodApi.Pod{
214+
Volumes: &schedulerPodResourcesApi.Volumes{
215+
Volumes: []core.Volume{
216+
{
217+
Name: "test",
218+
VolumeSource: core.VolumeSource{},
219+
},
220+
},
221+
},
222+
},
223+
}
224+
}, tests.MarkArangoProfileAsReady)
210225
extension := tests.NewMetaObject[*schedulerApi.ArangoSchedulerCronJob](t, tests.FakeNamespace, "test",
211226
func(t *testing.T, obj *schedulerApi.ArangoSchedulerCronJob) {
212227
obj.Spec.Profiles = []string{profile.GetName()}
@@ -228,4 +243,9 @@ func Test_Handler_Profile(t *testing.T) {
228243

229244
require.Len(t, extension.Status.Profiles, 1)
230245
require.Equal(t, profile.GetName(), extension.Status.Profiles[0])
246+
247+
require.Len(t, extension.Status.Profiles, 1)
248+
require.Equal(t, profile.GetName(), extension.Status.Profiles[0])
249+
require.Len(t, cronJob.Spec.JobTemplate.Spec.Template.Spec.Volumes, 1)
250+
require.EqualValues(t, "test", cronJob.Spec.JobTemplate.Spec.Template.Spec.Volumes[0].Name)
231251
}

pkg/handlers/scheduler/deployment/handler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ func (h *handler) HandleObject(ctx context.Context, item operation.Item, extensi
148148
Labels: extension.ObjectMeta.Labels,
149149
Annotations: extension.ObjectMeta.Annotations,
150150
}
151-
extension.Spec.DeploymentSpec.DeepCopyInto(&obj.Spec)
152-
extension.Spec.DeploymentSpec.Template.DeepCopyInto(&obj.Spec.Template)
151+
deploymentTemplate.Spec.DeepCopyInto(&obj.Spec)
152+
deploymentTemplate.Spec.Template.DeepCopyInto(&obj.Spec.Template)
153153

154154
obj.OwnerReferences = append(obj.OwnerReferences, extension.AsOwner())
155155

pkg/handlers/scheduler/deployment/handler_manage_test.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ import (
2525

2626
"github.com/stretchr/testify/require"
2727
apps "k8s.io/api/apps/v1"
28+
core "k8s.io/api/core/v1"
2829
"k8s.io/apimachinery/pkg/types"
2930

3031
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
32+
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
33+
schedulerPodResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod/resources"
3134
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
3235
"github.com/arangodb/kube-arangodb/pkg/util"
3336
"github.com/arangodb/kube-arangodb/pkg/util/tests"
@@ -202,10 +205,24 @@ func Test_Handler_Profile(t *testing.T) {
202205
handler := newFakeHandler()
203206

204207
// Arrange
205-
profile := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test", tests.MarkArangoProfileAsReady)
208+
profile := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test", func(t *testing.T, obj *schedulerApi.ArangoProfile) {
209+
obj.Spec.Template = &schedulerApi.ProfileTemplate{
210+
Pod: &schedulerPodApi.Pod{
211+
Volumes: &schedulerPodResourcesApi.Volumes{
212+
Volumes: []core.Volume{
213+
{
214+
Name: "test",
215+
VolumeSource: core.VolumeSource{},
216+
},
217+
},
218+
},
219+
},
220+
}
221+
}, tests.MarkArangoProfileAsReady)
206222
extension := tests.NewMetaObject[*schedulerApi.ArangoSchedulerDeployment](t, tests.FakeNamespace, "test",
207223
func(t *testing.T, obj *schedulerApi.ArangoSchedulerDeployment) {
208224
obj.Spec.Profiles = []string{profile.GetName()}
225+
obj.Spec.DeploymentSpec.Replicas = util.NewType[int32](10)
209226
})
210227
deployment := tests.NewMetaObject[*apps.Deployment](t, tests.FakeNamespace, "test")
211228

@@ -222,6 +239,11 @@ func Test_Handler_Profile(t *testing.T) {
222239
tests.RefreshObjects(t, handler.kubeClient, handler.client, &deployment)
223240
require.NotNil(t, deployment)
224241

242+
require.NotNil(t, deployment.Spec.Replicas)
243+
require.EqualValues(t, 10, *deployment.Spec.Replicas)
244+
225245
require.Len(t, extension.Status.Profiles, 1)
226246
require.Equal(t, profile.GetName(), extension.Status.Profiles[0])
247+
require.Len(t, deployment.Spec.Template.Spec.Volumes, 1)
248+
require.EqualValues(t, "test", deployment.Spec.Template.Spec.Volumes[0].Name)
227249
}

pkg/handlers/scheduler/pod/handler_manage_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"k8s.io/apimachinery/pkg/types"
2929

3030
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
31+
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
32+
schedulerPodResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod/resources"
3133
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
3234
"github.com/arangodb/kube-arangodb/pkg/util"
3335
"github.com/arangodb/kube-arangodb/pkg/util/tests"
@@ -202,7 +204,20 @@ func Test_Handler_Profile(t *testing.T) {
202204
handler := newFakeHandler()
203205

204206
// Arrange
205-
profile := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test", tests.MarkArangoProfileAsReady)
207+
profile := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test", func(t *testing.T, obj *schedulerApi.ArangoProfile) {
208+
obj.Spec.Template = &schedulerApi.ProfileTemplate{
209+
Pod: &schedulerPodApi.Pod{
210+
Volumes: &schedulerPodResourcesApi.Volumes{
211+
Volumes: []core.Volume{
212+
{
213+
Name: "test",
214+
VolumeSource: core.VolumeSource{},
215+
},
216+
},
217+
},
218+
},
219+
}
220+
}, tests.MarkArangoProfileAsReady)
206221
extension := tests.NewMetaObject[*schedulerApi.ArangoSchedulerPod](t, tests.FakeNamespace, "test",
207222
func(t *testing.T, obj *schedulerApi.ArangoSchedulerPod) {
208223
obj.Spec.Profiles = []string{profile.GetName()}
@@ -224,4 +239,9 @@ func Test_Handler_Profile(t *testing.T) {
224239

225240
require.Len(t, extension.Status.Profiles, 1)
226241
require.Equal(t, profile.GetName(), extension.Status.Profiles[0])
242+
243+
require.Len(t, extension.Status.Profiles, 1)
244+
require.Equal(t, profile.GetName(), extension.Status.Profiles[0])
245+
require.Len(t, pod.Spec.Volumes, 1)
246+
require.EqualValues(t, "test", pod.Spec.Volumes[0].Name)
227247
}

0 commit comments

Comments
 (0)