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

Support configure resources #48

Merged
merged 2 commits into from
Mar 18, 2021
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
33 changes: 33 additions & 0 deletions api/v1alpha1/observatorium_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ type ThanosReceiveControllerSpec struct {
Image string `json:"image,omitempty"`
// Version describes the version of Thanos receive controller to use.
Version string `json:"version,omitempty"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

type ReceiversSpec struct {
Expand All @@ -112,6 +115,9 @@ type ReceiversSpec struct {
VolumeClaimTemplate VolumeClaimTemplate `json:"volumeClaimTemplate"`
// ReplicationFactor defines the number of copies of every time-series
ReplicationFactor *int32 `json:"replicationFactor,omitempty"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

type StoreSpec struct {
Expand All @@ -124,6 +130,9 @@ type StoreSpec struct {
Shards *int32 `json:"shards,omitempty"`
// Memcached spec for Store
Cache StoreCacheSpec `json:"cache,omitempty"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

// StoreCacheSpec describes configuration for Store Memcached
Expand All @@ -140,6 +149,12 @@ type StoreCacheSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
// Memory limit of Memcached in megabytes.
MemoryLimitMB *int32 `json:"memoryLimitMb,omitempty"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
// Compute Resources required by this container.
// +optional
ExporterResources v1.ResourceRequirements `json:"exporterResources,omitempty"`
}

// Permission is an Observatorium RBAC permission.
Expand Down Expand Up @@ -254,6 +269,9 @@ type APISpec struct {
RBAC APIRBAC `json:"rbac"`
// Tenants is a slice of tenants for the Observatorium API.
Tenants []APITenant `json:"tenants"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

type QuerySpec struct {
Expand All @@ -263,6 +281,9 @@ type QuerySpec struct {
Replicas *int32 `json:"replicas,omitempty"`
// Version of Thanos image to be deployed.
Version string `json:"version,omitempty"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

type RuleConfig struct {
Expand Down Expand Up @@ -290,6 +311,12 @@ type RuleSpec struct {
// ReloaderImage is an image of configmap reloader
// +optional
ReloaderImage string `json:"reloaderImage,omitempty"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
// Compute Resources required by this container.
// +optional
ReloaderResources v1.ResourceRequirements `json:"reloaderResources,omitempty"`
}

type CompactSpec struct {
Expand All @@ -309,6 +336,9 @@ type CompactSpec struct {
RetentionResolution1h string `json:"retentionResolution1h"`
// EnableDownsampling enables downsampling.
EnableDownsampling bool `json:"enableDownsampling,omitempty"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

type VolumeClaimTemplate struct {
Expand All @@ -322,6 +352,9 @@ type QueryFrontendSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
// Version of Query Frontend image to be deployed.
Version string `json:"version,omitempty"`
// Compute Resources required by this container.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

type Hashring struct {
Expand Down
13 changes: 12 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions example/manifests/observatorium.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ spec:
- hashring: default
tenants: []
loki:
image: docker.io/grafana/loki:2.1.0
image: docker.io/grafana/loki:2.0.0
replicas:
compactor: 1
distributor: 1
ingester: 1
querier: 1
query_frontend: 1
version: 2.1.0
version: 2.0.0
volumeClaimTemplate:
spec:
accessModes:
Expand Down
27 changes: 25 additions & 2 deletions jsonnet/obs-operator.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ local operatorObs = obs {
securityContext: if std.objectHas(cr.spec, 'securityContext') then cr.spec.securityContext else obs.thanos.stores.config.securityContext,
} + if std.objectHas(cr.spec, 'store') then cr.spec.store else {},

storeCache+:: {
storeCache+:: (if std.objectHas(cr.spec, 'store') && std.objectHas(cr.spec.store, 'cache') then cr.spec.store.cache else {}) + {
memoryLimitMb: if std.objectHas(cr.spec.store, 'cache') && std.objectHas(cr.spec.store.cache, 'memoryLimitMb') then cr.spec.store.cache.memoryLimitMb else obs.thanos.storeCache.config.memoryLimitMb,
securityContext: if std.objectHas(cr.spec, 'securityContext') then cr.spec.securityContext else obs.thanos.storeCache.config.securityContext,
} + if std.objectHas(cr.spec, 'store') && std.objectHas(cr.spec.store, 'cache') then cr.spec.store.cache else {},
resources+: (
if std.objectHas(cr.spec.store.cache, 'resources') then {
memcached: cr.spec.store.cache.resources
} else {}
) + (
if std.objectHas(cr.spec.store.cache, 'exporterResources') then {
exporter: cr.spec.store.cache.exporterResources
} else {}
),
},

query+:: {
securityContext: if std.objectHas(cr.spec, 'securityContext') then cr.spec.securityContext else obs.thanos.query.config.securityContext,
Expand Down Expand Up @@ -71,6 +80,7 @@ local operatorObs = obs {
image: if std.objectHas(cr.spec, 'api') && std.objectHas(cr.spec.api, 'image') then cr.spec.api.image else obs.api.config.image,
version: if std.objectHas(cr.spec, 'api') && std.objectHas(cr.spec.api, 'version') then cr.spec.api.version else obs.api.config.version,
replicas: if std.objectHas(cr.spec, 'api') && std.objectHas(cr.spec.api, 'replicas') then cr.spec.api.replicas else obs.api.config.replicas,
resources: if std.objectHas(cr.spec.api, 'resources') then cr.spec.api.resources else obs.api.config.resources,
tls: if std.objectHas(cr.spec, 'api') && std.objectHas(cr.spec.api, 'tls') then cr.spec.api.tls else obs.api.config.tls,
rbac: if std.objectHas(cr.spec, 'api') && std.objectHas(cr.spec.api, 'rbac') then cr.spec.api.rbac else obs.api.config.rbac,
tenants: if std.objectHas(cr.spec, 'api') && std.objectHas(cr.spec.api, 'tenants') then { tenants: cr.spec.api.tenants } else obs.api.config.tenants,
Expand Down Expand Up @@ -114,6 +124,19 @@ local operatorObs = obs {
},
},
} else {}
) + (
if (std.objectHas(cr.spec.rule, 'reloaderResources') && (v.kind == 'StatefulSet') && v.metadata.name == obs.config.name + '-thanos-rule') then {
template+: {
spec+:{
containers: [
if c.name == 'configmap-reloader' then c {
resources: cr.spec.rule.reloaderResources,
} else c
for c in super.containers
],
},
},
} else {}
),
}, operatorObs.manifests),
}
Loading