From 12425c4adb66729b101351def866df9b785b9645 Mon Sep 17 00:00:00 2001 From: jennybuckley Date: Wed, 28 Nov 2018 13:47:55 -0800 Subject: [PATCH] update generated --- Godeps/LICENSES | 209 ++++++++++++++++++ .../src/k8s.io/apiserver/Godeps/Godeps.json | 4 + .../pkg/endpoints/handlers/apply/BUILD | 6 + vendor/BUILD | 1 + .../structured-merge-diff/merge/BUILD | 30 +++ .../structured-merge-diff/merge/conflict.go | 91 ++++++++ .../structured-merge-diff/merge/update.go | 137 ++++++++++++ 7 files changed, 478 insertions(+) create mode 100644 vendor/sigs.k8s.io/structured-merge-diff/merge/BUILD create mode 100644 vendor/sigs.k8s.io/structured-merge-diff/merge/conflict.go create mode 100644 vendor/sigs.k8s.io/structured-merge-diff/merge/update.go diff --git a/Godeps/LICENSES b/Godeps/LICENSES index 7267c409f10..042780ff87f 100644 --- a/Godeps/LICENSES +++ b/Godeps/LICENSES @@ -112945,6 +112945,215 @@ third-party archives. ================================================================================ +================================================================================ += vendor/sigs.k8s.io/structured-merge-diff/merge licensed under: = + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + += vendor/sigs.k8s.io/structured-merge-diff/LICENSE e3fc50a88d0a364313df4b21ef20c29e +================================================================================ + + ================================================================================ = vendor/sigs.k8s.io/structured-merge-diff/schema licensed under: = diff --git a/staging/src/k8s.io/apiserver/Godeps/Godeps.json b/staging/src/k8s.io/apiserver/Godeps/Godeps.json index 2c1c90da4f6..3a551d4957f 100644 --- a/staging/src/k8s.io/apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/apiserver/Godeps/Godeps.json @@ -2050,6 +2050,10 @@ "ImportPath": "sigs.k8s.io/structured-merge-diff/fieldpath", "Rev": "01332b709372d8d83b4d7653b30a1961680a47d5" }, + { + "ImportPath": "sigs.k8s.io/structured-merge-diff/merge", + "Rev": "01332b709372d8d83b4d7653b30a1961680a47d5" + }, { "ImportPath": "sigs.k8s.io/structured-merge-diff/schema", "Rev": "01332b709372d8d83b4d7653b30a1961680a47d5" diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/apply/BUILD b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/apply/BUILD index 6a880bb5d1a..0ef91ca5b15 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/apply/BUILD +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/apply/BUILD @@ -7,6 +7,7 @@ go_library( "encode.go", "gvkparser.go", "typeconverter.go", + "versionconverter.go", ], importmap = "k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/endpoints/handlers/apply", importpath = "k8s.io/apiserver/pkg/endpoints/handlers/apply", @@ -19,6 +20,7 @@ go_library( "//vendor/k8s.io/kube-openapi/pkg/schemaconv:go_default_library", "//vendor/k8s.io/kube-openapi/pkg/util/proto:go_default_library", "//vendor/sigs.k8s.io/structured-merge-diff/fieldpath:go_default_library", + "//vendor/sigs.k8s.io/structured-merge-diff/merge:go_default_library", "//vendor/sigs.k8s.io/structured-merge-diff/typed:go_default_library", "//vendor/sigs.k8s.io/structured-merge-diff/value:go_default_library", ], @@ -30,15 +32,19 @@ go_test( "decode_test.go", "roundtrip_test.go", "typeconverter_test.go", + "versionconverter_test.go", ], data = ["//api/openapi-spec:swagger-spec"], embed = [":go_default_library"], deps = [ "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/github.com/ghodss/yaml:go_default_library", "//vendor/k8s.io/kube-openapi/pkg/util/proto:go_default_library", "//vendor/k8s.io/kube-openapi/pkg/util/proto/testing:go_default_library", + "//vendor/sigs.k8s.io/structured-merge-diff/fieldpath:go_default_library", ], ) diff --git a/vendor/BUILD b/vendor/BUILD index ad96438822d..56c9359f936 100644 --- a/vendor/BUILD +++ b/vendor/BUILD @@ -469,6 +469,7 @@ filegroup( "//vendor/k8s.io/utils/exec:all-srcs", "//vendor/k8s.io/utils/pointer:all-srcs", "//vendor/sigs.k8s.io/structured-merge-diff/fieldpath:all-srcs", + "//vendor/sigs.k8s.io/structured-merge-diff/merge:all-srcs", "//vendor/sigs.k8s.io/structured-merge-diff/schema:all-srcs", "//vendor/sigs.k8s.io/structured-merge-diff/typed:all-srcs", "//vendor/sigs.k8s.io/structured-merge-diff/value:all-srcs", diff --git a/vendor/sigs.k8s.io/structured-merge-diff/merge/BUILD b/vendor/sigs.k8s.io/structured-merge-diff/merge/BUILD new file mode 100644 index 00000000000..498b255b8f7 --- /dev/null +++ b/vendor/sigs.k8s.io/structured-merge-diff/merge/BUILD @@ -0,0 +1,30 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "conflict.go", + "update.go", + ], + importmap = "k8s.io/kubernetes/vendor/sigs.k8s.io/structured-merge-diff/merge", + importpath = "sigs.k8s.io/structured-merge-diff/merge", + visibility = ["//visibility:public"], + deps = [ + "//vendor/sigs.k8s.io/structured-merge-diff/fieldpath:go_default_library", + "//vendor/sigs.k8s.io/structured-merge-diff/typed:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/vendor/sigs.k8s.io/structured-merge-diff/merge/conflict.go b/vendor/sigs.k8s.io/structured-merge-diff/merge/conflict.go new file mode 100644 index 00000000000..1056037b83c --- /dev/null +++ b/vendor/sigs.k8s.io/structured-merge-diff/merge/conflict.go @@ -0,0 +1,91 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package merge + +import ( + "fmt" + "sort" + "strings" + + "sigs.k8s.io/structured-merge-diff/fieldpath" +) + +// Conflict is a conflict on a specific field with the current manager of +// that field. It does implement the error interface so that it can be +// used as an error. +type Conflict struct { + Manager string + Path fieldpath.Path +} + +// Conflict is an error. +var _ error = Conflict{} + +// Error formats the conflict as an error. +func (c Conflict) Error() string { + return fmt.Sprintf("conflict with %q: %v", c.Manager, c.Path) +} + +// Conflicts accumulates multiple conflicts and aggregates them by managers. +type Conflicts []Conflict + +var _ error = Conflicts{} + +// Error prints the list of conflicts, grouped by sorted managers. +func (conflicts Conflicts) Error() string { + if len(conflicts) == 1 { + return conflicts[0].Error() + } + + m := map[string][]fieldpath.Path{} + for _, conflict := range conflicts { + m[conflict.Manager] = append(m[conflict.Manager], conflict.Path) + } + + managers := []string{} + for manager := range m { + managers = append(managers, manager) + } + + // Print conflicts by sorted managers. + sort.Strings(managers) + + messages := []string{} + for _, manager := range managers { + messages = append(messages, fmt.Sprintf("conflicts with %q:", manager)) + for _, path := range m[manager] { + messages = append(messages, fmt.Sprintf("- %v", path)) + } + } + return strings.Join(messages, "\n") +} + +// ConflictsFromManagers creates a list of conflicts given Managers sets. +func ConflictsFromManagers(sets fieldpath.ManagedFields) Conflicts { + conflicts := []Conflict{} + + for manager, set := range sets { + set.Iterate(func(p fieldpath.Path) { + conflicts = append(conflicts, Conflict{ + Manager: manager, + Path: p, + }) + }) + } + + return conflicts +} diff --git a/vendor/sigs.k8s.io/structured-merge-diff/merge/update.go b/vendor/sigs.k8s.io/structured-merge-diff/merge/update.go new file mode 100644 index 00000000000..bbcbbeedd9e --- /dev/null +++ b/vendor/sigs.k8s.io/structured-merge-diff/merge/update.go @@ -0,0 +1,137 @@ +/* +Copyright 2018 The Kubernetes Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package merge + +import ( + "fmt" + + "sigs.k8s.io/structured-merge-diff/fieldpath" + "sigs.k8s.io/structured-merge-diff/typed" +) + +// Converter is an interface to the conversion logic. The converter +// needs to be able to convert objects from one version to another. +type Converter interface { + Convert(object typed.TypedValue, version fieldpath.APIVersion) (typed.TypedValue, error) +} + +// Updater is the object used to compute updated FieldSets and also +// merge the object on Apply. +type Updater struct { + Converter Converter +} + +func (s *Updater) update(oldObject, newObject typed.TypedValue, managers fieldpath.ManagedFields, workflow string, force bool) (fieldpath.ManagedFields, error) { + if managers == nil { + managers = fieldpath.ManagedFields{} + } + conflicts := fieldpath.ManagedFields{} + type Versioned struct { + oldObject typed.TypedValue + newObject typed.TypedValue + } + versions := map[fieldpath.APIVersion]Versioned{} + + for manager, managerSet := range managers { + if manager == workflow { + continue + } + versioned, ok := versions[managerSet.APIVersion] + if !ok { + var err error + versioned.oldObject, err = s.Converter.Convert(oldObject, managerSet.APIVersion) + if err != nil { + return nil, fmt.Errorf("failed to convert old object: %v", err) + } + versioned.newObject, err = s.Converter.Convert(newObject, managerSet.APIVersion) + if err != nil { + return nil, fmt.Errorf("failed to convert new object: %v", err) + } + versions[managerSet.APIVersion] = versioned + } + compare, err := versioned.oldObject.Compare(versioned.newObject) + if err != nil { + return nil, fmt.Errorf("failed to compare objects: %v", err) + } + + conflictSet := managerSet.Intersection(compare.Modified.Union(compare.Added)) + if !conflictSet.Empty() { + conflicts[manager] = &fieldpath.VersionedSet{ + Set: conflictSet, + APIVersion: managerSet.APIVersion, + } + } + } + + if !force && len(conflicts) != 0 { + return nil, ConflictsFromManagers(conflicts) + } + + for manager, conflictSet := range conflicts { + managers[manager].Set = managers[manager].Set.Difference(conflictSet.Set) + } + + return managers, nil +} + +// Update is the method you should call once you've merged your final +// object on CREATE/UPDATE/PATCH verbs. newObject must be the object +// that you intend to persist (after applying the patch if this is for a +// PATCH call), and liveObject must be the original object (empty if +// this is a CREATE call). +func (s *Updater) Update(liveObject, newObject typed.TypedValue, managers fieldpath.ManagedFields, manager string) (fieldpath.ManagedFields, error) { + var err error + managers, err = s.update(liveObject, newObject, managers, manager, true) + if err != nil { + return fieldpath.ManagedFields{}, err + } + compare, err := liveObject.Compare(newObject) + if err != nil { + return fieldpath.ManagedFields{}, fmt.Errorf("failed to compare live and new objects: %v", err) + } + if _, ok := managers[manager]; !ok { + managers[manager] = &fieldpath.VersionedSet{ + Set: fieldpath.NewSet(), + } + } + managers[manager].Set = managers[manager].Set.Union(compare.Modified).Union(compare.Added).Difference(compare.Removed) + managers[manager].APIVersion = fieldpath.APIVersion("v1") // TODO: We don't support multiple versions yet. + return managers, nil +} + +// Apply should be called when Apply is run, given the current object as +// well as the configuration that is applied. This will merge the object +// and return it. +func (s *Updater) Apply(liveObject, configObject typed.TypedValue, managers fieldpath.ManagedFields, manager string, force bool) (typed.TypedValue, fieldpath.ManagedFields, error) { + newObject, err := liveObject.Merge(configObject) + if err != nil { + return typed.TypedValue{}, fieldpath.ManagedFields{}, fmt.Errorf("failed to merge config: %v", err) + } + managers, err = s.update(liveObject, newObject, managers, manager, force) + if err != nil { + return typed.TypedValue{}, fieldpath.ManagedFields{}, err + } + + // TODO: Remove unconflicting removed fields + + set, err := configObject.ToFieldSet() + if err != nil { + return typed.TypedValue{}, fieldpath.ManagedFields{}, fmt.Errorf("failed to get field set: %v", err) + } + managers[manager] = &fieldpath.VersionedSet{ + Set: set, + APIVersion: fieldpath.APIVersion("v1"), // TODO: We don't support multiple versions yet. + } + return newObject, managers, nil +}