Skip to content

Commit

Permalink
Merge pull request #209 from danisla/gcs-snapshot
Browse files Browse the repository at this point in the history
Support for GCS Snapshots
  • Loading branch information
stevesloka authored Jul 7, 2018
2 parents 21591e3 + 039b890 commit 18ca90c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ If changes are required to the cluster, say the replica count of the data nodes
# Snapshot
Elasticsearch can snapshot it's indexes for easy backup / recovery of the cluster. Currently there's an integration to Amazon S3 as the backup repository for snapshots. The `upmcenterprises` docker images include the [S3 Plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/current/repository-s3.html) which enables this feature in AWS.
Elasticsearch can snapshot it's indexes for easy backup / recovery of the cluster. Currently there's an integration to Amazon S3 or Google Cloud Storage as the backup repository for snapshots. The `upmcenterprises` docker images include the [S3 Plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/current/repository-s3.html) and the [GCS Plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/current/repository-gcs.html) which enables this feature in AWS and GCP.
## Schedule
Expand Down Expand Up @@ -221,6 +221,21 @@ To enable the snapshots create a bucket in S3, then apply the following IAM perm
}
```
## GCP Setup
To enable snapshots with GCS on GKE, create a bucket in GCS and bind the `storage.admin` role to the cluster service account replacing `${BUCKET}` with your bucket name:
```
gsutil mb gs://${BUCKET}

SA_EMAIL=$(kubectl run shell --rm --restart=Never -it --image google/cloud-sdk --command /usr/bin/curl -- -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/email)

PROJECT=$(gcloud config get-value project)

gcloud projects add-iam-policy-binding ${PROJECT} \
--role roles/storage.admin --member serviceAccount:${SA_EMAIL}
```
## Snapshot Authentication
If you are using an elasticsearch image that requires authentication for the snapshot url, you can specify basic auth credentials.
Expand Down
8 changes: 6 additions & 2 deletions pkg/apis/elasticsearchoperator/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ type Snapshot struct {
// Enabled determines if snapshots are enabled
SchedulerEnabled bool `json:"scheduler-enabled"`

// BucketName defines the AWS S3 bucket to store snapshots
// RepoType defines the type of Elasticsearch Repository, s3 or gcs
RepoType string `json:"type"`

// BucketName defines the AWS S3 or GCS bucket to store snapshots
BucketName string `json:"bucket-name"`

// CronSchedule defines how to run the snapshots
Expand Down Expand Up @@ -204,7 +207,8 @@ type Cerebro struct {

// Scheduler stores info about how to snapshot the cluster
type Scheduler struct {
S3bucketName string
RepoType string
BucketName string
CronSchedule string
Enabled bool
Auth SchedulerAuthentication
Expand Down
5 changes: 4 additions & 1 deletion pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (p *Processor) refreshClusters() error {
KeepSecretsOnDelete: cluster.Spec.KeepSecretsOnDelete,
Snapshot: myspec.Snapshot{
SchedulerEnabled: cluster.Spec.Snapshot.SchedulerEnabled,
RepoType: cluster.Spec.Snapshot.RepoType,
BucketName: cluster.Spec.Snapshot.BucketName,
CronSchedule: cluster.Spec.Snapshot.CronSchedule,
},
Expand All @@ -175,7 +176,8 @@ func (p *Processor) refreshClusters() error {
VolumeReclaimPolicy: cluster.Spec.Storage.VolumeReclaimPolicy,
},
Scheduler: myspec.Scheduler{
S3bucketName: cluster.Spec.Snapshot.BucketName,
RepoType: cluster.Spec.Snapshot.RepoType,
BucketName: cluster.Spec.Snapshot.BucketName,
CronSchedule: cluster.Spec.Snapshot.CronSchedule,
Enabled: cluster.Spec.Snapshot.SchedulerEnabled,
Auth: myspec.SchedulerAuthentication{
Expand Down Expand Up @@ -210,6 +212,7 @@ func (p *Processor) refreshClusters() error {
},
},
Scheduler: snapshot.New(
cluster.Spec.Snapshot.RepoType,
cluster.Spec.Snapshot.BucketName,
cluster.Spec.Snapshot.CronSchedule,
cluster.Spec.Snapshot.SchedulerEnabled,
Expand Down
12 changes: 9 additions & 3 deletions pkg/snapshot/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,22 @@ type Scheduler struct {
}

// New creates an instance of Scheduler
func New(bucketName, cronSchedule string, enabled, useSSL bool, userName, password, image,
func New(repoType, bucketName, cronSchedule string, enabled, useSSL bool, userName, password, image,
elasticURL, clusterName, namespace string, kc kubernetes.Interface) *Scheduler {

if repoType == "" {
repoType = "s3"
}

if image == "" {
image = defaultCronImage
}

return &Scheduler{
Kclient: kc,
CRD: enterprisesv1.Scheduler{
S3bucketName: bucketName,
RepoType: repoType,
BucketName: bucketName,
CronSchedule: cronSchedule,
ElasticURL: elasticURL,
Auth: enterprisesv1.SchedulerAuthentication{
Expand Down Expand Up @@ -214,7 +219,8 @@ func (s *Scheduler) CreateCronJob(namespace, clusterName, action, cronSchedule s
},
Args: []string{
fmt.Sprintf("--action=%s", action),
fmt.Sprintf("--s3-bucket-name=%s", s.CRD.S3bucketName),
fmt.Sprintf("--repo-type=%s", s.CRD.RepoType),
fmt.Sprintf("--bucket-name=%s", s.CRD.BucketName),
fmt.Sprintf("--elastic-url=%s", s.CRD.ElasticURL),
fmt.Sprintf("--auth-username=%s", s.CRD.Auth.UserName),
fmt.Sprintf("--auth-password=%s", s.CRD.Auth.Password),
Expand Down

0 comments on commit 18ca90c

Please sign in to comment.