Skip to content

Commit

Permalink
Add support for hook executionPolicy (#1457)
Browse files Browse the repository at this point in the history
Signed-off-by: hossainemruz <[email protected]>
  • Loading branch information
Emruz Hossain authored Jul 9, 2022
1 parent 85d6c50 commit 98d3568
Show file tree
Hide file tree
Showing 106 changed files with 13,309 additions and 393 deletions.
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
kmodules.xyz/openshift v0.24.0
kmodules.xyz/prober v0.24.0
kmodules.xyz/webhook-runtime v0.24.0
stash.appscode.dev/apimachinery v0.21.0
stash.appscode.dev/apimachinery v0.21.1-0.20220709120130-c6c22dfcf170
)

require (
Expand All @@ -53,7 +53,9 @@ require (
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 // indirect
github.com/aws/aws-sdk-go v1.44.27 // indirect
Expand Down Expand Up @@ -92,6 +94,7 @@ require (
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -101,7 +104,9 @@ require (
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -122,6 +127,8 @@ require (
github.com/prometheus/procfs v0.7.3 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/stretchr/testify v1.7.1 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
Expand Down
18 changes: 16 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ github.com/GoogleCloudPlatform/cloudsql-proxy v1.19.1/go.mod h1:+yYmuKqcBVkgRePG
github.com/GoogleCloudPlatform/k8s-cloud-provider v1.16.1-0.20210702024009-ea6160c1d0e3/go.mod h1:8XasY4ymP2V/tn2OOV9ZadmiTE1FIB/h3W+yNlPttKw=
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab/go.mod h1:3VYc5hodBMJ5+l/7J4xAyMeuM2PNuepvHlGs8yilUCA=
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8=
github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
github.com/Microsoft/go-winio v0.4.15/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
github.com/Microsoft/go-winio v0.4.17/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Microsoft/hcsshim v0.8.22/go.mod h1:91uVCVzvX2QD16sMCenoxxXo6L1wJnLMX2PSufFMtF0=
Expand Down Expand Up @@ -521,6 +525,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
github.com/heketi/heketi v10.3.0+incompatible/go.mod h1:bB9ly3RchcQqsQ9CpyaQwvva7RS5ytVoSoholZQON6o=
github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6/go.mod h1:xGMAM8JLi7UkZt1i4FQeQy0R2T8GLUwQhOP5M1gBhy4=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
Expand Down Expand Up @@ -615,6 +621,8 @@ github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
Expand All @@ -628,6 +636,8 @@ github.com/mitchellh/mapstructure v1.4.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/moby/ipvs v1.0.1/go.mod h1:2pngiyseZbIKXNv7hsKj3O9UEz30c53MT9005gt2hxQ=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
Expand Down Expand Up @@ -758,6 +768,8 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
Expand All @@ -778,6 +790,7 @@ github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTd
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
Expand Down Expand Up @@ -928,6 +941,7 @@ golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down Expand Up @@ -1627,5 +1641,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.21.0 h1:uK4IAuT3+V7b2/sQAWslQ3iT8agN6qgy58gg9W51rhk=
stash.appscode.dev/apimachinery v0.21.0/go.mod h1:mtxrytXCX8271F5xVMKTwVPoERs6XbhLZlhRKJU08uI=
stash.appscode.dev/apimachinery v0.21.1-0.20220709120130-c6c22dfcf170 h1:HJlM+en1Cxgdml/byxk8i/2dd1O4c+iX0NpEtRKbb8o=
stash.appscode.dev/apimachinery v0.21.1-0.20220709120130-c6c22dfcf170/go.mod h1:uzKMOt8OxE5YpSjRPR6DCkUA+Wn8McXQNPSaVARB0GM=
7 changes: 4 additions & 3 deletions pkg/backup/backupsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (c *BackupSessionController) handleBackupFailure(backupSession *api_v1beta1
func (c *BackupSessionController) handleBackupCompletion(inv invoker.BackupInvoker, targetInfo invoker.BackupTargetInfo, backupSession *api_v1beta1.BackupSession, backupOutput *restic.BackupOutput) error {
// execute hooks at the end of backup completion. no matter if the backup succeed or fail.
defer func() {
if targetInfo.Hooks != nil && targetInfo.Hooks.PostBackup != nil {
if targetInfo.Hooks != nil && targetInfo.Hooks.PostBackup.Handler != nil {
hookErr := c.executePostBackupHook(inv, targetInfo, backupSession)
if hookErr != nil {
klog.Infof("failed to execute postBackup hook. Reason: ", hookErr)
Expand Down Expand Up @@ -582,8 +582,9 @@ func (c *BackupSessionController) executePostBackupHook(inv invoker.BackupInvoke
Namespace: c.Namespace,
Name: meta.PodName(),
},
Hook: targetInfo.Hooks.PostBackup,
HookType: apis.PostBackupHook,
Hook: targetInfo.Hooks.PostBackup.Handler,
ExecutionPolicy: targetInfo.Hooks.PostBackup.ExecutionPolicy,
HookType: apis.PostBackupHook,
}
return hookExecutor.Execute()
}
1 change: 1 addition & 0 deletions pkg/cmds/backup_pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func NewCmdBackupPVC() *cobra.Command {
cmd.Flags().StringVar(&opt.backupOpt.Host, "hostname", opt.backupOpt.Host, "Name of the host machine")
cmd.Flags().StringSliceVar(&opt.backupOpt.BackupPaths, "backup-paths", opt.backupOpt.BackupPaths, "List of paths to backup")
cmd.Flags().StringSliceVar(&opt.backupOpt.Exclude, "exclude", opt.backupOpt.Exclude, "List of pattern for directory/file to ignore during backup. Stash will not backup those files that matches these patterns.")
cmd.Flags().StringSliceVar(&opt.backupOpt.Args, "args", opt.backupOpt.Args, "Arguments to pass to the backup command.")
cmd.Flags().StringVar(&opt.invokerKind, "invoker-kind", opt.invokerKind, "Kind of the backup invoker")
cmd.Flags().StringVar(&opt.invokerName, "invoker-name", opt.invokerName, "Name of the respective backup invoker")
cmd.Flags().StringVar(&opt.targetRef.Name, "target-name", opt.targetRef.Name, "Name of the Target")
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmds/create_volumesnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ func (opt *VSoption) createVolumeSnapshot(bsMeta metav1.ObjectMeta, inv invoker.
}

// If postBackup hook is specified, then execute those hooks after backup
if targetInfo.Hooks != nil && targetInfo.Hooks.PostBackup != nil {
if targetInfo.Hooks != nil && targetInfo.Hooks.PostBackup.Handler != nil {
klog.Infoln("Executing postBackup hooks........")
podName := meta.PodName()
if podName == "" {
return nil, fmt.Errorf("failed to execute postBackup hook. Reason: POD_NAME environment variable not found")
}
err := prober.RunProbe(opt.config, targetInfo.Hooks.PostBackup, podName, opt.namespace)
err := prober.RunProbe(opt.config, targetInfo.Hooks.PostBackup.Handler, podName, opt.namespace)
if err != nil {
return nil, fmt.Errorf(err.Error() + "Warning: The actual backup process may be succeeded." +
"Hence, the backup snapshots might be present in the backend even if the overall BackupSession phase is 'Failed'")
Expand Down
1 change: 1 addition & 0 deletions pkg/cmds/restore_pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func NewCmdRestorePVC() *cobra.Command {
cmd.Flags().StringSliceVar(&opt.restoreOpt.RestorePaths, "restore-paths", opt.restoreOpt.RestorePaths, "List of paths to restore")
cmd.Flags().StringSliceVar(&opt.restoreOpt.Exclude, "exclude", opt.restoreOpt.Exclude, "List of pattern for directory/file to ignore during restore. Stash will not restore those files that matches these patterns.")
cmd.Flags().StringSliceVar(&opt.restoreOpt.Include, "include", opt.restoreOpt.Include, "List of pattern for directory/file to restore. Stash will restore only those files that matches these patterns.")
cmd.Flags().StringSliceVar(&opt.restoreOpt.Args, "args", opt.restoreOpt.Args, "Arguments to pass to the restore command.")
cmd.Flags().StringSliceVar(&opt.restoreOpt.Snapshots, "snapshots", opt.restoreOpt.Snapshots, "List of snapshots to be restored")

cmd.Flags().StringVar(&opt.invokerKind, "invoker-kind", opt.invokerKind, "Kind of the backup invoker")
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmds/restore_volumesnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ func (opt *VSoption) restoreVolumeSnapshot(targetInfo invoker.RestoreTargetInfo)
})
}
// If postRestore hook is specified, then execute those hooks after restore
if targetInfo.Hooks != nil && targetInfo.Hooks.PostRestore != nil {
if targetInfo.Hooks != nil && targetInfo.Hooks.PostRestore.Handler != nil {
klog.Infoln("Executing postRestore hooks........")
podName := meta.PodName()
if podName == "" {
return nil, fmt.Errorf("failed to execute postRestore hook. Reason: POD_NAME environment variable not found")
}
err := prober.RunProbe(opt.config, targetInfo.Hooks.PostRestore, podName, opt.namespace)
err := prober.RunProbe(opt.config, targetInfo.Hooks.PostRestore.Handler, podName, opt.namespace)
if err != nil {
return nil, fmt.Errorf(err.Error() + "Warning: The actual restore process may be succeeded." +
"Hence, the restored data might be present in the target even if the overall RestoreSession phase is 'Failed'")
Expand Down
20 changes: 11 additions & 9 deletions pkg/cmds/run_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,15 @@ func (opt *hookOptions) executeBackupHook() error {
Invoker: inv,
Target: targetInfo.Target.Ref,
ExecutorPod: kmapi.ObjectReference{
Namespace: opt.namespace,
Namespace: opt.targetRef.Namespace,
},
}
if opt.hookType == apis.PreBackupHook {
hookExecutor.Hook = targetInfo.Hooks.PreBackup
hookExecutor.HookType = apis.PreBackupHook
} else {
hookExecutor.Hook = targetInfo.Hooks.PostBackup
hookExecutor.Hook = targetInfo.Hooks.PostBackup.Handler
hookExecutor.ExecutionPolicy = targetInfo.Hooks.PostBackup.ExecutionPolicy
hookExecutor.HookType = apis.PostBackupHook
}
hookExecutor.ExecutorPod.Name, err = opt.getHookExecutorPodName(targetInfo.Target.Ref)
Expand Down Expand Up @@ -194,15 +195,16 @@ func (opt *hookOptions) executeRestoreHook() error {
Invoker: inv,
Target: targetInfo.Target.Ref,
ExecutorPod: kmapi.ObjectReference{
Namespace: opt.namespace,
Namespace: opt.targetRef.Namespace,
},
}

if opt.hookType == apis.PreRestoreHook {
hookExecutor.Hook = targetInfo.Hooks.PreRestore
hookExecutor.HookType = apis.PreRestoreHook
} else {
hookExecutor.Hook = targetInfo.Hooks.PostRestore
hookExecutor.Hook = targetInfo.Hooks.PostRestore.Handler
hookExecutor.ExecutionPolicy = targetInfo.Hooks.PostRestore.ExecutionPolicy
hookExecutor.HookType = apis.PostRestoreHook
}
hookExecutor.ExecutorPod.Name, err = opt.getHookExecutorPodName(targetInfo.Target.Ref)
Expand All @@ -225,23 +227,23 @@ func (opt *hookOptions) getHookExecutorPodName(targetRef v1beta1.TargetRef) (str
switch targetRef.Kind {
case apis.KindAppBinding:
// For AppBinding, we will execute the hooks in the respective app pod
return opt.getAppPodName(targetRef.Name)
return opt.getAppPodName()
default:
// For other types of target, hook will be executed where this process is running.
return meta.PodName(), nil
}
}

func (opt *hookOptions) getAppPodName(appbindingName string) (string, error) {
appbinding, err := opt.appClient.AppcatalogV1alpha1().AppBindings(opt.namespace).Get(context.TODO(), appbindingName, metav1.GetOptions{})
func (opt *hookOptions) getAppPodName() (string, error) {
appbinding, err := opt.appClient.AppcatalogV1alpha1().AppBindings(opt.targetRef.Namespace).Get(context.TODO(), opt.targetRef.Name, metav1.GetOptions{})
if err != nil {
return "", err
}

// AppBinding should have a Service in ClientConfig field. This service selects the app pod. We will execute the hooks in the app pod.
if appbinding.Spec.ClientConfig.Service != nil {
// there should be an endpoint with same name as the service which contains the name of the selected pods.
endPoint, err := opt.kubeClient.CoreV1().Endpoints(opt.namespace).Get(context.TODO(), appbinding.Spec.ClientConfig.Service.Name, metav1.GetOptions{})
endPoint, err := opt.kubeClient.CoreV1().Endpoints(opt.targetRef.Namespace).Get(context.TODO(), appbinding.Spec.ClientConfig.Service.Name, metav1.GetOptions{})
if err != nil {
return "", err
}
Expand All @@ -261,7 +263,7 @@ func (opt *hookOptions) getAppPodName(appbindingName string) (string, error) {
}
}
}
return "", fmt.Errorf("no pod found for AppBinding %s/%s", opt.namespace, appbindingName)
return "", fmt.Errorf("no pod found for AppBinding %s/%s", opt.targetRef.Namespace, opt.targetRef.Name)
}

func (opt *hookOptions) shouldFailContainer() bool {
Expand Down
Loading

0 comments on commit 98d3568

Please sign in to comment.