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

Add support for additional storage backends in operator #5432

Merged
merged 5 commits into from
Feb 24, 2022
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
1 change: 1 addition & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Main

- [4975](https://github.com/grafana/loki/pull/4975) **periklis**: Provide saner default for loki-operator managed chunk_target_size
- [4974](https://github.com/grafana/loki/pull/5432) **Red-GV**: Provide storage configuration for Azure, GCS, and Swift through common_config
28 changes: 27 additions & 1 deletion operator/api/v1beta1/lokistack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,39 @@ type LokiTemplateSpec struct {
IndexGateway *LokiComponentSpec `json:"indexGateway,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"
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:io.kubernetes:Secret",displayName="Object Storage Secret Name"
Name string `json:"name"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,18 @@ spec:
path: storage
- description: Name of a secret in the namespace configured for object storage
secrets.
displayName: Object Storage Secret
displayName: Object Storage Secret Name
path: storage.secret.name
x-descriptors:
- urn:alm:descriptor:io.kubernetes:Secret
- description: Type of object storage that should be used
displayName: Object Storage Secret Type
path: storage.secret.type
x-descriptors:
- 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
- description: Storage class name defines the storage class for ingester/querier
PVCs.
displayName: Storage Class Name
Expand Down
9 changes: 9 additions & 0 deletions operator/bundle/manifests/loki.grafana.com_lokistacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,17 @@ spec:
description: Name of a secret in the namespace configured
for object storage secrets.
type: string
type:
description: Type of object storage that should be used
enum:
- azure
- gcs
- s3
- swift
type: string
required:
- name
- type
type: object
required:
- secret
Expand Down
33 changes: 18 additions & 15 deletions operator/cmd/loki-broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ViaQ/logerr/log"
"github.com/grafana/loki/operator/api/v1beta1"
"github.com/grafana/loki/operator/internal/manifests"
"github.com/grafana/loki/operator/internal/manifests/storage"
"sigs.k8s.io/yaml"
)

Expand All @@ -21,7 +22,7 @@ type config struct {
Image string

featureFlags manifests.FeatureFlags
objectStorage manifests.ObjectStorage
objectStorage storage.Options

crFilepath string
writeToDir string
Expand All @@ -39,12 +40,14 @@ func (c *config) registerFlags(f *flag.FlagSet) {
f.BoolVar(&c.featureFlags.EnableTLSServiceMonitorConfig, "with-tls-service-monitors", false, "Enable TLS endpoint for service monitors.")
f.BoolVar(&c.featureFlags.EnableGateway, "with-lokistack-gateway", false, "Enables the manifest creation for the entire lokistack-gateway.")
// Object storage options
c.objectStorage = manifests.ObjectStorage{}
f.StringVar(&c.objectStorage.Endpoint, "object-storage.endpoint", "", "The S3 endpoint location.")
f.StringVar(&c.objectStorage.Buckets, "object-storage.buckets", "", "A comma-separated list of S3 buckets.")
f.StringVar(&c.objectStorage.Region, "object-storage.region", "", "An S3 region.")
f.StringVar(&c.objectStorage.AccessKeyID, "object-storage.access-key-id", "", "The access key id for S3.")
f.StringVar(&c.objectStorage.AccessKeySecret, "object-storage.access-key-secret", "", "The access key secret for S3.")
c.objectStorage = storage.Options{
S3: &storage.S3StorageConfig{},
}
f.StringVar(&c.objectStorage.S3.Endpoint, "object-storage.s3.endpoint", "", "The S3 endpoint location.")
f.StringVar(&c.objectStorage.S3.Buckets, "object-storage.s3.buckets", "", "A comma-separated list of S3 buckets.")
f.StringVar(&c.objectStorage.S3.Region, "object-storage.s3.region", "", "An S3 region.")
f.StringVar(&c.objectStorage.S3.AccessKeyID, "object-storage.s3.access-key-id", "", "The access key id for S3.")
f.StringVar(&c.objectStorage.S3.AccessKeySecret, "object-storage.s3.access-key-secret", "", "The access key secret for S3.")
// Input and output file/dir options
f.StringVar(&c.crFilepath, "custom-resource.path", "", "Path to a custom resource YAML file.")
f.StringVar(&c.writeToDir, "output.write-dir", "", "write each file to the specified directory.")
Expand All @@ -64,20 +67,20 @@ func (c *config) validateFlags() {
os.Exit(1)
}
// Validate manifests.objectStorage
if cfg.objectStorage.Endpoint == "" {
log.Info("-object.storage.endpoint flag is required")
if cfg.objectStorage.S3.Endpoint == "" {
log.Info("-object-storage.s3.endpoint flag is required")
os.Exit(1)
}
if cfg.objectStorage.Buckets == "" {
log.Info("-object.storage.buckets flag is required")
if cfg.objectStorage.S3.Buckets == "" {
log.Info("-object-storage.s3.buckets flag is required")
os.Exit(1)
}
if cfg.objectStorage.AccessKeyID == "" {
log.Info("-object.storage.access.key.id flag is required")
if cfg.objectStorage.S3.AccessKeyID == "" {
log.Info("-object-storage.s3.access.key.id flag is required")
os.Exit(1)
}
if cfg.objectStorage.AccessKeySecret == "" {
log.Info("-object.storage.access.key.secret flag is required")
if cfg.objectStorage.S3.AccessKeySecret == "" {
log.Info("-object-storage.s3.access.key.secret flag is required")
os.Exit(1)
}
}
Expand Down
9 changes: 9 additions & 0 deletions operator/config/crd/bases/loki.grafana.com_lokistacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,17 @@ spec:
name:
description: Name of a secret in the namespace configured for object storage secrets.
type: string
type:
description: Type of object storage that should be used
enum:
- azure
- gcs
- s3
- swift
type: string
required:
- name
- type
type: object
required:
- secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,18 @@ spec:
path: storage
- description: Name of a secret in the namespace configured for object storage
secrets.
displayName: Object Storage Secret
displayName: Object Storage Secret Name
path: storage.secret.name
x-descriptors:
- urn:alm:descriptor:io.kubernetes:Secret
- description: Type of object storage that should be used
displayName: Object Storage Secret Type
path: storage.secret.type
x-descriptors:
- 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
- description: Storage class name defines the storage class for ingester/querier
PVCs.
displayName: Storage Class Name
Expand Down
30 changes: 14 additions & 16 deletions operator/docs/hack_operator_make_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ _Note:_ This is helpful when you don't want to deploy the Loki Operator image ev
```console
kubectl rollout status deployment/<DEPLOYMENT_NAME>
```

where `<DEPLOYMENT_NAME>` is the name of the deployment and can be found using:

```console
kubectl get deployments
```

Confirm that all are up and running for `statefulsets` using:

```console
kubectl rollout status statefulset/<STATEFULSET_NAME>
```

where `<STATEFULSET_NAME>` is the name of the statefulset and can be found using:

```console
kubectl get statefulsets
```

* If you make some changes to the operator's code, then just stop the operator locally using `CTRL + C`, update the code and rerun the operator locally:

```console
make run
```
Expand All @@ -92,7 +92,7 @@ _Note:_ This is helpful when you don't want to deploy the Loki Operator image ev
```console
make uninstall
```

* Cleanup the minio deployment using:

```console
Expand Down Expand Up @@ -120,7 +120,7 @@ _Note:_ This is helpful when you don't want to deploy the Loki Operator image ev
```console
kubectl get crd lokistacks.loki.grafana.com
```

* Create the `openshift-logging` namespace in the cluster:

```console
Expand All @@ -130,17 +130,15 @@ _Note:_ This is helpful when you don't want to deploy the Loki Operator image ev
* Now you need to create a storage secret for the operator. This can be done using:

```console
make olm-deploy-example-storage-secret
./hack/deploy-aws-storage-secret.sh <BUCKET_NAME>
```

OR
This secret will be available in `openshift-logging` namespace. You can check the `hack/deploy-aws-storage-secret.sh` file to check the content of the secret. By default, the script will pull credential information using the `aws` cli. However, these values can be overwritten. For example:

```console
./hack/deploy-example-secret.sh openshift-logging
REGION=us-west-1 ./hack/deploy-aws-storage-secret.sh <BUCKET_NAME>
```

This secret will be available in openshift-logging namespace. You can check the `hack/deploy-example-secret.sh` file to check the content of the secret.

* Once the object storage secret is created, you can now create a LokiStack instance:

```console
Expand Down Expand Up @@ -178,7 +176,7 @@ _Note:_ This is helpful when you don't want to deploy the Loki Operator image ev
```console
kubectl -n openshift-logging get statefulsets
```

* If you want `lokistack-gateway` component [1] to be deployed then you need to create a gateway secret [2] for the operator. This can be done using:

```code
Expand All @@ -187,13 +185,13 @@ _Note:_ This is helpful when you don't want to deploy the Loki Operator image ev
--from-literal=clientSecret="<CLIENT_SECRET>" \
--from-literal=issuerCAPath="<ISSUER_CA_PATH>"
```

* Now create a LokiStack instance using:

```console
kubectl -n openshift-logging apply -f hack/lokistack_gateway_dev.yaml
```

* Edit the [main file](https://github.com/grafana/loki/blob/master/operator/main.go) to set the flag values to `true` and rerun the operator using:

```console
Expand Down
1 change: 1 addition & 0 deletions operator/hack/lokistack_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ spec:
storage:
secret:
name: test
type: s3
storageClassName: standard
1 change: 1 addition & 0 deletions operator/hack/lokistack_gateway_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spec:
storage:
secret:
name: test
type: s3
storageClassName: gp2
tenants:
mode: static
Expand Down
1 change: 1 addition & 0 deletions operator/hack/lokistack_gateway_ocp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spec:
storage:
secret:
name: test
type: s3
storageClassName: gp2
tenants:
mode: openshift-logging
Loading