// runIntegrationHook runs integration provisioning hook, sets up all secrets and deletes hook and secret after completing
runIntegrationHook runs integration provisioning hook, sets up all secrets and deletes hook and secret after completing
// runIntegrationHook runs integration provisioning hook sets up all secrets and deletes hook and secret after completing
func (s *site) runIntegrationHook(ctx *operationContext, job *batchv1.Job, request app.HookRunRequest, secretParams secretParams) error {
	pack, err := secret(job.Name, job.Namespace, secretParams)
	if err != nil {
		return trace.Wrap(err)
	}
	request.Volumes = []v1.Volume{*pack.volume}
	request.VolumeMounts = []v1.VolumeMount{*pack.mount}
	request.ServiceUser = s.serviceUser()
	client, err := s.service.GetKubeClient()
	if err != nil {
		return trace.Wrap(err)
	}
	_, err = client.CoreV1().Secrets(pack.secret.Namespace).
		Create(context.TODO(), pack.secret, metav1.CreateOptions{})
	if err != nil {
		return rigging.ConvertError(err)
	}
	defer func() {
		err := client.CoreV1().Secrets(pack.secret.Namespace).Delete(
			context.TODO(), pack.secret.Name, metav1.DeleteOptions{})
		if err != nil {
			ctx.Warningf("Failed to delete secret: %v", trace.DebugReport(err))
		}
	}()
	ref, err := s.appService.StartAppHook(context.TODO(), request)
	if err != nil {
		ctx.RecordError("Failed to start hook: %v.", err)
		return trace.Wrap(err)
	}
	defer func() {
		err := s.appService.DeleteAppHookJob(context.TODO(), app.DeleteAppHookJobRequest{
			HookRef: *ref,
		})
		if err != nil {
			ctx.Warningf("Failed to delete hook job: %v.", trace.DebugReport(err))
		}
	}()
	go func() {
		err := s.appService.StreamAppHookLogs(context.TODO(), *ref, ctx.recorder)
		if err != nil {
			if err != io.EOF {
				ctx.Warningf("Failed to stream logs: %v.", trace.DebugReport(err))
			}
		}
	}()
	err = utils.Retry(defaults.RetryInterval, defaults.RetryLessAttempts, func() error {
		err = s.appService.WaitAppHook(context.TODO(), *ref)
		if err != nil {
			if !trace.IsConnectionProblem(err) {
				ctx.Infof("Failed to wait for hook completion: %v.", err)
				return utils.Abort(err)
			} else {
				return utils.Continue("got a connection problem, will continue waiting")
			}
		}
		return nil
	})
	if err != nil {
		ctx.RecordError("Hook failed to execute.")
		return trace.Wrap(err)
	}
	ctx.RecordInfo("Hook completed successfully.")
	return nil
}
func ( s * site ) runIntegrationHook ( ctx * operationContext , job * batchv1 . Job , request app . HookRunRequest , secretParams secretParams ) error { pack , err := secret ( job . Name , job . Namespace , secretParams ) if err != nil { return trace . Wrap ( err ) } request . Volumes = [ ] v1 . Volume { * pack . volume } request . VolumeMounts = [ ] v1 . VolumeMount { * pack . mount } request . ServiceUser = s . serviceUser ( ) client , err := s . service . GetKubeClient ( ) if err != nil { return trace . Wrap ( err ) } _ , err = client . CoreV1 ( ) . Secrets ( pack . secret . Namespace ) . Create ( context . TODO ( ) , pack . secret , metav1 . CreateOptions { } ) if err != nil { return rigging . ConvertError ( err ) } defer func ( ) { err := client . CoreV1 ( ) . Secrets ( pack . secret . Namespace ) . Delete ( context . TODO ( ) , pack . secret . Name , metav1 . DeleteOptions { } ) if err != nil { ctx . Warningf ( " " , trace . DebugReport ( err ) ) } } ( ) ref , err := s . appService . StartAppHook ( context . TODO ( ) , request ) if err != nil { ctx . RecordError ( " " , err ) return trace . Wrap ( err ) } defer func ( ) { err := s . appService . DeleteAppHookJob ( context . TODO ( ) , app . DeleteAppHookJobRequest { HookRef : * ref , } ) if err != nil { ctx . Warningf ( " " , trace . DebugReport ( err ) ) } } ( ) go func ( ) { err := s . appService . StreamAppHookLogs ( context . TODO ( ) , * ref , ctx . recorder ) if err != nil { if err != io . EOF { ctx . Warningf ( " " , trace . DebugReport ( err ) ) } } } ( ) err = utils . Retry ( defaults . RetryInterval , defaults . RetryLessAttempts , func ( ) error { err = s . appService . WaitAppHook ( context . TODO ( ) , * ref ) if err != nil { if ! trace . IsConnectionProblem ( err ) { ctx . Infof ( " " , err ) return utils . Abort ( err ) } else { return utils . Continue ( " " ) } } return nil } ) if err != nil { ctx . RecordError ( " " ) return trace . Wrap ( err ) } ctx . RecordInfo ( " " ) return nil }
runIntegrationHook runs integration provisioning hook, sets up all secrets and deletes hook and secret after completing
runIntegrationHook runs integration provisioning hook sets up all secrets and deletes hook and secret after completing
// create secret with credentials and setup volumes