Consider namespace when comparing resources

Fixes #6857

X-Cherry-Picked: 7f7e90b407
Signed-off-by: Mike Lundy <mike@fluffypenguin.org>
pull/8305/head
Fabian Ruff 5 years ago committed by Mike Lundy
parent 7606f0879c
commit 0c96138afa
No known key found for this signature in database
GPG Key ID: 0B40134B0A3E8BE3

@ -339,7 +339,7 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
err = perform(tinfos, func(info *resource.Info) error { err = perform(tinfos, func(info *resource.Info) error {
mux.Lock() mux.Lock()
defer mux.Unlock() defer mux.Unlock()
c.Log("Doing get for %s: %q", info.Mapping.GroupVersionKind.Kind, info.Name) c.Log("Doing get for %s: %q in %q", info.Mapping.GroupVersionKind.Kind, info.Name, info.Namespace)
if err := info.Get(); err != nil { if err := info.Get(); err != nil {
c.Log("WARNING: Failed Get for resource %q: %s", info.Name, err) c.Log("WARNING: Failed Get for resource %q: %s", info.Name, err)
missing = append(missing, fmt.Sprintf("%v\t\t%s", info.Mapping.Resource, info.Name)) missing = append(missing, fmt.Sprintf("%v\t\t%s", info.Mapping.Resource, info.Name))
@ -515,7 +515,7 @@ func (c *Client) UpdateWithOptions(namespace string, originalReader, targetReade
newlyCreatedResources = append(newlyCreatedResources, info) newlyCreatedResources = append(newlyCreatedResources, info)
kind := info.Mapping.GroupVersionKind.Kind kind := info.Mapping.GroupVersionKind.Kind
c.Log("Created a new %s called %q\n", kind, info.Name) c.Log("Created a new %s called %q in %s\n", kind, info.Name, info.Namespace)
return nil return nil
} }
@ -528,9 +528,10 @@ func (c *Client) UpdateWithOptions(namespace string, originalReader, targetReade
// See https://github.com/helm/helm/issues/1193 for more info. // See https://github.com/helm/helm/issues/1193 for more info.
if originalInfo == nil { if originalInfo == nil {
return fmt.Errorf( return fmt.Errorf(
"kind %s with the name %q already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart", "kind %s with the name %q in %q already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart",
info.Mapping.GroupVersionKind.Kind, info.Mapping.GroupVersionKind.Kind,
info.Name, info.Name,
info.Namespace,
) )
} }
@ -846,7 +847,7 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
return fmt.Errorf("failed to create patch: %s", err) return fmt.Errorf("failed to create patch: %s", err)
} }
if patch == nil { if patch == nil {
c.Log("Looks like there are no changes for %s %q", target.Mapping.GroupVersionKind.Kind, target.Name) c.Log("Looks like there are no changes for %s %q in %q", target.Mapping.GroupVersionKind.Kind, target.Name, target.Namespace)
// This needs to happen to make sure that tiller has the latest info from the API // This needs to happen to make sure that tiller has the latest info from the API
// Otherwise there will be no labels and other functions that use labels will panic // Otherwise there will be no labels and other functions that use labels will panic
if err := target.Get(); err != nil { if err := target.Get(); err != nil {
@ -859,20 +860,20 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
obj, err := helper.Patch(target.Namespace, target.Name, patchType, patch, nil) obj, err := helper.Patch(target.Namespace, target.Name, patchType, patch, nil)
if err != nil { if err != nil {
kind := target.Mapping.GroupVersionKind.Kind kind := target.Mapping.GroupVersionKind.Kind
log.Printf("Cannot patch %s: %q (%v)", kind, target.Name, err) log.Printf("Cannot patch %s: %q in %q (%v)", kind, target.Name, target.Namespace, err)
if force { if force {
// Attempt to delete... // Attempt to delete...
if err := deleteResource(target); err != nil { if err := deleteResource(target); err != nil {
return err return err
} }
log.Printf("Deleted %s: %q", kind, target.Name) log.Printf("Deleted %s: %q in %q", kind, target.Name, target.Namespace)
// ... and recreate // ... and recreate
if err := createResource(target); err != nil { if err := createResource(target); err != nil {
return fmt.Errorf("Failed to recreate resource: %s", err) return fmt.Errorf("Failed to recreate resource: %s", err)
} }
log.Printf("Created a new %s called %q\n", kind, target.Name) log.Printf("Created a new %s called %q in %s\n", kind, target.Name, target.Namespace)
// No need to refresh the target, as we recreated the resource based // No need to refresh the target, as we recreated the resource based
// on it. In addition, it might not exist yet and a call to `Refresh` // on it. In addition, it might not exist yet and a call to `Refresh`
@ -973,7 +974,7 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err
lw := cachetools.NewListWatchFromClient(info.Client, info.Mapping.Resource.Resource, info.Namespace, selector) lw := cachetools.NewListWatchFromClient(info.Client, info.Mapping.Resource.Resource, info.Namespace, selector)
kind := info.Mapping.GroupVersionKind.Kind kind := info.Mapping.GroupVersionKind.Kind
c.Log("Watching for changes to %s %s with timeout of %v", kind, info.Name, timeout) c.Log("Watching for changes to %s %s in %s with timeout of %v", kind, info.Name, info.Namespace, timeout)
// What we watch for depends on the Kind. // What we watch for depends on the Kind.
// - For a Job, we watch for completion. // - For a Job, we watch for completion.

@ -302,7 +302,7 @@ func TestUpdateNonManagedResourceError(t *testing.T) {
} }
if err := c.Update(v1.NamespaceDefault, objBody(&current), objBody(&target), false, false, 0, false); err != nil { if err := c.Update(v1.NamespaceDefault, objBody(&current), objBody(&target), false, false, 0, false); err != nil {
if err.Error() != "kind Pod with the name \"starfish\" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart" { if err.Error() != "kind Pod with the name \"starfish\" in \"default\" already exists in the cluster and wasn't defined in the previous release. Before upgrading, please either delete the resource from the cluster or remove it from the chart" {
t.Fatal(err) t.Fatal(err)
} }
} else { } else {

@ -83,5 +83,5 @@ func (r Result) Intersect(rs Result) Result {
// isMatchingInfo returns true if infos match on Name and GroupVersionKind. // isMatchingInfo returns true if infos match on Name and GroupVersionKind.
func isMatchingInfo(a, b *resource.Info) bool { func isMatchingInfo(a, b *resource.Info) bool {
return a.Name == b.Name && a.Mapping.GroupVersionKind.Kind == b.Mapping.GroupVersionKind.Kind return a.Name == b.Name && a.Namespace == b.Namespace && a.Mapping.GroupVersionKind.Kind == b.Mapping.GroupVersionKind.Kind
} }

Loading…
Cancel
Save