v3 compatibility: Fix `helmfile delete` to not fail when there was no release to be deleted
`helmfile delete` is designed to be idempotent. That is, it is safe to be run when there is nothing to delete. A change in helm v3 broke that behavior. This enhances Helmfile to be able to behave the same for helm v2 and v3.
This commit is contained in:
		
							parent
							
								
									30751e94f7
								
							
						
					
					
						commit
						fbbd7630e7
					
				| 
						 | 
					@ -133,6 +133,17 @@ func (helm *execer) List(context HelmContext, filter string, flags ...string) (s
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	out, err := helm.exec(append(append(preArgs, args...), flags...), env)
 | 
						out, err := helm.exec(append(append(preArgs, args...), flags...), env)
 | 
				
			||||||
 | 
						// In v2 we have been expecting `helm list FILTER` prints nothing.
 | 
				
			||||||
 | 
						// In v3 helm still prints the header like `NAME	NAMESPACE	REVISION	UPDATED	STATUS	CHART	APP VERSION`,
 | 
				
			||||||
 | 
						// which confuses helmfile's existing logic that treats any non-empty output from `helm list` is considered as the indication
 | 
				
			||||||
 | 
						// of the release to exist.
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// This fixes it by removing the header from the v3 output, so that the output is formatted the same as that of v2.
 | 
				
			||||||
 | 
						if helm.isHelm3() {
 | 
				
			||||||
 | 
							lines := strings.Split(string(out), "\n")
 | 
				
			||||||
 | 
							lines = lines[1:]
 | 
				
			||||||
 | 
							out = []byte(strings.Join(lines, "\n"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	helm.write(out)
 | 
						helm.write(out)
 | 
				
			||||||
	return string(out), err
 | 
						return string(out), err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue