Skip to content

Commit 99dcf0a

Browse files
authored
Add support for specifying "region" for S3 backend (#1050)
* Add support for specifying "region" for S3 backend Signed-off-by: hossainemruz <emruz@appscode.com> * Update restic version to 0.9.6 Signed-off-by: hossainemruz <emruz@appscode.com> * Revendor using kubernetes-1.16.3 branch of objectstore-api Signed-off-by: hossainemruz <emruz@appscode.com>
1 parent deeaaaf commit 99dcf0a

File tree

14 files changed

+37
-13
lines changed

14 files changed

+37
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ endif
5050

5151
RESTIC_VER := 0.8.3
5252
# also update in restic wrapper library
53-
NEW_RESTIC_VER := 0.9.5
53+
NEW_RESTIC_VER := 0.9.6
5454

5555
###
5656
### These variables should not need tweaking.

apis/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
RepositoryBucket = "REPOSITORY_BUCKET"
3535
RepositoryPrefix = "REPOSITORY_PREFIX"
3636
RepositoryEndpoint = "REPOSITORY_ENDPOINT"
37+
RepositoryRegion = "REPOSITORY_REGION"
3738

3839
Hostname = "HOSTNAME"
3940
SourceHostname = "SOURCE_HOSTNAME"

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ require (
4141
kmodules.xyz/constants v0.0.0-20191024095500-cd4313df4aa6
4242
kmodules.xyz/crd-schema-fuzz v0.0.0-20191129174258-81f984340891
4343
kmodules.xyz/custom-resources v0.0.0-20191130062942-f41b54f62419
44-
kmodules.xyz/objectstore-api v0.0.0-20191127144749-5881939b57f0
45-
kmodules.xyz/offshoot-api v0.0.0-20200103145223-2c4f520520d2
44+
kmodules.xyz/objectstore-api v0.0.0-20200213071506-f176860e67f7
45+
kmodules.xyz/offshoot-api v0.0.0-20200207061254-705ac16690ec
4646
kmodules.xyz/openshift v0.0.0-20191127145035-f6c48a90dbb7
4747
kmodules.xyz/prober v0.0.0-20191216013129-7c91e2b0edb2
4848
kmodules.xyz/webhook-runtime v0.0.0-20191127075323-d4bfdee6974d

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,10 @@ kmodules.xyz/crd-schema-fuzz v0.0.0-20191129174258-81f984340891 h1:2W/fqLbAurvup
697697
kmodules.xyz/crd-schema-fuzz v0.0.0-20191129174258-81f984340891/go.mod h1:9NXNZ4xhqof0WngtIuo4vl+WoCQpLJEJcyuEo3mPpiM=
698698
kmodules.xyz/custom-resources v0.0.0-20191130062942-f41b54f62419 h1:o6KD8XMxdyRR3rqScTsWvcufFDT7vQBnYXpHUp6UtRg=
699699
kmodules.xyz/custom-resources v0.0.0-20191130062942-f41b54f62419/go.mod h1:EksiAQK3p3bVU5cNBjLT0z5V7er1tvWLBWILTuf6G/0=
700-
kmodules.xyz/objectstore-api v0.0.0-20191127144749-5881939b57f0 h1:ilgkGU/bteKRvH99piXxU8b2c1E9lwxb0sDpLLhy4iY=
701-
kmodules.xyz/objectstore-api v0.0.0-20191127144749-5881939b57f0/go.mod h1:AE1rz+T/3dlUwH5pLgCNghWeeFfeVBnBXKJVpsLHlmc=
702-
kmodules.xyz/offshoot-api v0.0.0-20200103145223-2c4f520520d2 h1:c/wxNy8KgaS8v/htruqtL0YgrKciUKroK1zXPVZHuqg=
703-
kmodules.xyz/offshoot-api v0.0.0-20200103145223-2c4f520520d2/go.mod h1:k1M+OOFHbMeS6N6OB2j9smKfMCyQOEQjZ3SLZ/KSe+w=
700+
kmodules.xyz/objectstore-api v0.0.0-20200213071506-f176860e67f7 h1:b2ahs7RkOilWVsXHgx/t44FhL8xdbB0r2/W1Jf62Il8=
701+
kmodules.xyz/objectstore-api v0.0.0-20200213071506-f176860e67f7/go.mod h1:AE1rz+T/3dlUwH5pLgCNghWeeFfeVBnBXKJVpsLHlmc=
702+
kmodules.xyz/offshoot-api v0.0.0-20200207061254-705ac16690ec h1:JdgvQhxyFXnxInPK42R3saSBjkhiiy8k5Uc9UdneVqE=
703+
kmodules.xyz/offshoot-api v0.0.0-20200207061254-705ac16690ec/go.mod h1:k1M+OOFHbMeS6N6OB2j9smKfMCyQOEQjZ3SLZ/KSe+w=
704704
kmodules.xyz/openshift v0.0.0-20191127054841-113eeb13704f/go.mod h1:de9+Zk2+wtGhRmGFBZ9T4+0lJZr4rHXW0dHffCaeO+g=
705705
kmodules.xyz/openshift v0.0.0-20191127145035-f6c48a90dbb7 h1:9PImU28r8bt+QoW7FkYbJ+prsZSNtwctLeXJj3wJK5U=
706706
kmodules.xyz/openshift v0.0.0-20191127145035-f6c48a90dbb7/go.mod h1:de9+Zk2+wtGhRmGFBZ9T4+0lJZr4rHXW0dHffCaeO+g=

pkg/cmds/backup_pvc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func NewCmdBackupPVC() *cobra.Command {
7171
cmd.Flags().StringVar(&setupOpt.Provider, "provider", setupOpt.Provider, "Backend provider (i.e. gcs, s3, azure etc)")
7272
cmd.Flags().StringVar(&setupOpt.Bucket, "bucket", setupOpt.Bucket, "Name of the cloud bucket/container (keep empty for local backend)")
7373
cmd.Flags().StringVar(&setupOpt.Endpoint, "endpoint", setupOpt.Endpoint, "Endpoint for s3/s3 compatible backend or REST server URL")
74+
cmd.Flags().StringVar(&setupOpt.Region, "region", setupOpt.Region, "Region for s3/s3 compatible backend")
7475
cmd.Flags().StringVar(&setupOpt.Path, "path", setupOpt.Path, "Directory inside the bucket where backed up data will be stored")
7576
cmd.Flags().StringVar(&setupOpt.SecretDir, "secret-dir", setupOpt.SecretDir, "Directory where storage secret has been mounted")
7677
cmd.Flags().StringVar(&setupOpt.ScratchDir, "scratch-dir", setupOpt.ScratchDir, "Temporary directory")

pkg/cmds/restore_pvc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func NewCmdRestorePVC() *cobra.Command {
7070
cmd.Flags().StringVar(&setupOpt.Provider, "provider", setupOpt.Provider, "Backend provider (i.e. gcs, s3, azure etc)")
7171
cmd.Flags().StringVar(&setupOpt.Bucket, "bucket", setupOpt.Bucket, "Name of the cloud bucket/container (keep empty for local backend)")
7272
cmd.Flags().StringVar(&setupOpt.Endpoint, "endpoint", setupOpt.Endpoint, "Endpoint for s3/s3 compatible backend or REST server URL")
73+
cmd.Flags().StringVar(&setupOpt.Region, "region", setupOpt.Region, "Region for s3/s3 compatible backend")
7374
cmd.Flags().StringVar(&setupOpt.Path, "path", setupOpt.Path, "Directory inside the bucket where backed up data has been stored")
7475
cmd.Flags().StringVar(&setupOpt.SecretDir, "secret-dir", setupOpt.SecretDir, "Directory where storage secret has been mounted")
7576
cmd.Flags().StringVar(&setupOpt.ScratchDir, "scratch-dir", setupOpt.ScratchDir, "Temporary directory")

pkg/controller/inputs.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,13 @@ func (c *StashController) inputsForRepository(repository *apiAlpha.Repository) (
119119
if repository.Spec.Backend.S3 != nil && repository.Spec.Backend.S3.Endpoint != "" {
120120
inputs[apis.RepositoryEndpoint] = repository.Spec.Backend.S3.Endpoint
121121
}
122-
if repository.Spec.Backend.Rest != nil && repository.Spec.Backend.Rest.URL != "" {
123-
inputs[apis.RepositoryEndpoint] = repository.Spec.Backend.Rest.URL
122+
endpoint, found := repository.Spec.Backend.Endpoint()
123+
if found {
124+
inputs[apis.RepositoryEndpoint] = endpoint
125+
}
126+
region, found := repository.Spec.Backend.Region()
127+
if found {
128+
inputs[apis.RepositoryRegion] = region
124129
}
125130
inputs[apis.MaxConnections] = strconv.FormatInt(repository.Spec.Backend.MaxConnections(), 10)
126131
return

pkg/restic/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
)
3737

3838
const (
39-
ResticCMD = "/bin/restic_0.9.5"
39+
ResticCMD = "/bin/restic_0.9.6"
4040
)
4141

4242
type Snapshot struct {

pkg/restic/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type SetupOptions struct {
7777
Provider string
7878
Bucket string
7979
Endpoint string
80+
Region string
8081
Path string
8182
SecretDir string
8283
CacertFile string

pkg/restic/setup.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const (
3333

3434
AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID"
3535
AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY"
36+
AWS_DEFAULT_REGION = "AWS_DEFAULT_REGION"
3637

3738
GOOGLE_PROJECT_ID = "GOOGLE_PROJECT_ID"
3839
GOOGLE_SERVICE_ACCOUNT_JSON_KEY = "GOOGLE_SERVICE_ACCOUNT_JSON_KEY"
@@ -127,6 +128,10 @@ func (w *ResticWrapper) setupEnv() error {
127128
w.sh.SetEnv(AWS_SECRET_ACCESS_KEY, string(v))
128129
}
129130

131+
if w.config.Region != "" {
132+
w.sh.SetEnv(AWS_DEFAULT_REGION, w.config.Region)
133+
}
134+
130135
case storage.ProviderGCS:
131136
r := fmt.Sprintf("gs:%s:/%s", w.config.Bucket, w.config.Path)
132137
w.sh.SetEnv(RESTIC_REPOSITORY, r)

0 commit comments

Comments
 (0)