Skip to content

Commit

Permalink
Signed-off-by: Anisur Rahman <[email protected]> (#2017)
Browse files Browse the repository at this point in the history
/cherry-pick
  • Loading branch information
anisurrahman75 authored and 1gtm committed Feb 9, 2024
1 parent 7c4fcb4 commit 5574133
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 25 deletions.
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ require (
gomodules.xyz/logs v0.0.7
gomodules.xyz/pointer v0.1.0
gomodules.xyz/x v0.0.15
k8s.io/api v0.25.3
k8s.io/apimachinery v0.25.3
k8s.io/client-go v0.25.3
k8s.io/klog/v2 v2.80.1
kmodules.xyz/client-go v0.25.37
kmodules.xyz/custom-resources v0.25.2
kmodules.xyz/offshoot-api v0.25.4
kubedb.dev/apimachinery v0.33.1
stash.appscode.dev/apimachinery v0.32.0
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/klog/v2 v2.110.1
kmodules.xyz/client-go v0.29.5
kmodules.xyz/custom-resources v0.29.0
kmodules.xyz/offshoot-api v0.29.0
kubedb.dev/apimachinery v0.40.1-0.20240101000103-032b27211164
stash.appscode.dev/apimachinery v0.32.1-0.20240202121916-8f4a855a72c8
)

require github.com/onsi/gomega v1.20.1 // indirect
Expand Down
20 changes: 8 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -897,15 +897,11 @@ kmodules.xyz/prober v0.25.0/go.mod h1:z4RTnjaajNQa/vPltsiOnO3xI716I/ziD2ac2Exm+1
kubedb.dev/apimachinery v0.33.1 h1:tZCe6hHslSsiV+nvhzIrFt01WLDqQjMc/DYxyH8DVWA=
kubedb.dev/apimachinery v0.33.1/go.mod h1:NeUOOmIS8E0TdDCSJcyYrbbs7wvebSXGO9ddredvgRs=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/controller-runtime v0.13.1 h1:tUsRCSJVM1QQOOeViGeX3GMT3dQF1eePPw6sEE3xSlg=
sigs.k8s.io/controller-runtime v0.13.1/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
stash.appscode.dev/apimachinery v0.32.0 h1:WgbZi/In8GCV/r5zx6KD9onDMQviQ74RpCjUbZBm6vs=
stash.appscode.dev/apimachinery v0.32.0/go.mod h1:sRMQDbHN5AH9Ntz2HfixcepaP0L0HWFNAqGN22GrBzc=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
stash.appscode.dev/apimachinery v0.32.1-0.20240202121916-8f4a855a72c8 h1:p3kd1saM5Ehz9mkqJhVrcFDhY0Bjv8S0XYuq2dZb3KI=
stash.appscode.dev/apimachinery v0.32.1-0.20240202121916-8f4a855a72c8/go.mod h1:cPdkM9Upe5hxgxrV+WlIQCq7K0Tpx//VUwFs0NKB7ek=
1 change: 1 addition & 0 deletions pkg/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func NewCmdBackup() *cobra.Command {
cmd.Flags().StringVar(&opt.setupOptions.Provider, "provider", opt.setupOptions.Provider, "Backend provider (i.e. gcs, s3, azure etc)")
cmd.Flags().StringVar(&opt.setupOptions.Bucket, "bucket", opt.setupOptions.Bucket, "Name of the cloud bucket/container (keep empty for local backend)")
cmd.Flags().StringVar(&opt.setupOptions.Endpoint, "endpoint", opt.setupOptions.Endpoint, "Endpoint for s3/s3 compatible backend or REST server URL")
cmd.Flags().BoolVar(&opt.setupOptions.InsecureTLS, "insecure-tls", opt.setupOptions.InsecureTLS, "InsecureTLS for TLS secure s3/s3 compatible backend")
cmd.Flags().StringVar(&opt.setupOptions.Region, "region", opt.setupOptions.Region, "Region for s3/s3 compatible backend")
cmd.Flags().StringVar(&opt.setupOptions.Path, "path", opt.setupOptions.Path, "Directory inside the bucket where backup will be stored")
cmd.Flags().StringVar(&opt.setupOptions.ScratchDir, "scratch-dir", opt.setupOptions.ScratchDir, "Temporary directory")
Expand Down
1 change: 1 addition & 0 deletions pkg/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func NewCmdRestore() *cobra.Command {
cmd.Flags().StringVar(&opt.setupOptions.Provider, "provider", opt.setupOptions.Provider, "Backend provider (i.e. gcs, s3, azure etc)")
cmd.Flags().StringVar(&opt.setupOptions.Bucket, "bucket", opt.setupOptions.Bucket, "Name of the cloud bucket/container (keep empty for local backend)")
cmd.Flags().StringVar(&opt.setupOptions.Endpoint, "endpoint", opt.setupOptions.Endpoint, "Endpoint for s3/s3 compatible backend or REST server URL")
cmd.Flags().BoolVar(&opt.setupOptions.InsecureTLS, "insecure-tls", opt.setupOptions.InsecureTLS, "InsecureTLS for TLS secure s3/s3 compatible backend")
cmd.Flags().StringVar(&opt.setupOptions.Region, "region", opt.setupOptions.Region, "Region for s3/s3 compatible backend")
cmd.Flags().StringVar(&opt.setupOptions.Path, "path", opt.setupOptions.Path, "Directory inside the bucket where backup will be stored")
cmd.Flags().StringVar(&opt.setupOptions.ScratchDir, "scratch-dir", opt.setupOptions.ScratchDir, "Temporary directory")
Expand Down
5 changes: 3 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,9 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.3.0
## explicit; go 1.12
sigs.k8s.io/yaml
# stash.appscode.dev/apimachinery v0.32.0
## explicit; go 1.18
sigs.k8s.io/yaml/goyaml.v2
# stash.appscode.dev/apimachinery v0.32.1-0.20240202121916-8f4a855a72c8
## explicit; go 1.21.5
stash.appscode.dev/apimachinery/apis
stash.appscode.dev/apimachinery/apis/repositories
stash.appscode.dev/apimachinery/apis/repositories/v1alpha1
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,8 @@ spec:
type: string
endpoint:
type: string
insecureTLS:
type: boolean
prefix:
type: string
region:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,8 @@ spec:
type: string
endpoint:
type: string
insecureTLS:
type: boolean
prefix:
type: string
region:
Expand Down
23 changes: 23 additions & 0 deletions vendor/stash.appscode.dev/apimachinery/pkg/restic/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (w *ResticWrapper) listSnapshots(snapshotIDs []string) ([]Snapshot, error)
result := make([]Snapshot, 0)
args := w.appendCacheDirFlag([]interface{}{"snapshots", "--json", "--quiet", "--no-lock"})
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)
for _, id := range snapshotIDs {
args = append(args, id)
Expand All @@ -95,6 +96,7 @@ func (w *ResticWrapper) listSnapshots(snapshotIDs []string) ([]Snapshot, error)
func (w *ResticWrapper) deleteSnapshots(snapshotIDs []string) ([]byte, error) {
args := w.appendCacheDirFlag([]interface{}{"forget", "--quiet", "--prune"})
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)
for _, id := range snapshotIDs {
args = append(args, id)
Expand All @@ -107,6 +109,7 @@ func (w *ResticWrapper) repositoryExist() bool {
klog.Infoln("Checking whether the backend repository exist or not....")
args := w.appendCacheDirFlag([]interface{}{"snapshots", "--json", "--no-lock"})
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)
if _, err := w.run(Command{Name: ResticCMD, Args: args}); err == nil {
return true
Expand All @@ -122,6 +125,7 @@ func (w *ResticWrapper) initRepository() error {

args := w.appendCacheDirFlag([]interface{}{"init"})
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)
_, err := w.run(Command{Name: ResticCMD, Args: args})
return err
Expand Down Expand Up @@ -151,6 +155,7 @@ func (w *ResticWrapper) backup(params backupParams) ([]byte, error) {
args = w.appendCacheDirFlag(args)
args = w.appendCleanupCacheFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
Expand All @@ -174,6 +179,7 @@ func (w *ResticWrapper) backupFromStdin(options BackupOptions) ([]byte, error) {
args = w.appendCacheDirFlag(args)
args = w.appendCleanupCacheFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)

commands = append(commands, Command{Name: ResticCMD, Args: args})
Expand Down Expand Up @@ -248,6 +254,7 @@ func (w *ResticWrapper) tryCleanup(retentionPolicy v1alpha1.RetentionPolicy, hos
if len(args) > 1 {
args = w.appendCacheDirFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
Expand Down Expand Up @@ -294,6 +301,7 @@ func (w *ResticWrapper) restore(params restoreParams) ([]byte, error) {
}
args = w.appendCacheDirFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
Expand Down Expand Up @@ -325,6 +333,7 @@ func (w *ResticWrapper) DumpOnce(dumpOptions DumpOptions) ([]byte, error) {

args = w.appendCacheDirFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)

// first add restic command, then add StdoutPipeCommands
Expand All @@ -339,6 +348,7 @@ func (w *ResticWrapper) check() ([]byte, error) {
klog.Infoln("Checking integrity of repository")
args := w.appendCacheDirFlag([]interface{}{"check", "--no-lock"})
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)
args = w.appendMaxConnectionsFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
Expand All @@ -353,6 +363,7 @@ func (w *ResticWrapper) stats(snapshotID string) ([]byte, error) {
args = w.appendMaxConnectionsFlag(args)
args = append(args, "--quiet", "--json", "--mode", "raw-data", "--no-lock")
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
}
Expand All @@ -362,6 +373,7 @@ func (w *ResticWrapper) unlock() ([]byte, error) {
args := w.appendCacheDirFlag([]interface{}{"unlock", "--remove-all"})
args = w.appendMaxConnectionsFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
}
Expand Down Expand Up @@ -515,6 +527,7 @@ func (w *ResticWrapper) addKey(params keyParams) ([]byte, error) {
args = w.appendCacheDirFlag(args)
args = w.appendMaxConnectionsFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
}
Expand All @@ -527,6 +540,7 @@ func (w *ResticWrapper) listKey() ([]byte, error) {
args = w.appendCacheDirFlag(args)
args = w.appendMaxConnectionsFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
}
Expand All @@ -543,6 +557,7 @@ func (w *ResticWrapper) updateKey(params keyParams) ([]byte, error) {
args = w.appendCacheDirFlag(args)
args = w.appendMaxConnectionsFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
}
Expand All @@ -555,6 +570,14 @@ func (w *ResticWrapper) removeKey(params keyParams) ([]byte, error) {
args = w.appendCacheDirFlag(args)
args = w.appendMaxConnectionsFlag(args)
args = w.appendCaCertFlag(args)
args = w.appendInsecureTLSFlag(args)

return w.run(Command{Name: ResticCMD, Args: args})
}

func (w *ResticWrapper) appendInsecureTLSFlag(args []interface{}) []interface{} {
if w.config.InsecureTLS {
return append(args, "--insecure-tls")
}
return args
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type SetupOptions struct {
CacertFile string
ScratchDir string
EnableCache bool
InsecureTLS bool
MaxConnections int64
StorageSecret *core.Secret
Nice *ofst.NiceSettings
Expand Down
25 changes: 23 additions & 2 deletions vendor/stash.appscode.dev/apimachinery/pkg/util/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func ExtractAddonInfo(appClient appcatalog_cs.Interface, task v1beta1.TaskRef, t
addon.RestoreTask.Name = task.Name
}
if len(task.Params) != 0 {
addon.BackupTask.Params = getTaskParams(task)
addon.RestoreTask.Params = getTaskParams(task)
addon.BackupTask.Params = upsertParams(addon.BackupTask.Params, getTaskParams(task))
addon.RestoreTask.Params = upsertParams(addon.BackupTask.Params, getTaskParams(task))
}

return &addon, nil
Expand All @@ -75,3 +75,24 @@ func getTaskParams(task v1beta1.TaskRef) []appcat.Param {
}
return params
}

func upsertParams(oldParams, newParams []appcat.Param) []appcat.Param {
paramMap := make(map[string]appcat.Param)

for _, newParam := range newParams {
paramMap[newParam.Name] = newParam
}

for _, oldParam := range oldParams {
if _, found := paramMap[oldParam.Name]; !found {
paramMap[oldParam.Name] = oldParam
}
}

var updatedParams []appcat.Param
for _, param := range paramMap {
updatedParams = append(updatedParams, param)
}

return updatedParams
}

0 comments on commit 5574133

Please sign in to comment.