diff --git a/.gitignore b/.gitignore index 25fbff6f..4581eda9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ bin/ # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ .vscode +.idea/ diff --git a/Makefile b/Makefile index 2867b3bf..20cb82ea 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 32af6af2..a8dc3d9a 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -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. @@ -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. diff --git a/pkg/release/apply.go b/pkg/release/apply.go index b46ea8f3..6b993787 100644 --- a/pkg/release/apply.go +++ b/pkg/release/apply.go @@ -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 { @@ -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 {