Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default resources to be set on all job types #175

Merged
merged 2 commits into from
Dec 7, 2020
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
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ changelog:
sort: asc
filters:
exclude:
- '^Docs:'
- '^Test:'
- '^Refactor:'
- '^(D|d)oc(s|umentation):'
- '^(T|t)ests?:'
- '^(R|r)efactor:'
- '^Merge pull request'

release:
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/archive_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand Down Expand Up @@ -65,3 +66,7 @@ func (*Archive) GetType() JobType {
func (a *Archive) GetK8upStatus() *K8upStatus {
return &a.Status.K8upStatus
}

func (a *Archive) GetResources() corev1.ResourceRequirements {
return a.Spec.Resources
}
8 changes: 8 additions & 0 deletions api/v1alpha1/backup_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand All @@ -23,6 +24,9 @@ type BackupSpec struct {
StatsURL string `json:"statsURL,omitempty"`
// Tags is a list of arbitrary tags that get added to the backup via Restic's tagging system
Tags []string `json:"tags,omitempty"`

// Resources describes the compute resource requirements (cpu, memory, etc.)
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}

type BackupTemplate struct {
Expand Down Expand Up @@ -89,6 +93,10 @@ func (b *Backup) GetK8upStatus() *K8upStatus {
return &b.Status.K8upStatus
}

func (b *Backup) GetResources() corev1.ResourceRequirements {
return b.Spec.Resources
}

func (b BackupSpec) CreateObject(name, namespace string) runtime.Object {
return &Backup{
ObjectMeta: metav1.ObjectMeta{
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/check_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand All @@ -11,6 +12,8 @@ type CheckSpec struct {
PromURL string `json:"promURL,omitempty"`
Backend *Backend `json:"backend,omitempty"`
KeepJobs *int `json:"keepJobs,omitempty"`
// Resources describes the compute resource requirements (cpu, memory, etc.)
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}

// CheckStatus defines the observed state of Check
Expand Down Expand Up @@ -59,6 +62,10 @@ func (c *Check) GetK8upStatus() *K8upStatus {
return &c.Status.K8upStatus
}

func (c *Check) GetResources() corev1.ResourceRequirements {
return c.Spec.Resources
}

func (c CheckSpec) CreateObject(name, namespace string) runtime.Object {
return &Check{
ObjectMeta: metav1.ObjectMeta{
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/prune_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand All @@ -12,6 +13,8 @@ type PruneSpec struct {
Retention RetentionPolicy `json:"retention,omitempty"`
Backend *Backend `json:"backend,omitempty"`
KeepJobs *int `json:"keepJobs,omitempty"`
// Resources describes the compute resource requirements (cpu, memory, etc.)
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}

func (p PruneSpec) CreateObject(name, namespace string) runtime.Object {
Expand Down Expand Up @@ -72,6 +75,10 @@ func (p *Prune) GetK8upStatus() *K8upStatus {
return &p.Status.K8upStatus
}

func (p *Prune) GetResources() corev1.ResourceRequirements {
return p.Spec.Resources
}

// +kubebuilder:object:root=true

// PruneList contains a list of Prune
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/restore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type RestoreSpec struct {
KeepJobs *int `json:"keepJobs,omitempty"`
// Tags is a list of arbitrary tags that get added to the backup via Restic's tagging system
Tags []string `json:"tags,omitempty"`
// Resources describes the compute resource requirements (cpu, memory, etc.)
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}

func (r RestoreSpec) CreateObject(name, namespace string) runtime.Object {
Expand Down Expand Up @@ -73,6 +75,10 @@ func (r *Restore) GetK8upStatus() *K8upStatus {
return &r.Status.K8upStatus
}

func (r *Restore) GetResources() corev1.ResourceRequirements {
return r.Spec.Resources
}

// +kubebuilder:object:root=true

// RestoreList contains a list of Restore
Expand Down
19 changes: 7 additions & 12 deletions api/v1alpha1/schedule_types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package v1alpha1

import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand All @@ -16,6 +15,8 @@ type ScheduleSpec struct {
Prune *PruneSchedule `json:"prune,omitempty"`
Backend *Backend `json:"backend,omitempty"`
KeepJobs *int `json:"keepJobs,omitempty"`
// ResourceRequirementsTemplate describes the compute resource requirements (cpu, memory, etc.)
ResourceRequirementsTemplate corev1.ResourceRequirements `json:"resourceRequirementsTemplate,omitempty"`
}

// ScheduleCommon contains fields every schedule needs
Expand Down Expand Up @@ -53,16 +54,6 @@ type PruneSchedule struct {
*ScheduleCommon `json:",inline"`
}

type NamespacedName struct {
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
}

// String returns the general purpose string representation
func (n NamespacedName) String() string {
return fmt.Sprintf("%s%s%s", n.Namespace, "/", n.Name)
}

// ScheduleStatus defines the observed state of Schedule
type ScheduleStatus struct {
}
Expand Down Expand Up @@ -107,3 +98,7 @@ func (*Schedule) GetType() JobType {
func (s *Schedule) GetK8upStatus() *K8upStatus {
return nil
}

func (s *Schedule) GetResources() corev1.ResourceRequirements {
return s.Spec.ResourceRequirementsTemplate
}
20 changes: 5 additions & 15 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 53 additions & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cfg

import "fmt"
import (
"fmt"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

const (
RestoreS3EndpointEnvName = "RESTORE_S3ENDPOINT"
Expand Down Expand Up @@ -36,6 +40,10 @@ type Configuration struct {
GlobalConcurrentCheckJobsLimit int `koanf:"globalconcurrentcheckjobslimit"`
GlobalConcurrentPruneJobsLimit int `koanf:"globalconcurrentprunejobslimit"`
GlobalConcurrentRestoreJobsLimit int `koanf:"globalconcurrentrestorejobslimit"`
GlobalCPUResourceRequest string `koanf:"globalcpu-request"`
GlobalCPUResourceLimit string `koanf:"globalcpu-limit"`
GlobalMemoryResourceRequest string `koanf:"globalmemory-request"`
GlobalMemoryResourceLimit string `koanf:"globalmemory-limit"`
BackupImage string `koanf:"image"`
MetricsBindAddress string `koanf:"metrics-bindaddress"`
PodExecRoleName string `koanf:"podexecrolename"`
Expand Down Expand Up @@ -66,6 +74,50 @@ func NewDefaultConfig() *Configuration {
}
}

func (c Configuration) ValidateSyntax() error {
if _, err := resource.ParseQuantity(c.GlobalMemoryResourceRequest); err != nil && c.GlobalMemoryResourceRequest != "" {
return fmt.Errorf("cannot parse global memory request: %v", err)
}
if _, err := resource.ParseQuantity(c.GlobalMemoryResourceLimit); err != nil && c.GlobalMemoryResourceLimit != "" {
return fmt.Errorf("cannot parse global memory limit: %v", err)
}
if _, err := resource.ParseQuantity(c.GlobalCPUResourceRequest); err != nil && c.GlobalCPUResourceRequest != "" {
return fmt.Errorf("cannot parse global CPU request: %v", err)
}
if _, err := resource.ParseQuantity(c.GlobalCPUResourceLimit); err != nil && c.GlobalCPUResourceLimit != "" {
return fmt.Errorf("cannot parse global CPU limit: %v", err)
}
return nil
}

func (c Configuration) GetGlobalDefaultResources() (res corev1.ResourceRequirements) {
if r, err := resource.ParseQuantity(c.GlobalMemoryResourceRequest); err == nil && c.GlobalMemoryResourceRequest != "" {
if res.Requests == nil {
res.Requests = make(corev1.ResourceList)
}
res.Requests[corev1.ResourceMemory] = r
}
if r, err := resource.ParseQuantity(c.GlobalCPUResourceRequest); err == nil && c.GlobalCPUResourceRequest != "" {
if res.Requests == nil {
res.Requests = make(corev1.ResourceList)
}
res.Requests[corev1.ResourceCPU] = r
}
if r, err := resource.ParseQuantity(c.GlobalMemoryResourceLimit); err == nil && c.GlobalMemoryResourceLimit != "" {
if res.Limits == nil {
res.Requests = make(corev1.ResourceList)
}
res.Requests[corev1.ResourceCPU] = r
}
if r, err := resource.ParseQuantity(c.GlobalCPUResourceLimit); err == nil && c.GlobalCPUResourceLimit != "" {
if res.Limits == nil {
res.Limits = make(corev1.ResourceList)
}
res.Limits[corev1.ResourceCPU] = r
}
return res
}

// GetGlobalRepository is a shortcut for building an S3 string "s3:<endpoint>/<bucket>"
func GetGlobalRepository() string {
return fmt.Sprintf("s3:%s/%s", Config.GlobalS3Endpoint, Config.GlobalS3Bucket)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,28 @@ spec:
type: object
keepJobs:
type: integer
resources:
description: Resources describes the compute resource requirements (cpu, memory, etc.)
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
restoreFilter:
type: string
restoreMethod:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,28 @@ spec:
promURL:
description: PromURL sets a prometheus push URL where the backup container send metrics to
type: string
resources:
description: Resources describes the compute resource requirements (cpu, memory, etc.)
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
statsURL:
description: StatsURL sets an arbitrary URL where the wrestic container posts metrics and information about the snapshots to. This is in addition to the prometheus pushgateway.
type: string
Expand Down
Loading