Merge pull request #3131 from fgimenez/fix-2745

check if resource is present before adding it to remaining or keep on deletion
pull/3222/head
Taylor Thomas 7 years ago committed by GitHub
commit 04769b7c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -53,6 +53,11 @@ import (
"k8s.io/kubernetes/pkg/printers"
)
const (
// MissingGetHeader is added to Get's outout when a resource is not found.
MissingGetHeader = "==> MISSING\nKIND\t\tNAME\n"
)
// ErrNoObjectsVisited indicates that during a visit operation, no matching objects were found.
var ErrNoObjectsVisited = goerrors.New("no objects visited")
@ -217,7 +222,7 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
}
}
if len(missing) > 0 {
buf.WriteString("==> MISSING\nKIND\t\tNAME\n")
buf.WriteString(MissingGetHeader)
for _, s := range missing {
fmt.Fprintln(buf, s)
}

@ -161,7 +161,7 @@ func DeleteRelease(rel *release.Release, vs chartutil.VersionSet, kubeClient env
filesToKeep, filesToDelete := filterManifestsToKeep(files)
if len(filesToKeep) > 0 {
kept = summarizeKeptManifests(filesToKeep)
kept = summarizeKeptManifests(filesToKeep, kubeClient, rel.Namespace)
}
errs = []error{}

@ -17,7 +17,11 @@ limitations under the License.
package tiller
import (
"bytes"
"strings"
"k8s.io/helm/pkg/kube"
"k8s.io/helm/pkg/tiller/environment"
)
// resourcePolicyAnno is the annotation name for a resource policy
@ -34,7 +38,6 @@ func filterManifestsToKeep(manifests []Manifest) ([]Manifest, []Manifest) {
keep := []Manifest{}
for _, m := range manifests {
if m.Head.Metadata == nil || m.Head.Metadata.Annotations == nil || len(m.Head.Metadata.Annotations) == 0 {
remaining = append(remaining, m)
continue
@ -55,10 +58,19 @@ func filterManifestsToKeep(manifests []Manifest) ([]Manifest, []Manifest) {
return keep, remaining
}
func summarizeKeptManifests(manifests []Manifest) string {
message := "These resources were kept due to the resource policy:\n"
func summarizeKeptManifests(manifests []Manifest, kubeClient environment.KubeClient, namespace string) string {
var message string
for _, m := range manifests {
// check if m is in fact present from k8s client's POV.
output, err := kubeClient.Get(namespace, bytes.NewBufferString(m.Content))
if err != nil || strings.Contains(output, kube.MissingGetHeader) {
continue
}
details := "[" + m.Head.Kind + "] " + m.Head.Metadata.Name + "\n"
if message == "" {
message = "These resources were kept due to the resource policy:\n"
}
message = message + details
}
return message

Loading…
Cancel
Save