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

operator: Add zone awareness spec to LokiStack #9315

Merged
merged 15 commits into from
May 2, 2023
1 change: 1 addition & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Main

- [9315](https://github.com/grafana/loki/pull/9315) **aminesnow**: Add zone awareness spec to LokiStack
- [9339](https://github.com/grafana/loki/pull/9339) **JoaoBraveCoding**: Add default PodAntiAffinity to Ruler
- [9329](https://github.com/grafana/loki/pull/9329) **JoaoBraveCoding**: Add default PodAntiAffinity to Ingester
- [9262](https://github.com/grafana/loki/pull/9262) **btaani**: Add PodDisruptionBudget to the Ruler
Expand Down
46 changes: 44 additions & 2 deletions operator/apis/loki/v1/lokistack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ type LokiStackSpec struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Cluster Proxy"
Proxy *ClusterProxy `json:"proxy,omitempty"`

// Deprecated: Please use replication.factor instead. This field will be removed in future versions of this CRD.
// ReplicationFactor defines the policy for log stream replication.
//
// +optional
Expand All @@ -774,7 +775,14 @@ type LokiStackSpec struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Replication Factor"
ReplicationFactor int32 `json:"replicationFactor,omitempty"`

// Rules defines the spec for the ruler component
// Replication defines the configuration for Loki data replication.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Replication Spec"
Replication *ReplicationSpec `json:"replication,omitempty"`

// Rules defines the spec for the ruler component.
//
// +optional
// +kubebuilder:validation:Optional
Expand All @@ -788,7 +796,7 @@ type LokiStackSpec struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:advanced",displayName="Rate Limiting"
Limits *LimitsSpec `json:"limits,omitempty"`

// Template defines the resource/limits/tolerations/nodeselectors per component
// Template defines the resource/limits/tolerations/nodeselectors per component.
//
// +optional
// +kubebuilder:validation:Optional
Expand All @@ -803,6 +811,40 @@ type LokiStackSpec struct {
Tenants *TenantsSpec `json:"tenants,omitempty"`
}

type ReplicationSpec struct {
// Factor defines the policy for log stream replication.
//
// +optional
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum:=1
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Replication Factor"
Factor int32 `json:"factor,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only discovered this recently but according to [1] if a field is optional and its type doesn't build in nil then they should be pointers. Now I also know that to not change a project conventions so I'm simply raising the question if this should not be a pointer

[1] https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#optional-vs-required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that for int32, 0 is the nil value, so if the value is 0, it will be omitted, which is the desired result.


// Zones defines an array of ZoneSpec that the scheduler will try to satisfy.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Zones Spec"
Zones []ZoneSpec `json:"zones,omitempty"`
}

// ZoneSpec defines the spec to support zone-aware component deployments.
type ZoneSpec struct {
// MaxSkew describes the maximum degree to which Pods can be unevenly distributed.
//
// +required
// +kubebuilder:default:=1
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Skew"
MaxSkew int `json:"maxSkew"`

// TopologyKey is the key that defines a topology in the Nodes' labels.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Topology Key"
TopologyKey string `json:"topologyKey"`
}

// LokiStackConditionType deifnes the type of condition types of a Loki deployment.
type LokiStackConditionType string

Expand Down
6 changes: 6 additions & 0 deletions operator/apis/loki/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ var (
ErrSchemaRetroactivelyChanged = errors.New("Cannot retroactively change schema")
// ErrHeaderAuthCredentialsConflict when both Credentials and CredentialsFile are used in a header authentication client.
ErrHeaderAuthCredentialsConflict = errors.New("credentials and credentialsFile cannot be used at the same time")
// ErrReplicationZonesNodes when there is an error retrieving nodes with replication zones labels.
ErrReplicationZonesNodes = errors.New("Failed to retrieve nodes for zone replication")
// ErrReplicationFactorToZonesRatio when the replication factor defined is greater than the number of available zones.
ErrReplicationFactorToZonesRatio = errors.New("replication factor is greater than the number of available zones")
// ErrReplicationSpecConflict when both the ReplicationSpec and depricated ReplicationFactor are used.
ErrReplicationSpecConflict = errors.New("replicationSpec and replicationFactor (deprecated) cannot be used at the same time")

// ErrRuleMustMatchNamespace indicates that an expression used in an alerting or recording rule is missing
// matchers for a namespace.
Expand Down
40 changes: 40 additions & 0 deletions operator/apis/loki/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,36 @@ spec:
- description: NoProxy configures the NO_PROXY/no_proxy env variable.
displayName: NoProxy
path: proxy.noProxy
- description: ReplicationFactor defines the policy for log stream replication.
- description: Replication defines the configuration for Loki data replication.
displayName: Replication Spec
path: replication
- description: Factor defines the policy for log stream replication.
displayName: Replication Factor
path: replication.factor
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: Zones defines an array of ZoneSpec that the scheduler will try
to satisfy.
displayName: Zones Spec
path: replication.zones
- description: MaxSkew describes the maximum degree to which Pods can be unevenly
distributed.
displayName: Max Skew
path: replication.zones[0].maxSkew
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: TopologyKey is the key that defines a topology in the Nodes'
labels.
displayName: Topology Key
path: replication.zones[0].topologyKey
- description: 'Deprecated: Please use replication.factor instead. This field
will be removed in future versions of this CRD. ReplicationFactor defines
the policy for log stream replication.'
displayName: Replication Factor
path: replicationFactor
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: Rules defines the spec for the ruler component
- description: Rules defines the spec for the ruler component.
displayName: Rules
path: rules
x-descriptors:
Expand Down Expand Up @@ -514,7 +538,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:io.kubernetes:StorageClass
- description: Template defines the resource/limits/tolerations/nodeselectors
per component
per component.
displayName: Node Placement
path: template
x-descriptors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,45 @@ spec:
description: NoProxy configures the NO_PROXY/no_proxy env variable.
type: string
type: object
replication:
description: Replication defines the configuration for Loki data replication.
properties:
factor:
description: Factor defines the policy for log stream replication.
format: int32
minimum: 1
type: integer
zones:
description: Zones defines an array of ZoneSpec that the scheduler
will try to satisfy.
items:
description: ZoneSpec defines the spec to support zone-aware
component deployments.
properties:
maxSkew:
default: 1
description: MaxSkew describes the maximum degree to which
Pods can be unevenly distributed.
type: integer
topologyKey:
description: TopologyKey is the key that defines a topology
in the Nodes' labels.
type: string
required:
- maxSkew
- topologyKey
type: object
type: array
type: object
replicationFactor:
description: ReplicationFactor defines the policy for log stream replication.
description: 'Deprecated: Please use replication.factor instead. This
field will be removed in future versions of this CRD. ReplicationFactor
defines the policy for log stream replication.'
format: int32
minimum: 1
type: integer
rules:
description: Rules defines the spec for the ruler component
description: Rules defines the spec for the ruler component.
properties:
enabled:
description: Enabled defines a flag to enable/disable the ruler
Expand Down Expand Up @@ -530,7 +562,7 @@ spec:
type: string
template:
description: Template defines the resource/limits/tolerations/nodeselectors
per component
per component.
properties:
compactor:
description: Compactor defines the compaction component spec.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,36 @@ spec:
- description: NoProxy configures the NO_PROXY/no_proxy env variable.
displayName: NoProxy
path: proxy.noProxy
- description: ReplicationFactor defines the policy for log stream replication.
- description: Replication defines the configuration for Loki data replication.
displayName: Replication Spec
path: replication
- description: Factor defines the policy for log stream replication.
displayName: Replication Factor
path: replication.factor
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: Zones defines an array of ZoneSpec that the scheduler will try
to satisfy.
displayName: Zones Spec
path: replication.zones
- description: MaxSkew describes the maximum degree to which Pods can be unevenly
distributed.
displayName: Max Skew
path: replication.zones[0].maxSkew
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: TopologyKey is the key that defines a topology in the Nodes'
labels.
displayName: Topology Key
path: replication.zones[0].topologyKey
- description: 'Deprecated: Please use replication.factor instead. This field
will be removed in future versions of this CRD. ReplicationFactor defines
the policy for log stream replication.'
displayName: Replication Factor
path: replicationFactor
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: Rules defines the spec for the ruler component
- description: Rules defines the spec for the ruler component.
displayName: Rules
path: rules
x-descriptors:
Expand Down Expand Up @@ -514,7 +538,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:io.kubernetes:StorageClass
- description: Template defines the resource/limits/tolerations/nodeselectors
per component
per component.
displayName: Node Placement
path: template
x-descriptors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,45 @@ spec:
description: NoProxy configures the NO_PROXY/no_proxy env variable.
type: string
type: object
replication:
description: Replication defines the configuration for Loki data replication.
properties:
factor:
description: Factor defines the policy for log stream replication.
format: int32
minimum: 1
type: integer
zones:
description: Zones defines an array of ZoneSpec that the scheduler
will try to satisfy.
items:
description: ZoneSpec defines the spec to support zone-aware
component deployments.
properties:
maxSkew:
default: 1
description: MaxSkew describes the maximum degree to which
Pods can be unevenly distributed.
type: integer
topologyKey:
description: TopologyKey is the key that defines a topology
in the Nodes' labels.
type: string
required:
- maxSkew
- topologyKey
type: object
type: array
type: object
replicationFactor:
description: ReplicationFactor defines the policy for log stream replication.
description: 'Deprecated: Please use replication.factor instead. This
field will be removed in future versions of this CRD. ReplicationFactor
defines the policy for log stream replication.'
format: int32
minimum: 1
type: integer
rules:
description: Rules defines the spec for the ruler component
description: Rules defines the spec for the ruler component.
properties:
enabled:
description: Enabled defines a flag to enable/disable the ruler
Expand Down Expand Up @@ -530,7 +562,7 @@ spec:
type: string
template:
description: Template defines the resource/limits/tolerations/nodeselectors
per component
per component.
properties:
compactor:
description: Compactor defines the compaction component spec.
Expand Down
Loading