Skip to content

Commit

Permalink
Fix Upserting temporary volume (#1498)
Browse files Browse the repository at this point in the history
* Fix upserting temporary volume

Signed-off-by: hmsayem <[email protected]>

* Run make gen

Signed-off-by: hmsayem <[email protected]>

* Use default scratch dir

Signed-off-by: hmsayem <[email protected]>

* Add stash prefix

Signed-off-by: hmsayem <[email protected]>

* Use sratch dir const

Signed-off-by: hmsayem <[email protected]>

* Revendor

Signed-off-by: hmsayem <[email protected]>

Signed-off-by: hmsayem <[email protected]>
  • Loading branch information
hmsayem authored Jan 3, 2023
1 parent 371fefe commit b7ed85b
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require (
kmodules.xyz/openshift v0.25.0
kmodules.xyz/prober v0.25.0
kmodules.xyz/webhook-runtime v0.25.0
stash.appscode.dev/apimachinery v0.24.0
stash.appscode.dev/apimachinery v0.24.1-0.20230103053452-3f20f5fe078b
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1393,5 +1393,5 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
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.24.0 h1:bMEySRvft1WYZX8EpYQR5Lqsi280/WKOYVUpqXRTTuM=
stash.appscode.dev/apimachinery v0.24.0/go.mod h1:AdK7wfKZXqlL5g30ceuMw/7nEVW3AOemQVWjc03sI3k=
stash.appscode.dev/apimachinery v0.24.1-0.20230103053452-3f20f5fe078b h1:W0qAo9g27HSoZXz6hrOeTC5+beIVX6RhARug2NILHGU=
stash.appscode.dev/apimachinery v0.24.1-0.20230103053452-3f20f5fe078b/go.mod h1:AdK7wfKZXqlL5g30ceuMw/7nEVW3AOemQVWjc03sI3k=
2 changes: 1 addition & 1 deletion pkg/cmds/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewCmdRestore() *cobra.Command {
KubeconfigPath: "",
Namespace: meta.PodNamespace(),
SetupOpt: restic.SetupOptions{
ScratchDir: "/tmp",
ScratchDir: restic.DefaultScratchDir,
EnableCache: true,
},
RestoreModel: restore.RestoreModelInitContainer,
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmds/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
cs "stash.appscode.dev/apimachinery/client/clientset/versioned"
"stash.appscode.dev/apimachinery/pkg/docker"
"stash.appscode.dev/apimachinery/pkg/metrics"
"stash.appscode.dev/apimachinery/pkg/restic"
"stash.appscode.dev/stash/pkg/controller"

"github.com/spf13/pflag"
Expand Down Expand Up @@ -67,7 +68,7 @@ func NewExtraOptions() *ExtraOptions {
StashImageTag: "",
MaxNumRequeues: 5,
NumThreads: 2,
ScratchDir: "/tmp",
ScratchDir: restic.DefaultScratchDir,
QPS: 100,
Burst: 100,
ResyncPeriod: 10 * time.Minute,
Expand Down
15 changes: 8 additions & 7 deletions pkg/util/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
util_v1beta1 "stash.appscode.dev/apimachinery/client/clientset/versioned/typed/stash/v1beta1/util"
"stash.appscode.dev/apimachinery/pkg/docker"
"stash.appscode.dev/apimachinery/pkg/metrics"
"stash.appscode.dev/apimachinery/pkg/restic"

core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -101,7 +102,6 @@ func updateStatusFunction(image docker.Docker) *api_v1beta1.Function {
"--endpoint=${REPOSITORY_ENDPOINT:=}",
"--region=${REPOSITORY_REGION:=}",
"--path=${REPOSITORY_PREFIX:=}",
"--scratch-dir=/tmp",
"--enable-cache=${ENABLE_CACHE:=true}",
"--max-connections=${MAX_CONNECTIONS:=0}",
"--namespace=${NAMESPACE:=default}",
Expand All @@ -115,6 +115,7 @@ func updateStatusFunction(image docker.Docker) *api_v1beta1.Function {
"--target-namespace=${TARGET_NAMESPACE:=}",
"--output-dir=${outputDir:=}",
"--metrics-enabled=true",
fmt.Sprintf("--scratch-dir=%s", restic.DefaultScratchDir),
fmt.Sprintf("--metrics-pushgateway-url=%s", metrics.GetPushgatewayURL()),
},
},
Expand All @@ -135,7 +136,6 @@ func pvcBackupFunction(image docker.Docker) *api_v1beta1.Function {
"--endpoint=${REPOSITORY_ENDPOINT:=}",
"--region=${REPOSITORY_REGION:=}",
"--path=${REPOSITORY_PREFIX:=}",
"--scratch-dir=/tmp",
"--enable-cache=${ENABLE_CACHE:=true}",
"--max-connections=${MAX_CONNECTIONS:=0}",
"--hostname=${HOSTNAME:=}",
Expand All @@ -160,6 +160,7 @@ func pvcBackupFunction(image docker.Docker) *api_v1beta1.Function {
"--retention-prune=${RETENTION_PRUNE:=false}",
"--retention-dry-run=${RETENTION_DRY_RUN:=false}",
"--output-dir=${outputDir:=}",
fmt.Sprintf("--scratch-dir=%s", restic.DefaultScratchDir),
},
VolumeMounts: []core.VolumeMount{
{
Expand All @@ -185,7 +186,6 @@ func pvcRestoreFunction(image docker.Docker) *api_v1beta1.Function {
"--endpoint=${REPOSITORY_ENDPOINT:=}",
"--region=${REPOSITORY_REGION:=}",
"--path=${REPOSITORY_PREFIX:=}",
"--scratch-dir=/tmp",
"--enable-cache=${ENABLE_CACHE:=true}",
"--max-connections=${MAX_CONNECTIONS:=0}",
"--hostname=${HOSTNAME:=}",
Expand All @@ -202,6 +202,7 @@ func pvcRestoreFunction(image docker.Docker) *api_v1beta1.Function {
"--target-kind=${TARGET_KIND:=}",
"--target-name=${TARGET_NAME:=}",
"--target-namespace=${TARGET_NAMESPACE:=}",
fmt.Sprintf("--scratch-dir=%s", restic.DefaultScratchDir),
},
VolumeMounts: []core.VolumeMount{
{
Expand All @@ -225,7 +226,7 @@ func pvcBackupTask() *api_v1beta1.Task {
Params: []api_v1beta1.Param{
{
Name: "outputDir",
Value: "/tmp/output",
Value: fmt.Sprintf("%s/output", restic.DefaultScratchDir),
},
{
Name: "targetVolume",
Expand All @@ -238,7 +239,7 @@ func pvcBackupTask() *api_v1beta1.Task {
Params: []api_v1beta1.Param{
{
Name: "outputDir",
Value: "/tmp/output",
Value: fmt.Sprintf("%s/output", restic.DefaultScratchDir),
},
},
},
Expand Down Expand Up @@ -269,7 +270,7 @@ func pvcRestoreTask() *api_v1beta1.Task {
Params: []api_v1beta1.Param{
{
Name: "outputDir",
Value: "/tmp/output",
Value: fmt.Sprintf("%s/output", restic.DefaultScratchDir),
},
{
Name: "targetVolume",
Expand All @@ -282,7 +283,7 @@ func pvcRestoreTask() *api_v1beta1.Task {
Params: []api_v1beta1.Param{
{
Name: "outputDir",
Value: "/tmp/output",
Value: fmt.Sprintf("%s/output", restic.DefaultScratchDir),
},
},
},
Expand Down
14 changes: 12 additions & 2 deletions pkg/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,25 @@ func GetString(m map[string]string, key string) string {
}

func UpsertTmpVolume(volumes []core.Volume, settings v1beta1_api.EmptyDirSettings) []core.Volume {
return core_util.UpsertVolume(volumes, core.Volume{
nv := core.Volume{
Name: apis.TmpDirVolumeName,
VolumeSource: core.VolumeSource{
EmptyDir: &core.EmptyDirVolumeSource{
Medium: settings.Medium,
SizeLimit: settings.SizeLimit,
},
},
})
}

for i, v := range volumes {
if v.Name == nv.Name {
volumes[i].EmptyDir.Medium = settings.Medium
volumes[i].EmptyDir.SizeLimit = settings.SizeLimit
return volumes
}
}

return append(volumes, nv)
}

func UpsertTmpVolumeMount(volumeMounts []core.VolumeMount) []core.VolumeMount {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ 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.24.0
# stash.appscode.dev/apimachinery v0.24.1-0.20230103053452-3f20f5fe078b
## explicit; go 1.18
stash.appscode.dev/apimachinery/apis
stash.appscode.dev/apimachinery/apis/repositories
Expand Down
4 changes: 2 additions & 2 deletions vendor/stash.appscode.dev/apimachinery/apis/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ const (
StashCronJobContainer = "stash-trigger"
LocalVolumeName = "stash-local"
ScratchDirVolumeName = "stash-scratchdir"
TmpDirVolumeName = "tmp-dir"
TmpDirMountPath = "/tmp"
TmpDirVolumeName = "stash-tmp-dir"
TmpDirMountPath = "/stash-tmp"
PodinfoVolumeName = "stash-podinfo"

RecoveryJobPrefix = "stash-recovery-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

const (
DefaultOutputFileName = "output.json"
DefaultScratchDir = "/tmp"
DefaultScratchDir = "/stash-tmp"
DefaultHost = "host-0"
)

Expand Down

0 comments on commit b7ed85b

Please sign in to comment.