Fix preapply hooks are not called on no diff when run apply subcommand (#522)
* Fix presync hooks are not called on no diff when run apply subcommand Signed-off-by: xiaomudk <xiaomudk@gmail.com> * Update docs/index.md Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com> Signed-off-by: xiaomudk <xiaomudk@gmail.com> Signed-off-by: xiaomudk <xiaomudk@gmail.com> Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
		
							parent
							
								
									70a1b3b513
								
							
						
					
					
						commit
						94381c1e17
					
				|  | @ -1240,7 +1240,7 @@ Hooks associated to `presync` events are triggered before each release is instal | ||||||
| This is the ideal event to execute any commands that may mutate the cluster state as it will not be run for read-only operations like `lint`, `diff` or `template`. | This is the ideal event to execute any commands that may mutate the cluster state as it will not be run for read-only operations like `lint`, `diff` or `template`. | ||||||
| 
 | 
 | ||||||
| `preapply` hooks are triggered before a release is uninstalled, installed, or upgraded as part of `helmfile apply`. | `preapply` hooks are triggered before a release is uninstalled, installed, or upgraded as part of `helmfile apply`. | ||||||
| This is the ideal event to hook into when you are going to use `helmfile apply` for every kind of change, and you want the hook to be called only when any kind of change is being made. | This is the ideal event to hook into when you are going to use `helmfile apply` for every kind of change and you want the hook to be triggered regardless of whether the releases have changed or not. Be sure to make each `preapply` hook command idempotent. Otherwise, rerunning helmfile-apply on a transient failure may end up either breaking your cluster, or the hook that runs for the second time will never succeed. | ||||||
| 
 | 
 | ||||||
| `preuninstall` hooks are triggered immediately before a release is uninstalled as part of `helmfile apply`, `helmfile sync`, `helmfile delete`, and `helmfile destroy`. | `preuninstall` hooks are triggered immediately before a release is uninstalled as part of `helmfile apply`, `helmfile sync`, `helmfile delete`, and `helmfile destroy`. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1354,30 +1354,20 @@ func (a *App) apply(r *Run, c ApplyConfigProvider) (bool, bool, []error) { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	for id := range releasesWithNoChange { | 	infoMsgStr := "" | ||||||
| 		r := releasesWithNoChange[id] |  | ||||||
| 		if _, err := st.TriggerCleanupEvent(&r, "apply"); err != nil { |  | ||||||
| 			a.Logger.Warnf("warn: %v\n", err) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if releasesToBeDeleted == nil && releasesToBeUpdated == nil { |  | ||||||
| 	if infoMsg != nil { | 	if infoMsg != nil { | ||||||
| 			logger := c.Logger() | 		infoMsgStr = *infoMsg | ||||||
| 			logger.Infof("") |  | ||||||
| 			logger.Infof(*infoMsg) |  | ||||||
| 		} |  | ||||||
| 		return true, false, nil |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	confMsg := fmt.Sprintf(`%s | 	confMsg := fmt.Sprintf(`%s | ||||||
| Do you really want to apply? | Do you really want to apply? | ||||||
|   Helmfile will apply all your changes, as shown above. |   Helmfile will apply all your changes, as shown above. | ||||||
| 
 | 
 | ||||||
| `, *infoMsg) | `, infoMsgStr) | ||||||
|  | 
 | ||||||
| 	interactive := c.Interactive() | 	interactive := c.Interactive() | ||||||
| 	if !interactive { | 	if !interactive && infoMsgStr != "" { | ||||||
| 		a.Logger.Debug(*infoMsg) | 		a.Logger.Debug(infoMsgStr) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	var applyErrs []error | 	var applyErrs []error | ||||||
|  | @ -1457,6 +1447,17 @@ Do you really want to apply? | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	affectedReleases.DisplayAffectedReleases(c.Logger()) | 	affectedReleases.DisplayAffectedReleases(c.Logger()) | ||||||
|  | 
 | ||||||
|  | 	for id := range releasesWithNoChange { | ||||||
|  | 		r := releasesWithNoChange[id] | ||||||
|  | 		if _, err := st.TriggerCleanupEvent(&r, "apply"); err != nil { | ||||||
|  | 			a.Logger.Warnf("warn: %v\n", err) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	if releasesToBeDeleted == nil && releasesToBeUpdated == nil { | ||||||
|  | 		return true, false, nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return true, true, applyErrs | 	return true, true, applyErrs | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -34,4 +34,11 @@ second-pass rendering result of "helmfile.yaml.part.0": | ||||||
| merged environment: &{default map[] map[]} | merged environment: &{default map[] map[]} | ||||||
| 2 release(s) found in helmfile.yaml | 2 release(s) found in helmfile.yaml | ||||||
| 
 | 
 | ||||||
|  | invoking preapply hooks for 2 groups of releases in this order: | ||||||
|  | GROUP RELEASES | ||||||
|  | 1     default//foo | ||||||
|  | 2     default//bar | ||||||
|  | 
 | ||||||
|  | invoking preapply hooks for releases in group 1/2: default//foo | ||||||
|  | invoking preapply hooks for releases in group 2/2: default//bar | ||||||
| changing working directory back to "/path/to" | changing working directory back to "/path/to" | ||||||
|  |  | ||||||
|  | @ -2,5 +2,8 @@ | ||||||
| hook[prepare] logs | foo | hook[prepare] logs | foo | ||||||
| hook[prepare] logs |  | hook[prepare] logs |  | ||||||
| 
 | 
 | ||||||
|  | hook[preapply] logs | foo | ||||||
|  | hook[preapply] logs |  | ||||||
|  | 
 | ||||||
| hook[cleanup] logs | foo | hook[cleanup] logs | foo | ||||||
| hook[cleanup] logs |  | hook[cleanup] logs |  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue