Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions provider/servicejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"maps"
"time"

corev1 "k8s.io/api/core/v1"

"github.com/codesphere-cloud/managed-services-lib/client"
"github.com/codesphere-cloud/managed-services-lib/model"
)
Expand Down Expand Up @@ -62,6 +64,8 @@ type ServiceJob struct {
Labels map[string]string
// ImagePullSecrets names Secrets used to pull Image from a private registry.
ImagePullSecrets []string
// Resources sets the container's resource requests/limits.
Resources corev1.ResourceRequirements
}

// ServiceJobName is the Job naming convention: "<operation>-<key>". It is stable
Expand Down Expand Up @@ -93,6 +97,7 @@ func ServiceJobSpec(j ServiceJob) client.JobSpec {
Secrets: j.Secrets,
Labels: labels,
ImagePullSecrets: j.ImagePullSecrets,
Resources: j.Resources,
}
}

Expand Down
28 changes: 28 additions & 0 deletions provider/servicejob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

"github.com/codesphere-cloud/managed-services-lib/client"
"github.com/codesphere-cloud/managed-services-lib/model"
Expand Down Expand Up @@ -65,6 +67,32 @@ var _ = Describe("Service job core", func() {
})
Expect(spec.ImagePullSecrets).To(Equal([]string{"regcred"}))
})

It("passes container resources through", func() {
res := corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("200m"),
corev1.ResourceMemory: resource.MustParse("256Mi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("512Mi"),
},
}
spec := provider.ServiceJobSpec(provider.ServiceJob{
Operation: provider.JobOpBackup, MsID: "svc-42", Key: "bkp-7",
Resources: res,
})
Expect(spec.Resources).To(Equal(res))
})

It("leaves resources unset if not specified", func() {
spec := provider.ServiceJobSpec(provider.ServiceJob{
Operation: provider.JobOpBackup, MsID: "svc-42", Key: "bkp-7",
})
Expect(spec.Resources.Requests).To(BeEmpty())
Expect(spec.Resources.Limits).To(BeEmpty())
})
})

Describe("OperationStatusFromJob", func() {
Expand Down
Loading