Skip to content

Commit

Permalink
[INSTBS-21] fix(upgrade): skip update if manifest is not changed (#177)
Browse files Browse the repository at this point in the history
* chore(gitignore): ignore idea

* chore(Makefile): remove release-cli

* fix(upgrade): skip update if manifest is not changed
  • Loading branch information
Lei Qian authored Nov 19, 2020
1 parent 4e05653 commit d30b5c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ bin/
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
.vscode
.idea/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
ROOT := github.com/caicloud/rudder

# Target binaries. You can build multiple binaries for a single project.
TARGETS := controller release-cli
TARGETS := controller

# Container image prefix and suffix added to targets.
# The final built images are:
Expand Down
28 changes: 24 additions & 4 deletions pkg/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Client interface {
// Get gets the current object by resources.
Get(namespace string, resources []string, options GetOptions) ([]runtime.Object, error)
// Apply creates/updates all these resources.
Apply(namespace string, resources []string, options ApplyOptions) error
Apply(namespace string, newResources, oldResources []string, options ApplyOptions) error
// Create creates all these resources.
Create(namespace string, resources []string, options CreateOptions) error
// Update updates all resources.
Expand Down Expand Up @@ -126,17 +126,37 @@ func (c *client) Get(namespace string, resources []string, options GetOptions) (
}

// Apply creates/updates all these resources.
func (c *client) Apply(namespace string, resources []string, options ApplyOptions) error {
objs, err := c.objectsByOrder(resources, InstallOrder)
func (c *client) Apply(namespace string, newResources, oldResources []string, options ApplyOptions) error {
newObjects, err := c.objectsByOrder(newResources, InstallOrder)
if err != nil {
return err
}
for _, obj := range objs {
oldObjects, err := c.objectsByOrder(oldResources, InstallOrder)
if err != nil {
return err
}
for _, obj := range newObjects {

gvk := obj.GetObjectKind().GroupVersionKind()
accessor, err := c.codec.AccessorForObject(obj)
if err != nil {
return err
}

if namespace != "default" && namespace != "kube-system" {
skipped := false
for _, each := range oldObjects {
if reflect.DeepEqual(obj, each) {
skipped = true
break
}
}
if skipped {
glog.Infoln(gvk.Kind, namespace, accessor.GetName(), "same manifest, skip update")
continue
}
}

if options.OwnerReferences != nil &&
// options.Checker is used to check if the object is belong to current owner.
// If not, add owner references to obj.
Expand Down
3 changes: 2 additions & 1 deletion pkg/release/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
func (rc *releaseContext) applyRelease(backend storage.ReleaseStorage, release *releaseapi.Release) error {
// Deep copy release. Avoid modifying original release.
release = release.DeepCopy()
oldManifests := render.SplitManifest(release.Status.Manifest)

var manifests []string
if release.Spec.RollbackTo != nil {
Expand Down Expand Up @@ -122,7 +123,7 @@ func (rc *releaseContext) applyRelease(backend storage.ReleaseStorage, release *

}
// Apply resources.
if err := rc.client.Apply(release.Namespace, manifests, kube.ApplyOptions{
if err := rc.client.Apply(release.Namespace, manifests, oldManifests, kube.ApplyOptions{
OwnerReferences: referencesForRelease(release),
Checker: rc.ignore,
}); err != nil {
Expand Down

0 comments on commit d30b5c7

Please sign in to comment.