-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
lokistack_types.go
1389 lines (1213 loc) · 52.3 KB
/
lokistack_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package v1beta1
import (
v1 "github.com/grafana/loki/operator/apis/loki/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// ManagementStateType defines the type for CR management states.
//
// +kubebuilder:validation:Enum=Managed;Unmanaged
type ManagementStateType string
const (
// ManagementStateManaged when the LokiStack custom resource should be
// reconciled by the operator.
ManagementStateManaged ManagementStateType = "Managed"
// ManagementStateUnmanaged when the LokiStack custom resource should not be
// reconciled by the operator.
ManagementStateUnmanaged ManagementStateType = "Unmanaged"
)
// LokiStackSizeType declares the type for loki cluster scale outs.
//
// +kubebuilder:validation:Enum="1x.extra-small";"1x.small";"1x.medium"
type LokiStackSizeType string
const (
// SizeOneXExtraSmall defines the size of a single Loki deployment
// with extra small resources/limits requirements and without HA support.
// This size is ultimately dedicated for development and demo purposes.
// DO NOT USE THIS IN PRODUCTION!
//
// FIXME: Add clear description of ingestion/query performance expectations.
SizeOneXExtraSmall LokiStackSizeType = "1x.extra-small"
// SizeOneXSmall defines the size of a single Loki deployment
// with small resources/limits requirements and HA support for all
// Loki components. This size is dedicated for setup **without** the
// requirement for single replication factor and auto-compaction.
//
// FIXME: Add clear description of ingestion/query performance expectations.
SizeOneXSmall LokiStackSizeType = "1x.small"
// SizeOneXMedium defines the size of a single Loki deployment
// with small resources/limits requirements and HA support for all
// Loki components. This size is dedicated for setup **with** the
// requirement for single replication factor and auto-compaction.
//
// FIXME: Add clear description of ingestion/query performance expectations.
SizeOneXMedium LokiStackSizeType = "1x.medium"
)
// SubjectKind is a kind of LokiStack Gateway RBAC subject.
//
// +kubebuilder:validation:Enum=user;group
type SubjectKind string
const (
// User represents a subject that is a user.
User SubjectKind = "user"
// Group represents a subject that is a group.
Group SubjectKind = "group"
)
// Subject represents a subject that has been bound to a role.
type Subject struct {
Name string `json:"name"`
Kind SubjectKind `json:"kind"`
}
// RoleBindingsSpec binds a set of roles to a set of subjects.
type RoleBindingsSpec struct {
Name string `json:"name"`
Subjects []Subject `json:"subjects"`
Roles []string `json:"roles"`
}
// PermissionType is a LokiStack Gateway RBAC permission.
//
// +kubebuilder:validation:Enum=read;write
type PermissionType string
const (
// Write gives access to write data to a tenant.
Write PermissionType = "write"
// Read gives access to read data from a tenant.
Read PermissionType = "read"
)
// RoleSpec describes a set of permissions to interact with a tenant.
type RoleSpec struct {
Name string `json:"name"`
Resources []string `json:"resources"`
Tenants []string `json:"tenants"`
Permissions []PermissionType `json:"permissions"`
}
// OPASpec defines the opa configuration spec for lokiStack Gateway component.
type OPASpec struct {
// URL defines the third-party endpoint for authorization.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="OpenPolicyAgent URL"
URL string `json:"url"`
}
// AuthorizationSpec defines the opa, role bindings and roles
// configuration per tenant for lokiStack Gateway component.
type AuthorizationSpec struct {
// OPA defines the spec for the third-party endpoint for tenant's authorization.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="OPA Configuration"
OPA *OPASpec `json:"opa"`
// Roles defines a set of permissions to interact with a tenant.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Static Roles"
Roles []RoleSpec `json:"roles"`
// RoleBindings defines configuration to bind a set of roles to a set of subjects.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Static Role Bindings"
RoleBindings []RoleBindingsSpec `json:"roleBindings"`
}
// TenantSecretSpec is a secret reference containing name only
// for a secret living in the same namespace as the LokiStack custom resource.
type TenantSecretSpec struct {
// Name of a secret in the namespace configured for tenant secrets.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:io.kubernetes:Secret",displayName="Tenant Secret Name"
Name string `json:"name"`
}
// OIDCSpec defines the oidc configuration spec for lokiStack Gateway component.
type OIDCSpec struct {
// Secret defines the spec for the clientID, clientSecret and issuerCAPath for tenant's authentication.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Tenant Secret"
Secret *TenantSecretSpec `json:"secret"`
// IssuerURL defines the URL for issuer.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Issuer URL"
IssuerURL string `json:"issuerURL"`
// RedirectURL defines the URL for redirect.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Redirect URL"
RedirectURL string `json:"redirectURL,omitempty"`
// Group claim field from ID Token
//
// +optional
// +kubebuilder:validation:Optional
GroupClaim string `json:"groupClaim,omitempty"`
// User claim field from ID Token
//
// +optional
// +kubebuilder:validation:Optional
UsernameClaim string `json:"usernameClaim,omitempty"`
}
// AuthenticationSpec defines the oidc configuration per tenant for lokiStack Gateway component.
type AuthenticationSpec struct {
// TenantName defines the name of the tenant.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Tenant Name"
TenantName string `json:"tenantName"`
// TenantID defines the id of the tenant.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Tenant ID"
TenantID string `json:"tenantId"`
// OIDC defines the spec for the OIDC tenant's authentication.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="OIDC Configuration"
OIDC *OIDCSpec `json:"oidc"`
}
// ModeType is the authentication/authorization mode in which LokiStack Gateway will be configured.
//
// +kubebuilder:validation:Enum=static;dynamic;openshift-logging
type ModeType string
const (
// Static mode asserts the Authorization Spec's Roles and RoleBindings
// using an in-process OpenPolicyAgent Rego authorizer.
Static ModeType = "static"
// Dynamic mode delegates the authorization to a third-party OPA-compatible endpoint.
Dynamic ModeType = "dynamic"
// OpenshiftLogging mode provides fully automatic OpenShift in-cluster authentication and authorization support.
OpenshiftLogging ModeType = "openshift-logging"
)
// TenantsSpec defines the mode, authentication and authorization
// configuration of the lokiStack gateway component.
type TenantsSpec struct {
// Mode defines the mode in which lokistack-gateway component will be configured.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:default:=openshift-logging
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:select:static","urn:alm:descriptor:com.tectonic.ui:select:dynamic","urn:alm:descriptor:com.tectonic.ui:select:openshift-logging"},displayName="Mode"
Mode ModeType `json:"mode"`
// Authentication defines the lokistack-gateway component authentication configuration spec per tenant.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Authentication"
Authentication []AuthenticationSpec `json:"authentication,omitempty"`
// Authorization defines the lokistack-gateway component authorization configuration spec per tenant.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Authorization"
Authorization *AuthorizationSpec `json:"authorization,omitempty"`
}
// LokiComponentSpec defines the requirements to configure scheduling
// of each loki component individually.
type LokiComponentSpec struct {
// Replicas defines the number of replica pods of the component.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:hidden"
Replicas int32 `json:"replicas,omitempty"`
// NodeSelector defines the labels required by a node to schedule
// the component onto it.
//
// +optional
// +kubebuilder:validation:Optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Tolerations defines the tolerations required by a node to schedule
// the component onto it.
//
// +optional
// +kubebuilder:validation:Optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
}
// LokiTemplateSpec defines the template of all requirements to configure
// scheduling of all Loki components to be deployed.
type LokiTemplateSpec struct {
// Compactor defines the compaction component spec.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Compactor pods"
Compactor *LokiComponentSpec `json:"compactor,omitempty"`
// Distributor defines the distributor component spec.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Distributor pods"
Distributor *LokiComponentSpec `json:"distributor,omitempty"`
// Ingester defines the ingester component spec.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Ingester pods"
Ingester *LokiComponentSpec `json:"ingester,omitempty"`
// Querier defines the querier component spec.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Querier pods"
Querier *LokiComponentSpec `json:"querier,omitempty"`
// QueryFrontend defines the query frontend component spec.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Query Frontend pods"
QueryFrontend *LokiComponentSpec `json:"queryFrontend,omitempty"`
// Gateway defines the lokistack gateway component spec.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Gateway pods"
Gateway *LokiComponentSpec `json:"gateway,omitempty"`
// IndexGateway defines the index gateway component spec.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Index Gateway pods"
IndexGateway *LokiComponentSpec `json:"indexGateway,omitempty"`
// Ruler defines the ruler component spec.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Ruler pods"
Ruler *LokiComponentSpec `json:"ruler,omitempty"`
}
// ObjectStorageTLSSpec is the TLS configuration for reaching the object storage endpoint.
type ObjectStorageTLSSpec struct {
// CA is the name of a ConfigMap containing a CA certificate.
// It needs to be in the same namespace as the LokiStack custom resource.
//
// +optional
// +kubebuilder:validation:optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:io.kubernetes:ConfigMap",displayName="CA ConfigMap Name"
CA string `json:"caName,omitempty"`
}
// ObjectStorageSecretType defines the type of storage which can be used with the Loki cluster.
//
// +kubebuilder:validation:Enum=azure;gcs;s3;swift
type ObjectStorageSecretType string
const (
// ObjectStorageSecretAzure when using Azure for Loki storage
ObjectStorageSecretAzure ObjectStorageSecretType = "azure"
// ObjectStorageSecretGCS when using GCS for Loki storage
ObjectStorageSecretGCS ObjectStorageSecretType = "gcs"
// ObjectStorageSecretS3 when using S3 for Loki storage
ObjectStorageSecretS3 ObjectStorageSecretType = "s3"
// ObjectStorageSecretSwift when using Swift for Loki storage
ObjectStorageSecretSwift ObjectStorageSecretType = "swift"
)
// ObjectStorageSecretSpec is a secret reference containing name only, no namespace.
type ObjectStorageSecretSpec struct {
// Type of object storage that should be used
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:select:azure","urn:alm:descriptor:com.tectonic.ui:select:gcs","urn:alm:descriptor:com.tectonic.ui:select:s3","urn:alm:descriptor:com.tectonic.ui:select:swift"},displayName="Object Storage Secret Type"
Type ObjectStorageSecretType `json:"type"`
// Name of a secret in the namespace configured for object storage secrets.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:io.kubernetes:Secret",displayName="Object Storage Secret Name"
Name string `json:"name"`
}
// ObjectStorageSchemaVersion defines the storage schema version which will be
// used with the Loki cluster.
//
// +kubebuilder:validation:Enum=v11;v12
type ObjectStorageSchemaVersion string
const (
// ObjectStorageSchemaV11 when using v11 for the storage schema
ObjectStorageSchemaV11 ObjectStorageSchemaVersion = "v11"
// ObjectStorageSchemaV12 when using v12 for the storage schema
ObjectStorageSchemaV12 ObjectStorageSchemaVersion = "v12"
)
// ObjectStorageSchema defines the requirements needed to configure a new
// storage schema.
type ObjectStorageSchema struct {
// Version for writing and reading logs.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:select:v11","urn:alm:descriptor:com.tectonic.ui:select:v12"},displayName="Version"
Version ObjectStorageSchemaVersion `json:"version"`
// EffectiveDate is the date in UTC that the schema will be applied on.
// To ensure readibility of logs, this date should be before the current
// date in UTC.
//
// +required
// +kubebuilder:validation:Required
EffectiveDate StorageSchemaEffectiveDate `json:"effectiveDate"`
}
// ObjectStorageSpec defines the requirements to access the object
// storage bucket to persist logs by the ingester component.
type ObjectStorageSpec struct {
// Schemas for reading and writing logs.
//
// +optional
// +kubebuilder:validation:Optional
// +kubebuilder:validation:MinItems:=1
// +kubebuilder:default:={{version:v11,effectiveDate:"2020-10-11"}}
Schemas []ObjectStorageSchema `json:"schemas"`
// Secret for object storage authentication.
// Name of a secret in the same namespace as the LokiStack custom resource.
//
// +required
// +kubebuilder:validation:Required
Secret ObjectStorageSecretSpec `json:"secret"`
// TLS configuration for reaching the object storage endpoint.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="TLS Config"
TLS *ObjectStorageTLSSpec `json:"tls,omitempty"`
}
// QueryLimitSpec defines the limits applies at the query path.
type QueryLimitSpec struct {
// MaxEntriesLimitsPerQuery defines the maximum number of log entries
// that will be returned for a query.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Entries Limit per Query"
MaxEntriesLimitPerQuery int32 `json:"maxEntriesLimitPerQuery,omitempty"`
// MaxChunksPerQuery defines the maximum number of chunks
// that can be fetched by a single query.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Chunk per Query"
MaxChunksPerQuery int32 `json:"maxChunksPerQuery,omitempty"`
// MaxQuerySeries defines the maximum of unique series
// that is returned by a metric query.
//
// + optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Query Series"
MaxQuerySeries int32 `json:"maxQuerySeries,omitempty"`
}
// IngestionLimitSpec defines the limits applied at the ingestion path.
type IngestionLimitSpec struct {
// IngestionRate defines the sample size per second. Units MB.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Ingestion Rate (in MB)"
IngestionRate int32 `json:"ingestionRate,omitempty"`
// IngestionBurstSize defines the local rate-limited sample size per
// distributor replica. It should be set to the set at least to the
// maximum logs size expected in a single push request.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Ingestion Burst Size (in MB)"
IngestionBurstSize int32 `json:"ingestionBurstSize,omitempty"`
// MaxLabelNameLength defines the maximum number of characters allowed
// for label keys in log streams.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Label Name Length"
MaxLabelNameLength int32 `json:"maxLabelNameLength,omitempty"`
// MaxLabelValueLength defines the maximum number of characters allowed
// for label values in log streams.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Label Value Length"
MaxLabelValueLength int32 `json:"maxLabelValueLength,omitempty"`
// MaxLabelNamesPerSeries defines the maximum number of label names per series
// in each log stream.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Labels Names per Series"
MaxLabelNamesPerSeries int32 `json:"maxLabelNamesPerSeries,omitempty"`
// MaxGlobalStreamsPerTenant defines the maximum number of active streams
// per tenant, across the cluster.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Global Streams per Tenant"
MaxGlobalStreamsPerTenant int32 `json:"maxGlobalStreamsPerTenant,omitempty"`
// MaxLineSize defines the maximum line size on ingestion path. Units in Bytes.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Max Line Size"
MaxLineSize int32 `json:"maxLineSize,omitempty"`
}
// LimitsTemplateSpec defines the limits and overrides applied per-tenant.
type LimitsTemplateSpec struct {
// IngestionLimits defines the limits applied on ingested log streams.
//
// +optional
// +kubebuilder:validation:Optional
IngestionLimits *IngestionLimitSpec `json:"ingestion,omitempty"`
// QueryLimits defines the limit applied on querying log streams.
//
// +optional
// +kubebuilder:validation:Optional
QueryLimits *QueryLimitSpec `json:"queries,omitempty"`
}
// LimitsSpec defines the spec for limits applied at ingestion or query
// path across the cluster or per tenant.
// It also defines the per-tenant configuration overrides.
type LimitsSpec struct {
// Global defines the limits applied globally across the cluster.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Global Limits"
Global *LimitsTemplateSpec `json:"global,omitempty"`
// Tenants defines the limits and overrides applied per tenant.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Limits per Tenant"
Tenants map[string]LimitsTemplateSpec `json:"tenants,omitempty"`
}
// RulesSpec deifnes the spec for the ruler component.
type RulesSpec struct {
// Enabled defines a flag to enable/disable the ruler component
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch",displayName="Enable"
Enabled bool `json:"enabled"`
// A selector to select which LokiRules to mount for loading alerting/recording
// rules from.
//
// +optional
// +kubebuilder:validation:optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Selector"
Selector *metav1.LabelSelector `json:"selector,omitempty"`
// Namespaces to be selected for PrometheusRules discovery. If unspecified, only
// the same namespace as the LokiStack object is in is used.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Namespace Selector"
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
}
// LokiStackSpec defines the desired state of LokiStack
type LokiStackSpec struct {
// ManagementState defines if the CR should be managed by the operator or not.
// Default is managed.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:default:=Managed
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:select:Managed","urn:alm:descriptor:com.tectonic.ui:select:Unmanaged"},displayName="Management State"
ManagementState ManagementStateType `json:"managementState,omitempty"`
// Size defines one of the support Loki deployment scale out sizes.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:select:1x.extra-small","urn:alm:descriptor:com.tectonic.ui:select:1x.small","urn:alm:descriptor:com.tectonic.ui:select:1x.medium"},displayName="LokiStack Size"
Size LokiStackSizeType `json:"size"`
// Storage defines the spec for the object storage endpoint to store logs.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Object Storage"
Storage ObjectStorageSpec `json:"storage"`
// Storage class name defines the storage class for ingester/querier PVCs.
//
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:io.kubernetes:StorageClass",displayName="Storage Class Name"
StorageClassName string `json:"storageClassName"`
// ReplicationFactor defines the policy for log stream replication.
//
// +optional
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum:=1
// +kubebuilder:default:=1
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:number",displayName="Replication Factor"
ReplicationFactor int32 `json:"replicationFactor"`
// Rules defines the spec for the ruler component
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:advanced",displayName="Rules"
Rules *RulesSpec `json:"rules,omitempty"`
// Limits defines the per-tenant limits to be applied to log stream processing and the per-tenant the config overrides.
//
// +optional
// +kubebuilder:validation:Optional
// +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
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:advanced",displayName="Node Placement"
Template *LokiTemplateSpec `json:"template,omitempty"`
// Tenants defines the per-tenant authentication and authorization spec for the lokistack-gateway component.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Tenants Configuration"
Tenants *TenantsSpec `json:"tenants,omitempty"`
}
// LokiStackConditionType deifnes the type of condition types of a Loki deployment.
type LokiStackConditionType string
const (
// ConditionReady defines the condition that all components in the Loki deployment are ready.
ConditionReady LokiStackConditionType = "Ready"
// ConditionPending defines the condition that some or all components are in pending state.
ConditionPending LokiStackConditionType = "Pending"
// ConditionFailed defines the condition that components in the Loki deployment failed to roll out.
ConditionFailed LokiStackConditionType = "Failed"
// ConditionDegraded defines the condition that some or all components in the Loki deployment
// are degraded or the cluster cannot connect to object storage.
ConditionDegraded LokiStackConditionType = "Degraded"
)
// LokiStackConditionReason defines the type for valid reasons of a Loki deployment conditions.
type LokiStackConditionReason string
const (
// ReasonFailedComponents when all/some LokiStack components fail to roll out.
ReasonFailedComponents LokiStackConditionReason = "FailedComponents"
// ReasonPendingComponents when all/some LokiStack components pending dependencies
ReasonPendingComponents LokiStackConditionReason = "PendingComponents"
// ReasonReadyComponents when all LokiStack components are ready to serve traffic.
ReasonReadyComponents LokiStackConditionReason = "ReadyComponents"
// ReasonMissingObjectStorageSecret when the required secret to store logs to object
// storage is missing.
ReasonMissingObjectStorageSecret LokiStackConditionReason = "MissingObjectStorageSecret"
// ReasonInvalidObjectStorageSecret when the format of the secret is invalid.
ReasonInvalidObjectStorageSecret LokiStackConditionReason = "InvalidObjectStorageSecret"
// ReasonInvalidObjectStorageSchema when the spec contains an invalid schema(s).
ReasonInvalidObjectStorageSchema LokiStackConditionReason = "InvalidObjectStorageSchema"
// ReasonMissingObjectStorageCAConfigMap when the required configmap to verify object storage
// certificates is missing.
ReasonMissingObjectStorageCAConfigMap LokiStackConditionReason = "MissingObjectStorageCAConfigMap"
// ReasonInvalidObjectStorageCAConfigMap when the format of the CA configmap is invalid.
ReasonInvalidObjectStorageCAConfigMap LokiStackConditionReason = "InvalidObjectStorageCAConfigMap"
// ReasonMissingRulerSecret when the required secret to authorization remote write connections
// for the ruler is missing.
ReasonMissingRulerSecret LokiStackConditionReason = "MissingRulerSecret"
// ReasonInvalidRulerSecret when the format of the ruler remote write authorization secret is invalid.
ReasonInvalidRulerSecret LokiStackConditionReason = "InvalidRulerSecret"
// ReasonInvalidReplicationConfiguration when the configurated replication factor is not valid
// with the select cluster size.
ReasonInvalidReplicationConfiguration LokiStackConditionReason = "InvalidReplicationConfiguration"
// ReasonMissingGatewayTenantSecret when the required tenant secret
// for authentication is missing.
ReasonMissingGatewayTenantSecret LokiStackConditionReason = "MissingGatewayTenantSecret"
// ReasonInvalidGatewayTenantSecret when the format of the secret is invalid.
ReasonInvalidGatewayTenantSecret LokiStackConditionReason = "InvalidGatewayTenantSecret"
// ReasonInvalidTenantsConfiguration when the tenant configuration provided is invalid.
ReasonInvalidTenantsConfiguration LokiStackConditionReason = "InvalidTenantsConfiguration"
// ReasonMissingGatewayOpenShiftBaseDomain when the reconciler cannot lookup the OpenShift DNS base domain.
ReasonMissingGatewayOpenShiftBaseDomain LokiStackConditionReason = "MissingGatewayOpenShiftBaseDomain"
)
// PodStatusMap defines the type for mapping pod status to pod name.
type PodStatusMap map[corev1.PodPhase][]string
// LokiStackComponentStatus defines the map of per pod status per LokiStack component.
// Each component is represented by a separate map of v1.Phase to a list of pods.
type LokiStackComponentStatus struct {
// Compactor is a map to the pod status of the compactor pod.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses",displayName="Compactor",order=5
Compactor PodStatusMap `json:"compactor,omitempty"`
// Distributor is a map to the per pod status of the distributor deployment
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses",displayName="Distributor",order=1
Distributor PodStatusMap `json:"distributor,omitempty"`
// IndexGateway is a map to the per pod status of the index gateway statefulset
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses",displayName="IndexGateway",order=6
IndexGateway PodStatusMap `json:"indexGateway,omitempty"`
// Ingester is a map to the per pod status of the ingester statefulset
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses",displayName="Ingester",order=2
Ingester PodStatusMap `json:"ingester,omitempty"`
// Querier is a map to the per pod status of the querier deployment
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses",displayName="Querier",order=3
Querier PodStatusMap `json:"querier,omitempty"`
// QueryFrontend is a map to the per pod status of the query frontend deployment
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses",displayName="Query Frontend",order=4
QueryFrontend PodStatusMap `json:"queryFrontend,omitempty"`
// Gateway is a map to the per pod status of the lokistack gateway deployment.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses",displayName="Gateway",order=5
Gateway PodStatusMap `json:"gateway,omitempty"`
// Ruler is a map to the per pod status of the lokistack ruler statefulset.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses",displayName="Ruler",order=6
Ruler PodStatusMap `json:"ruler,omitempty"`
}
// LokiStackStorageStatus defines the observed state of
// the Loki storage configuration.
type LokiStackStorageStatus struct {
// Schemas is a list of schemas which have been applied
// to the LokiStack.
//
// +optional
// +kubebuilder:validation:Optional
Schemas []ObjectStorageSchema `json:"schemas,omitempty"`
}
// LokiStackStatus defines the observed state of LokiStack
type LokiStackStatus struct {
// Components provides summary of all Loki pod status grouped
// per component.
//
// +optional
// +kubebuilder:validation:Optional
Components LokiStackComponentStatus `json:"components,omitempty"`
// Storage provides summary of all changes that have occurred
// to the storage configuration.
//
// +optional
// +kubebuilder:validation:Optional
Storage LokiStackStorageStatus `json:"storage,omitempty"`
// Conditions of the Loki deployment health.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors="urn:alm:descriptor:io.kubernetes.conditions"
Conditions []metav1.Condition `json:"conditions,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:unservedversion
// +kubebuilder:resource:categories=logging
// LokiStack is the Schema for the lokistacks API
//
// +operator-sdk:csv:customresourcedefinitions:displayName="LokiStack",resources={{Deployment,v1},{StatefulSet,v1},{ConfigMap,v1},{Ingress,v1},{Service,v1},{ServiceAccount,v1},{PersistentVolumeClaims,v1},{Route,v1},{ServiceMonitor,v1}}
type LokiStack struct {
Spec LokiStackSpec `json:"spec,omitempty"`
Status LokiStackStatus `json:"status,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
metav1.TypeMeta `json:",inline"`
}
// +kubebuilder:object:root=true
// LokiStackList contains a list of LokiStack
type LokiStackList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []LokiStack `json:"items"`
}
func init() {
SchemeBuilder.Register(&LokiStack{}, &LokiStackList{})
}
func convertStatusV1(src PodStatusMap) v1.PodStatusMap {
if src == nil {
return nil
}
dst := v1.PodStatusMap{}
for k, v := range src {
dst[v1.PodStatus(k)] = v
}
return dst
}
func convertStatusBeta(src v1.PodStatusMap) PodStatusMap {
if src == nil {
return nil
}
dst := PodStatusMap{}
for k, v := range src {
dst[corev1.PodPhase(k)] = v
}
return dst
}
// ConvertTo converts this LokiStack (v1beta1) to the Hub version (v1).
func (src *LokiStack) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1.LokiStack)
dst.ObjectMeta = src.ObjectMeta
dst.Status.Conditions = src.Status.Conditions
dst.Status.Components = v1.LokiStackComponentStatus{
Compactor: convertStatusV1(src.Status.Components.Compactor),
Distributor: convertStatusV1(src.Status.Components.Distributor),
Ingester: convertStatusV1(src.Status.Components.Ingester),
Querier: convertStatusV1(src.Status.Components.Querier),
QueryFrontend: convertStatusV1(src.Status.Components.QueryFrontend),
IndexGateway: convertStatusV1(src.Status.Components.IndexGateway),
Ruler: convertStatusV1(src.Status.Components.Ruler),
Gateway: convertStatusV1(src.Status.Components.Gateway),
}
var statusSchemas []v1.ObjectStorageSchema
for _, s := range src.Status.Storage.Schemas {
statusSchemas = append(statusSchemas, v1.ObjectStorageSchema{
Version: v1.ObjectStorageSchemaVersion(s.Version),
EffectiveDate: v1.StorageSchemaEffectiveDate(s.EffectiveDate),
})
}
dst.Status.Storage = v1.LokiStackStorageStatus{Schemas: statusSchemas}
if src.Spec.ManagementState != "" {
dst.Spec.ManagementState = v1.ManagementStateType(src.Spec.ManagementState)
}
if src.Spec.Size != "" {
dst.Spec.Size = v1.LokiStackSizeType(src.Spec.Size)
}
var storageTLS *v1.ObjectStorageTLSSpec
if src.Spec.Storage.TLS != nil {
storageTLS = &v1.ObjectStorageTLSSpec{
CASpec: v1.CASpec{
CA: src.Spec.Storage.TLS.CA,
},
}
}
var schemas []v1.ObjectStorageSchema
for _, s := range src.Spec.Storage.Schemas {
schemas = append(schemas, v1.ObjectStorageSchema{
EffectiveDate: v1.StorageSchemaEffectiveDate(s.EffectiveDate),
Version: v1.ObjectStorageSchemaVersion(s.Version),
})
}
dst.Spec.Storage = v1.ObjectStorageSpec{
Schemas: schemas,
Secret: v1.ObjectStorageSecretSpec{
Type: v1.ObjectStorageSecretType(src.Spec.Storage.Secret.Type),
Name: src.Spec.Storage.Secret.Name,
},
TLS: storageTLS,
}
if src.Spec.StorageClassName != "" {
dst.Spec.StorageClassName = src.Spec.StorageClassName
}
if src.Spec.ReplicationFactor != 0 {
dst.Spec.ReplicationFactor = src.Spec.ReplicationFactor
}
if src.Spec.Rules != nil {
dst.Spec.Rules = &v1.RulesSpec{
Enabled: src.Spec.Rules.Enabled,
Selector: src.Spec.Rules.Selector,
NamespaceSelector: src.Spec.Rules.NamespaceSelector,
}
}
if src.Spec.Limits != nil {
dst.Spec.Limits = &v1.LimitsSpec{}
if src.Spec.Limits.Global != nil {
dst.Spec.Limits.Global = &v1.LimitsTemplateSpec{}
if src.Spec.Limits.Global.IngestionLimits != nil {
dst.Spec.Limits.Global.IngestionLimits = &v1.IngestionLimitSpec{
IngestionRate: src.Spec.Limits.Global.IngestionLimits.IngestionRate,
IngestionBurstSize: src.Spec.Limits.Global.IngestionLimits.IngestionBurstSize,
MaxLabelNameLength: src.Spec.Limits.Global.IngestionLimits.MaxLabelNameLength,
MaxLabelValueLength: src.Spec.Limits.Global.IngestionLimits.MaxLabelValueLength,
MaxLabelNamesPerSeries: src.Spec.Limits.Global.IngestionLimits.MaxLabelNamesPerSeries,
MaxGlobalStreamsPerTenant: src.Spec.Limits.Global.IngestionLimits.MaxGlobalStreamsPerTenant,
MaxLineSize: src.Spec.Limits.Global.IngestionLimits.MaxLineSize,
}
}
if src.Spec.Limits.Global.QueryLimits != nil {
dst.Spec.Limits.Global.QueryLimits = &v1.QueryLimitSpec{
MaxEntriesLimitPerQuery: src.Spec.Limits.Global.QueryLimits.MaxEntriesLimitPerQuery,
MaxChunksPerQuery: src.Spec.Limits.Global.QueryLimits.MaxChunksPerQuery,
MaxQuerySeries: src.Spec.Limits.Global.QueryLimits.MaxQuerySeries,
}
}
}
if len(src.Spec.Limits.Tenants) > 0 {
dst.Spec.Limits.Tenants = make(map[string]v1.PerTenantLimitsTemplateSpec)
}
for tenant, srcSpec := range src.Spec.Limits.Tenants {
dstSpec := v1.PerTenantLimitsTemplateSpec{}
if srcSpec.IngestionLimits != nil {
dstSpec.IngestionLimits = &v1.IngestionLimitSpec{
IngestionRate: srcSpec.IngestionLimits.IngestionRate,
IngestionBurstSize: srcSpec.IngestionLimits.IngestionBurstSize,
MaxLabelNameLength: srcSpec.IngestionLimits.MaxLabelNameLength,
MaxLabelValueLength: srcSpec.IngestionLimits.MaxLabelValueLength,
MaxLabelNamesPerSeries: srcSpec.IngestionLimits.MaxLabelNamesPerSeries,
MaxGlobalStreamsPerTenant: srcSpec.IngestionLimits.MaxGlobalStreamsPerTenant,
MaxLineSize: srcSpec.IngestionLimits.MaxLineSize,
}
}
if srcSpec.QueryLimits != nil {
dstSpec.QueryLimits = &v1.PerTenantQueryLimitSpec{
QueryLimitSpec: v1.QueryLimitSpec{
MaxEntriesLimitPerQuery: srcSpec.QueryLimits.MaxEntriesLimitPerQuery,
MaxChunksPerQuery: srcSpec.QueryLimits.MaxChunksPerQuery,
MaxQuerySeries: srcSpec.QueryLimits.MaxQuerySeries,
},
}
}
dst.Spec.Limits.Tenants[tenant] = dstSpec
}
}
if src.Spec.Template != nil {
dst.Spec.Template = &v1.LokiTemplateSpec{}
if src.Spec.Template.Compactor != nil {
dst.Spec.Template.Compactor = &v1.LokiComponentSpec{
Replicas: src.Spec.Template.Compactor.Replicas,
NodeSelector: src.Spec.Template.Compactor.NodeSelector,
Tolerations: src.Spec.Template.Compactor.Tolerations,
}
}