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 aware API spec validation #9378

Merged
merged 31 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
690f17d
operator: Add zone awareness spec to LokiStack
Apr 27, 2023
b52e936
Merge branch 'main' of github.com:grafana/loki into zone_aware_spec
Apr 27, 2023
4043b77
add api docs
Apr 27, 2023
7510503
changelog
Apr 27, 2023
06fe96b
lint
Apr 27, 2023
90af9bf
Merge branch 'main' of github.com:grafana/loki into zone_aware_spec
Apr 27, 2023
ccfc5f4
lint
Apr 28, 2023
b01cf07
Merge branch 'main' of github.com:grafana/loki into zone_aware_spec
Apr 28, 2023
ddfcec7
Merge branch 'main' of github.com:grafana/loki into zone_aware_spec_val
May 3, 2023
d788c98
fix test
May 3, 2023
8d72ce1
changelog
May 3, 2023
a27ba96
move client
May 4, 2023
dda3bf4
Update loki-build-image with go1.20.4 (#9372)
May 3, 2023
3e50897
Adding CHANGELOG entry missed in #9370 (#9376)
May 3, 2023
9fd5cd9
Update docs 2.8.2 (#9379)
salvacorts May 3, 2023
5843fc4
Add default PodAntiAffinity to Query-Frontend (#9343)
JoaoBraveCoding May 3, 2023
7768ee8
[CI/CD] Update yaml file `./production/helm/loki/Chart.yaml` (+1 othe…
grafanabot May 3, 2023
dbab2de
[CI/CD] Update yaml file `./production/helm/loki/values.yaml` (+1 oth…
grafanabot May 3, 2023
e66fac7
Add missing release notes for 2.8.2 (#9389)
salvacorts May 3, 2023
dec4e82
operator: Add support for custom tenant topology in rules (#9366)
periklis May 3, 2023
287d16e
Update _index.md (#9331)
MattiasSegerdahl May 3, 2023
53dadd3
Update docs to make file rotation support clearer (#9391)
slim-bean May 4, 2023
e12dea6
Loki microservices Tanka: fix error during manifest generation (#9362)
irizzant May 4, 2023
39f580f
Promtail: Break on iterate journal failure (#9155)
farodin91 May 4, 2023
0cd3889
Update retention doc tsdb support of compactor (#9397)
alainpham May 4, 2023
cd5ddde
Merge branch 'main' of github.com:grafana/loki into zone_aware_spec_val
May 4, 2023
83f1fdb
Merge branch 'main' of github.com:grafana/loki into zone_aware_spec_val
May 9, 2023
61ee40e
remove replication to zones validation
May 10, 2023
ce576b3
comment
May 11, 2023
5f1be23
Merge branch 'main' of github.com:grafana/loki into zone_aware_spec_val
May 11, 2023
a8b29c1
Merge branch 'main' of github.com:grafana/loki into zone_aware_spec_val
May 17, 2023
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
1 change: 1 addition & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Main

- [9378](https://github.com/grafana/loki/pull/9378) **aminesnow**: Add zone aware API spec validation
- [9408](https://github.com/grafana/loki/pull/9408) **JoaoBraveCoding**: Add PodAntiAffinity overwrites per component
- [9429](https://github.com/grafana/loki/pull/9429) **aminesnow**: Add default TopologySpreadContraints to Gateway
- [9418](https://github.com/grafana/loki/pull/9418) **JoaoBraveCoding**: Add default TopologySpreadContaints to Querier
Expand Down
1 change: 1 addition & 0 deletions operator/apis/loki/v1/lokistack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ type ReplicationSpec struct {
Factor int32 `json:"factor,omitempty"`

// Zones defines an array of ZoneSpec that the scheduler will try to satisfy.
// IMPORTANT: Make sure that the replication factor defined is less than or equal to the number of available zones.
//
// +optional
// +kubebuilder:validation:Optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: docker.io/grafana/loki-operator:main-ac1c1fd
createdAt: "2023-05-09T09:43:36Z"
createdAt: "2023-05-11T08:04:29Z"
description: The Community Loki Operator provides Kubernetes native deployment
and management of Loki and related logging components.
operators.operatorframework.io/builder: operator-sdk-unknown
Expand Down Expand Up @@ -446,8 +446,9 @@ spec:
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.
- description: 'Zones defines an array of ZoneSpec that the scheduler will try
to satisfy. IMPORTANT: Make sure that the replication factor defined is
less than or equal to the number of available zones.'
displayName: Zones Spec
path: replication.zones
- description: MaxSkew describes the maximum degree to which Pods can be unevenly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,10 @@ spec:
minimum: 1
type: integer
zones:
description: Zones defines an array of ZoneSpec that the scheduler
will try to satisfy.
description: 'Zones defines an array of ZoneSpec that the scheduler
will try to satisfy. IMPORTANT: Make sure that the replication
factor defined is less than or equal to the number of available
zones.'
items:
description: ZoneSpec defines the spec to support zone-aware
component deployments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: docker.io/grafana/loki-operator:main-ac1c1fd
createdAt: "2023-05-09T09:44:16Z"
createdAt: "2023-05-11T08:04:26Z"
description: The Community Loki Operator provides Kubernetes native deployment
and management of Loki and related logging components.
operators.operatorframework.io/builder: operator-sdk-unknown
Expand Down Expand Up @@ -446,8 +446,9 @@ spec:
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.
- description: 'Zones defines an array of ZoneSpec that the scheduler will try
to satisfy. IMPORTANT: Make sure that the replication factor defined is
less than or equal to the number of available zones.'
displayName: Zones Spec
path: replication.zones
- description: MaxSkew describes the maximum degree to which Pods can be unevenly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,10 @@ spec:
minimum: 1
type: integer
zones:
description: Zones defines an array of ZoneSpec that the scheduler
will try to satisfy.
description: 'Zones defines an array of ZoneSpec that the scheduler
will try to satisfy. IMPORTANT: Make sure that the replication
factor defined is less than or equal to the number of available
zones.'
items:
description: ZoneSpec defines the spec to support zone-aware
component deployments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: quay.io/openshift-logging/loki-operator:v0.1.0
createdAt: "2023-05-09T09:43:37Z"
createdAt: "2023-05-11T08:04:32Z"
description: |
The Loki Operator for OCP provides a means for configuring and managing a Loki stack for cluster logging.
## Prerequisites and Requirements
Expand Down Expand Up @@ -459,8 +459,9 @@ spec:
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.
- description: 'Zones defines an array of ZoneSpec that the scheduler will try
to satisfy. IMPORTANT: Make sure that the replication factor defined is
less than or equal to the number of available zones.'
displayName: Zones Spec
path: replication.zones
- description: MaxSkew describes the maximum degree to which Pods can be unevenly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,10 @@ spec:
minimum: 1
type: integer
zones:
description: Zones defines an array of ZoneSpec that the scheduler
will try to satisfy.
description: 'Zones defines an array of ZoneSpec that the scheduler
will try to satisfy. IMPORTANT: Make sure that the replication
factor defined is less than or equal to the number of available
zones.'
items:
description: ZoneSpec defines the spec to support zone-aware
component deployments.
Expand Down
6 changes: 4 additions & 2 deletions operator/config/crd/bases/loki.grafana.com_lokistacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ spec:
minimum: 1
type: integer
zones:
description: Zones defines an array of ZoneSpec that the scheduler
will try to satisfy.
description: 'Zones defines an array of ZoneSpec that the scheduler
will try to satisfy. IMPORTANT: Make sure that the replication
factor defined is less than or equal to the number of available
zones.'
items:
description: ZoneSpec defines the spec to support zone-aware
component deployments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ spec:
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.
- description: 'Zones defines an array of ZoneSpec that the scheduler will try
to satisfy. IMPORTANT: Make sure that the replication factor defined is
less than or equal to the number of available zones.'
displayName: Zones Spec
path: replication.zones
- description: MaxSkew describes the maximum degree to which Pods can be unevenly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ spec:
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.
- description: 'Zones defines an array of ZoneSpec that the scheduler will try
to satisfy. IMPORTANT: Make sure that the replication factor defined is
less than or equal to the number of available zones.'
displayName: Zones Spec
path: replication.zones
- description: MaxSkew describes the maximum degree to which Pods can be unevenly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ spec:
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.
- description: 'Zones defines an array of ZoneSpec that the scheduler will try
to satisfy. IMPORTANT: Make sure that the replication factor defined is
less than or equal to the number of available zones.'
displayName: Zones Spec
path: replication.zones
- description: MaxSkew describes the maximum degree to which Pods can be unevenly
Expand Down
26 changes: 26 additions & 0 deletions operator/internal/validation/lokistack.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (v *LokiStackValidator) validate(ctx context.Context, obj runtime.Object) e
allErrs = append(allErrs, errors...)
}

errors = v.validateReplicationSpec(ctx, stack.Spec)
if len(errors) != 0 {
allErrs = append(allErrs, errors...)
}

if v.ExtendedValidator != nil {
allErrs = append(allErrs, v.ExtendedValidator(ctx, stack)...)
}
Expand All @@ -83,6 +88,27 @@ func (v *LokiStackValidator) validate(ctx context.Context, obj runtime.Object) e
)
}

func (v LokiStackValidator) validateReplicationSpec(ctx context.Context, stack lokiv1.LokiStackSpec) field.ErrorList {
if stack.Replication == nil {
return nil
}

var allErrs field.ErrorList

// nolint:staticcheck
if stack.Replication != nil && stack.ReplicationFactor > 0 {
allErrs = append(allErrs, field.Invalid(
field.NewPath("spec", "replicationFactor"),
stack.ReplicationFactor,
lokiv1.ErrReplicationSpecConflict.Error(),
))

return allErrs
}

return nil
}

// ValidateSchemas ensures that the schemas are in a valid format
func ValidateSchemas(v *lokiv1.ObjectStorageSpec, utcTime time.Time, status lokiv1.LokiStackStorageStatus) field.ErrorList {
var allErrs field.ErrorList
Expand Down
64 changes: 64 additions & 0 deletions operator/internal/validation/lokistack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,70 @@ var ltt = []struct {
},
),
},
{
desc: "valid replication zones",
spec: lokiv1.LokiStack{
Spec: lokiv1.LokiStackSpec{
Storage: lokiv1.ObjectStorageSpec{
Schemas: []lokiv1.ObjectStorageSchema{
{
Version: lokiv1.ObjectStorageSchemaV12,
EffectiveDate: "2020-10-11",
},
},
},
Replication: &lokiv1.ReplicationSpec{
Zones: []lokiv1.ZoneSpec{
{
TopologyKey: "zone",
},
},
Factor: 1,
},
},
},
},
{
desc: "using both replication and replicationFactor",
spec: lokiv1.LokiStack{
Spec: lokiv1.LokiStackSpec{
Storage: lokiv1.ObjectStorageSpec{
Schemas: []lokiv1.ObjectStorageSchema{
{
Version: lokiv1.ObjectStorageSchemaV12,
EffectiveDate: "2020-10-11",
},
},
},
ReplicationFactor: 2,
Replication: &lokiv1.ReplicationSpec{
Zones: []lokiv1.ZoneSpec{
{
TopologyKey: "zone",
},
{
TopologyKey: "region",
},
{
TopologyKey: "planet",
},
},
Factor: 1,
},
},
},
err: apierrors.NewInvalid(
schema.GroupKind{Group: "loki.grafana.com", Kind: "LokiStack"},
"testing-stack",
field.ErrorList{
field.Invalid(
field.NewPath("spec", "replicationFactor"),
2,
lokiv1.ErrReplicationSpecConflict.Error(),
),
},
),
},
}

func TestLokiStackValidationWebhook_ValidateCreate(t *testing.T) {
Expand Down