mirror of
https://github.com/niusmallnan/steve.git
synced 2025-09-09 09:00:31 +00:00
Update vendor
This commit is contained in:
94
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go
generated
vendored
94
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go
generated
vendored
@@ -5,9 +5,10 @@ import (
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rancher/wrangler/pkg/data/convert"
|
||||
patch2 "github.com/rancher/wrangler/pkg/patch"
|
||||
"github.com/sirupsen/logrus"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -19,23 +20,12 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/jsonmergepatch"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
)
|
||||
|
||||
const (
|
||||
LabelApplied = "objectset.rio.cattle.io/applied"
|
||||
)
|
||||
|
||||
var (
|
||||
patchCache = map[schema.GroupVersionKind]patchCacheEntry{}
|
||||
patchCacheLock = sync.Mutex{}
|
||||
)
|
||||
|
||||
type patchCacheEntry struct {
|
||||
patchType types.PatchType
|
||||
lookup strategicpatch.LookupPatchMeta
|
||||
}
|
||||
|
||||
func prepareObjectForCreate(gvk schema.GroupVersionKind, obj runtime.Object) (runtime.Object, error) {
|
||||
serialized, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
@@ -68,7 +58,7 @@ func prepareObjectForCreate(gvk schema.GroupVersionKind, obj runtime.Object) (ru
|
||||
}
|
||||
|
||||
func originalAndModified(gvk schema.GroupVersionKind, oldMetadata v1.Object, newObject runtime.Object) ([]byte, []byte, error) {
|
||||
original, err := getOriginal(gvk, oldMetadata)
|
||||
original, err := getOriginalBytes(gvk, oldMetadata)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -99,7 +89,7 @@ func emptyMaps(data map[string]interface{}, keys ...string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
data = toMapInterface(value)
|
||||
data = convert.ToMapInterface(value)
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -148,7 +138,6 @@ func applyPatch(gvk schema.GroupVersionKind, reconciler Reconciler, patcher Patc
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
current, err := json.Marshal(oldObject)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -172,12 +161,18 @@ func applyPatch(gvk schema.GroupVersionKind, reconciler Reconciler, patcher Patc
|
||||
return false, nil
|
||||
}
|
||||
|
||||
logrus.Debugf("DesiredSet - Patch %s %s/%s for %s -- [%s, %s, %s, %s]", gvk, oldMetadata.GetNamespace(), oldMetadata.GetName(), debugID, patch, original, modified, current)
|
||||
|
||||
if reconciler != nil {
|
||||
newObject, err := prepareObjectForCreate(gvk, newObject)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
handled, err := reconciler(oldObject, newObject)
|
||||
originalObject, err := getOriginalObject(gvk, oldMetadata)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
handled, err := reconciler(originalObject, newObject)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -186,9 +181,6 @@ func applyPatch(gvk schema.GroupVersionKind, reconciler Reconciler, patcher Patc
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("DesiredSet - Patch %s %s/%s for %s -- [%s, %s, %s, %s]", gvk, oldMetadata.GetNamespace(), oldMetadata.GetName(), debugID,
|
||||
patch, original, modified, current)
|
||||
|
||||
logrus.Debugf("DesiredSet - Updated %s %s/%s for %s -- %s %s", gvk, oldMetadata.GetNamespace(), oldMetadata.GetName(), debugID, patchType, patch)
|
||||
_, err = patcher(oldMetadata.GetNamespace(), oldMetadata.GetName(), patchType, patch)
|
||||
|
||||
@@ -216,7 +208,7 @@ func removeCreationTimestamp(data map[string]interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
data = toMapInterface(metadata)
|
||||
data = convert.ToMapInterface(metadata)
|
||||
if _, ok := data["creationTimestamp"]; ok {
|
||||
delete(data, "creationTimestamp")
|
||||
return true
|
||||
@@ -225,10 +217,10 @@ func removeCreationTimestamp(data map[string]interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func getOriginal(gvk schema.GroupVersionKind, obj v1.Object) ([]byte, error) {
|
||||
func getOriginalObject(gvk schema.GroupVersionKind, obj v1.Object) (runtime.Object, error) {
|
||||
original := appliedFromAnnotation(obj.GetAnnotations()[LabelApplied])
|
||||
if len(original) == 0 {
|
||||
return []byte("{}"), nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
mapObj := map[string]interface{}{}
|
||||
@@ -238,16 +230,19 @@ func getOriginal(gvk schema.GroupVersionKind, obj v1.Object) ([]byte, error) {
|
||||
}
|
||||
|
||||
removeCreationTimestamp(mapObj)
|
||||
|
||||
u := &unstructured.Unstructured{
|
||||
return prepareObjectForCreate(gvk, &unstructured.Unstructured{
|
||||
Object: mapObj,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
objCopy, err := prepareObjectForCreate(gvk, u)
|
||||
func getOriginalBytes(gvk schema.GroupVersionKind, obj v1.Object) ([]byte, error) {
|
||||
objCopy, err := getOriginalObject(gvk, obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if objCopy == nil {
|
||||
return []byte("{}"), nil
|
||||
}
|
||||
return json.Marshal(objCopy)
|
||||
}
|
||||
|
||||
@@ -295,7 +290,7 @@ func doPatch(gvk schema.GroupVersionKind, original, modified, current []byte) (t
|
||||
var patch []byte
|
||||
var lookupPatchMeta strategicpatch.LookupPatchMeta
|
||||
|
||||
patchType, lookupPatchMeta, err := getPatchStyle(gvk)
|
||||
patchType, lookupPatchMeta, err := patch2.GetMergeStyle(gvk)
|
||||
if err != nil {
|
||||
return patchType, nil, err
|
||||
}
|
||||
@@ -312,46 +307,3 @@ func doPatch(gvk schema.GroupVersionKind, original, modified, current []byte) (t
|
||||
|
||||
return patchType, patch, err
|
||||
}
|
||||
|
||||
func getPatchStyle(gvk schema.GroupVersionKind) (types.PatchType, strategicpatch.LookupPatchMeta, error) {
|
||||
var (
|
||||
patchType types.PatchType
|
||||
lookupPatchMeta strategicpatch.LookupPatchMeta
|
||||
)
|
||||
|
||||
patchCacheLock.Lock()
|
||||
entry, ok := patchCache[gvk]
|
||||
patchCacheLock.Unlock()
|
||||
|
||||
if ok {
|
||||
return entry.patchType, entry.lookup, nil
|
||||
}
|
||||
|
||||
versionedObject, err := scheme.Scheme.New(gvk)
|
||||
|
||||
if runtime.IsNotRegisteredError(err) {
|
||||
patchType = types.MergePatchType
|
||||
} else if err != nil {
|
||||
return patchType, nil, err
|
||||
} else {
|
||||
patchType = types.StrategicMergePatchType
|
||||
lookupPatchMeta, err = strategicpatch.NewPatchMetaFromStruct(versionedObject)
|
||||
if err != nil {
|
||||
return patchType, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
patchCacheLock.Lock()
|
||||
patchCache[gvk] = patchCacheEntry{
|
||||
patchType: patchType,
|
||||
lookup: lookupPatchMeta,
|
||||
}
|
||||
patchCacheLock.Unlock()
|
||||
|
||||
return patchType, lookupPatchMeta, nil
|
||||
}
|
||||
|
||||
func toMapInterface(obj interface{}) map[string]interface{} {
|
||||
v, _ := obj.(map[string]interface{})
|
||||
return v
|
||||
}
|
||||
|
4
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_crud.go
generated
vendored
4
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_crud.go
generated
vendored
@@ -51,8 +51,8 @@ func (o *desiredSet) get(nsed bool, namespace, name string, client dynamic.Names
|
||||
return client.Get(name, v1.GetOptions{})
|
||||
}
|
||||
|
||||
func (o *desiredSet) delete(nsed bool, namespace, name string, client dynamic.NamespaceableResourceInterface) error {
|
||||
if o.noDelete {
|
||||
func (o *desiredSet) delete(nsed bool, namespace, name string, client dynamic.NamespaceableResourceInterface, force bool) error {
|
||||
if o.noDelete && !force {
|
||||
return nil
|
||||
}
|
||||
opts := &v1.DeleteOptions{
|
||||
|
8
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_process.go
generated
vendored
8
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_process.go
generated
vendored
@@ -239,8 +239,8 @@ func (o *desiredSet) process(debugID string, set labels.Selector, gvk schema.Gro
|
||||
logrus.Debugf("DesiredSet - Created %s %s for %s", gvk, k, debugID)
|
||||
}
|
||||
|
||||
deleteF := func(k objectset.ObjectKey) {
|
||||
if err := o.delete(nsed, k.Namespace, k.Name, client); err != nil {
|
||||
deleteF := func(k objectset.ObjectKey, force bool) {
|
||||
if err := o.delete(nsed, k.Namespace, k.Name, client, force); err != nil {
|
||||
o.err(errors.Wrapf(err, "failed to delete %s %s for %s", k, gvk, debugID))
|
||||
return
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func (o *desiredSet) process(debugID string, set labels.Selector, gvk schema.Gro
|
||||
updateF := func(k objectset.ObjectKey) {
|
||||
err := o.compareObjects(gvk, patcher, client, debugID, existing[k], objs[k], len(toCreate) > 0 || len(toDelete) > 0)
|
||||
if err == ErrReplace {
|
||||
deleteF(k)
|
||||
deleteF(k, true)
|
||||
o.err(fmt.Errorf("DesiredSet - Replace Wait %s %s for %s", gvk, k, debugID))
|
||||
} else if err != nil {
|
||||
o.err(errors.Wrapf(err, "failed to update %s %s for %s", k, gvk, debugID))
|
||||
@@ -266,7 +266,7 @@ func (o *desiredSet) process(debugID string, set labels.Selector, gvk schema.Gro
|
||||
}
|
||||
|
||||
for _, k := range toDelete {
|
||||
deleteF(k)
|
||||
deleteF(k, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
83
vendor/github.com/rancher/wrangler/pkg/broadcast/generic.go
generated
vendored
Normal file
83
vendor/github.com/rancher/wrangler/pkg/broadcast/generic.go
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
package broadcast
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type ConnectFunc func() (chan interface{}, error)
|
||||
|
||||
type Broadcaster struct {
|
||||
sync.Mutex
|
||||
running bool
|
||||
subs map[chan interface{}]struct{}
|
||||
}
|
||||
|
||||
func (b *Broadcaster) Subscribe(ctx context.Context, connect ConnectFunc) (chan interface{}, error) {
|
||||
b.Lock()
|
||||
defer b.Unlock()
|
||||
|
||||
if !b.running {
|
||||
if err := b.start(connect); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
sub := make(chan interface{}, 100)
|
||||
if b.subs == nil {
|
||||
b.subs = map[chan interface{}]struct{}{}
|
||||
}
|
||||
b.subs[sub] = struct{}{}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
b.unsub(sub, true)
|
||||
}()
|
||||
|
||||
return sub, nil
|
||||
}
|
||||
|
||||
func (b *Broadcaster) unsub(sub chan interface{}, lock bool) {
|
||||
if lock {
|
||||
b.Lock()
|
||||
}
|
||||
if _, ok := b.subs[sub]; ok {
|
||||
close(sub)
|
||||
delete(b.subs, sub)
|
||||
}
|
||||
if lock {
|
||||
b.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Broadcaster) start(connect ConnectFunc) error {
|
||||
c, err := connect()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go b.stream(c)
|
||||
b.running = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Broadcaster) stream(input chan interface{}) {
|
||||
for item := range input {
|
||||
b.Lock()
|
||||
for sub := range b.subs {
|
||||
select {
|
||||
case sub <- item:
|
||||
default:
|
||||
// Slow consumer, drop
|
||||
go b.unsub(sub, true)
|
||||
}
|
||||
}
|
||||
b.Unlock()
|
||||
}
|
||||
|
||||
b.Lock()
|
||||
for sub := range b.subs {
|
||||
b.unsub(sub, false)
|
||||
}
|
||||
b.running = false
|
||||
b.Unlock()
|
||||
}
|
59
vendor/github.com/rancher/wrangler/pkg/condition/condition.go
generated
vendored
59
vendor/github.com/rancher/wrangler/pkg/condition/condition.go
generated
vendored
@@ -4,16 +4,16 @@ import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Cond string
|
||||
|
||||
func (c Cond) GetStatus(obj runtime.Object) string {
|
||||
func (c Cond) GetStatus(obj interface{}) string {
|
||||
return getStatus(obj, string(c))
|
||||
}
|
||||
|
||||
func (c Cond) SetError(obj runtime.Object, reason string, err error) {
|
||||
func (c Cond) SetError(obj interface{}, reason string, err error) {
|
||||
if err == nil {
|
||||
c.True(obj)
|
||||
c.Message(obj, "")
|
||||
@@ -28,7 +28,7 @@ func (c Cond) SetError(obj runtime.Object, reason string, err error) {
|
||||
c.Reason(obj, reason)
|
||||
}
|
||||
|
||||
func (c Cond) MatchesError(obj runtime.Object, reason string, err error) bool {
|
||||
func (c Cond) MatchesError(obj interface{}, reason string, err error) bool {
|
||||
if err == nil {
|
||||
return c.IsTrue(obj) &&
|
||||
c.GetMessage(obj) == "" &&
|
||||
@@ -42,11 +42,11 @@ func (c Cond) MatchesError(obj runtime.Object, reason string, err error) bool {
|
||||
c.GetReason(obj) == reason
|
||||
}
|
||||
|
||||
func (c Cond) SetStatus(obj runtime.Object, status string) {
|
||||
func (c Cond) SetStatus(obj interface{}, status string) {
|
||||
setStatus(obj, string(c), status)
|
||||
}
|
||||
|
||||
func (c Cond) SetStatusBool(obj runtime.Object, val bool) {
|
||||
func (c Cond) SetStatusBool(obj interface{}, val bool) {
|
||||
if val {
|
||||
setStatus(obj, string(c), "True")
|
||||
} else {
|
||||
@@ -54,52 +54,52 @@ func (c Cond) SetStatusBool(obj runtime.Object, val bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c Cond) True(obj runtime.Object) {
|
||||
func (c Cond) True(obj interface{}) {
|
||||
setStatus(obj, string(c), "True")
|
||||
}
|
||||
|
||||
func (c Cond) IsTrue(obj runtime.Object) bool {
|
||||
func (c Cond) IsTrue(obj interface{}) bool {
|
||||
return getStatus(obj, string(c)) == "True"
|
||||
}
|
||||
|
||||
func (c Cond) False(obj runtime.Object) {
|
||||
func (c Cond) False(obj interface{}) {
|
||||
setStatus(obj, string(c), "False")
|
||||
}
|
||||
|
||||
func (c Cond) IsFalse(obj runtime.Object) bool {
|
||||
func (c Cond) IsFalse(obj interface{}) bool {
|
||||
return getStatus(obj, string(c)) == "False"
|
||||
}
|
||||
|
||||
func (c Cond) Unknown(obj runtime.Object) {
|
||||
func (c Cond) Unknown(obj interface{}) {
|
||||
setStatus(obj, string(c), "Unknown")
|
||||
}
|
||||
|
||||
func (c Cond) IsUnknown(obj runtime.Object) bool {
|
||||
func (c Cond) IsUnknown(obj interface{}) bool {
|
||||
return getStatus(obj, string(c)) == "Unknown"
|
||||
}
|
||||
|
||||
func (c Cond) LastUpdated(obj runtime.Object, ts string) {
|
||||
func (c Cond) LastUpdated(obj interface{}, ts string) {
|
||||
setTS(obj, string(c), ts)
|
||||
}
|
||||
|
||||
func (c Cond) GetLastUpdated(obj runtime.Object) string {
|
||||
func (c Cond) GetLastUpdated(obj interface{}) string {
|
||||
return getTS(obj, string(c))
|
||||
}
|
||||
|
||||
func (c Cond) CreateUnknownIfNotExists(obj runtime.Object) {
|
||||
func (c Cond) CreateUnknownIfNotExists(obj interface{}) {
|
||||
condSlice := getValue(obj, "Status", "Conditions")
|
||||
cond := findCond(condSlice, string(c))
|
||||
cond := findCond(obj, condSlice, string(c))
|
||||
if cond == nil {
|
||||
c.Unknown(obj)
|
||||
}
|
||||
}
|
||||
|
||||
func (c Cond) Reason(obj runtime.Object, reason string) {
|
||||
func (c Cond) Reason(obj interface{}, reason string) {
|
||||
cond := findOrCreateCond(obj, string(c))
|
||||
getFieldValue(cond, "Reason").SetString(reason)
|
||||
}
|
||||
|
||||
func (c Cond) GetReason(obj runtime.Object) string {
|
||||
func (c Cond) GetReason(obj interface{}) string {
|
||||
cond := findOrNotCreateCond(obj, string(c))
|
||||
if cond == nil {
|
||||
return ""
|
||||
@@ -107,18 +107,18 @@ func (c Cond) GetReason(obj runtime.Object) string {
|
||||
return getFieldValue(*cond, "Reason").String()
|
||||
}
|
||||
|
||||
func (c Cond) SetMessageIfBlank(obj runtime.Object, message string) {
|
||||
func (c Cond) SetMessageIfBlank(obj interface{}, message string) {
|
||||
if c.GetMessage(obj) == "" {
|
||||
c.Message(obj, message)
|
||||
}
|
||||
}
|
||||
|
||||
func (c Cond) Message(obj runtime.Object, message string) {
|
||||
func (c Cond) Message(obj interface{}, message string) {
|
||||
cond := findOrCreateCond(obj, string(c))
|
||||
setValue(cond, "Message", message)
|
||||
}
|
||||
|
||||
func (c Cond) GetMessage(obj runtime.Object) string {
|
||||
func (c Cond) GetMessage(obj interface{}) string {
|
||||
cond := findOrNotCreateCond(obj, string(c))
|
||||
if cond == nil {
|
||||
return ""
|
||||
@@ -167,12 +167,15 @@ func setValue(cond reflect.Value, fieldName, newValue string) {
|
||||
|
||||
func findOrNotCreateCond(obj interface{}, condName string) *reflect.Value {
|
||||
condSlice := getValue(obj, "Status", "Conditions")
|
||||
return findCond(condSlice, condName)
|
||||
return findCond(obj, condSlice, condName)
|
||||
}
|
||||
|
||||
func findOrCreateCond(obj interface{}, condName string) reflect.Value {
|
||||
condSlice := getValue(obj, "Status", "Conditions")
|
||||
cond := findCond(condSlice, condName)
|
||||
if !condSlice.IsValid() {
|
||||
condSlice = getValue(obj, "Conditions")
|
||||
}
|
||||
cond := findCond(obj, condSlice, condName)
|
||||
if cond != nil {
|
||||
return *cond
|
||||
}
|
||||
@@ -181,10 +184,16 @@ func findOrCreateCond(obj interface{}, condName string) reflect.Value {
|
||||
newCond.FieldByName("Type").SetString(condName)
|
||||
newCond.FieldByName("Status").SetString("Unknown")
|
||||
condSlice.Set(reflect.Append(condSlice, newCond))
|
||||
return *findCond(condSlice, condName)
|
||||
return *findCond(obj, condSlice, condName)
|
||||
}
|
||||
|
||||
func findCond(val reflect.Value, name string) *reflect.Value {
|
||||
func findCond(obj interface{}, val reflect.Value, name string) *reflect.Value {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
logrus.Fatalf("failed to find .Status.Conditions field on %v", reflect.TypeOf(obj))
|
||||
}
|
||||
}()
|
||||
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
cond := val.Index(i)
|
||||
typeVal := getFieldValue(cond, "Type")
|
||||
|
2
vendor/github.com/rancher/wrangler/pkg/generic/controller.go
generated
vendored
2
vendor/github.com/rancher/wrangler/pkg/generic/controller.go
generated
vendored
@@ -199,7 +199,7 @@ func (c *Controller) enqueue(obj interface{}) {
|
||||
utilruntime.HandleError(err)
|
||||
return
|
||||
}
|
||||
c.workqueue.AddRateLimited(key)
|
||||
c.workqueue.Add(key)
|
||||
}
|
||||
|
||||
func (c *Controller) handleObject(obj interface{}) {
|
||||
|
19
vendor/github.com/rancher/wrangler/pkg/gvk/detect.go
generated
vendored
Normal file
19
vendor/github.com/rancher/wrangler/pkg/gvk/detect.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package gvk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
func Detect(obj []byte) (schema.GroupVersionKind, bool, error) {
|
||||
partial := v1.PartialObjectMetadata{}
|
||||
if err := json.Unmarshal(obj, &partial); err != nil {
|
||||
return schema.GroupVersionKind{}, false, err
|
||||
}
|
||||
|
||||
result := partial.GetObjectKind().GroupVersionKind()
|
||||
ok := result.Kind != "" && result.Version != ""
|
||||
return result, ok, nil
|
||||
}
|
5
vendor/github.com/rancher/wrangler/pkg/gvk/get.go
generated
vendored
5
vendor/github.com/rancher/wrangler/pkg/gvk/get.go
generated
vendored
@@ -3,6 +3,7 @@ package gvk
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rancher/wrangler/pkg/schemes"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
@@ -16,11 +17,11 @@ func Get(obj runtime.Object) (schema.GroupVersionKind, error) {
|
||||
|
||||
gvks, _, err := schemes.All.ObjectKinds(obj)
|
||||
if err != nil {
|
||||
return schema.GroupVersionKind{}, err
|
||||
return schema.GroupVersionKind{}, errors.Wrapf(err, "failed to find gvk for %T, you may need to import the wrangler generated controller package", obj)
|
||||
}
|
||||
|
||||
if len(gvks) == 0 {
|
||||
return schema.GroupVersionKind{}, fmt.Errorf("failed to find gvk for %v", obj.GetObjectKind())
|
||||
return schema.GroupVersionKind{}, fmt.Errorf("failed to find gvk for %T", obj)
|
||||
}
|
||||
|
||||
return gvks[0], nil
|
||||
|
3
vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go
generated
vendored
3
vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go
generated
vendored
@@ -5,6 +5,7 @@ import (
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rancher/wrangler/pkg/gvk"
|
||||
|
||||
"github.com/rancher/wrangler/pkg/merr"
|
||||
@@ -97,7 +98,7 @@ func (o *ObjectSet) add(obj runtime.Object) {
|
||||
|
||||
gvk, err := o.objects.Add(obj)
|
||||
if err != nil {
|
||||
o.err(fmt.Errorf("failed to add %v", obj))
|
||||
o.err(errors.Wrapf(err, "failed to add %T", obj))
|
||||
return
|
||||
}
|
||||
|
||||
|
57
vendor/github.com/rancher/wrangler/pkg/patch/apply.go
generated
vendored
Normal file
57
vendor/github.com/rancher/wrangler/pkg/patch/apply.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package patch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
)
|
||||
|
||||
func Apply(original, patch []byte) ([]byte, error) {
|
||||
style, metadata, err := GetPatchStyle(original, patch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch style {
|
||||
case types.JSONPatchType:
|
||||
return applyJSONPatch(original, patch)
|
||||
case types.MergePatchType:
|
||||
return applyMergePatch(original, patch)
|
||||
case types.StrategicMergePatchType:
|
||||
return applyStrategicMergePatch(original, patch, metadata)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid patch")
|
||||
}
|
||||
}
|
||||
|
||||
func applyStrategicMergePatch(original, patch []byte, lookup strategicpatch.LookupPatchMeta) ([]byte, error) {
|
||||
originalMap := map[string]interface{}{}
|
||||
patchMap := map[string]interface{}{}
|
||||
if err := json.Unmarshal(original, &originalMap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := json.Unmarshal(patch, &patchMap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
patchedMap, err := strategicpatch.StrategicMergeMapPatch(originalMap, patchMap, lookup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(patchedMap)
|
||||
}
|
||||
|
||||
func applyMergePatch(original, patch []byte) ([]byte, error) {
|
||||
return jsonpatch.MergePatch(original, patch)
|
||||
}
|
||||
|
||||
func applyJSONPatch(original, patch []byte) ([]byte, error) {
|
||||
jsonPatch, err := jsonpatch.DecodePatch(patch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return jsonPatch.Apply(original)
|
||||
}
|
79
vendor/github.com/rancher/wrangler/pkg/patch/style.go
generated
vendored
Normal file
79
vendor/github.com/rancher/wrangler/pkg/patch/style.go
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
package patch
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/rancher/wrangler/pkg/gvk"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
)
|
||||
|
||||
var (
|
||||
patchCache = map[schema.GroupVersionKind]patchCacheEntry{}
|
||||
patchCacheLock = sync.Mutex{}
|
||||
)
|
||||
|
||||
type patchCacheEntry struct {
|
||||
patchType types.PatchType
|
||||
lookup strategicpatch.LookupPatchMeta
|
||||
}
|
||||
|
||||
func isJSONPatch(patch []byte) bool {
|
||||
// a JSON patch is a list
|
||||
return len(patch) > 0 && patch[0] == '['
|
||||
}
|
||||
|
||||
func GetPatchStyle(original, patch []byte) (types.PatchType, strategicpatch.LookupPatchMeta, error) {
|
||||
if isJSONPatch(patch) {
|
||||
return types.JSONPatchType, nil, nil
|
||||
}
|
||||
gvk, ok, err := gvk.Detect(original)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
if !ok {
|
||||
return types.MergePatchType, nil, nil
|
||||
}
|
||||
return GetMergeStyle(gvk)
|
||||
}
|
||||
|
||||
func GetMergeStyle(gvk schema.GroupVersionKind) (types.PatchType, strategicpatch.LookupPatchMeta, error) {
|
||||
var (
|
||||
patchType types.PatchType
|
||||
lookupPatchMeta strategicpatch.LookupPatchMeta
|
||||
)
|
||||
|
||||
patchCacheLock.Lock()
|
||||
entry, ok := patchCache[gvk]
|
||||
patchCacheLock.Unlock()
|
||||
|
||||
if ok {
|
||||
return entry.patchType, entry.lookup, nil
|
||||
}
|
||||
|
||||
versionedObject, err := scheme.Scheme.New(gvk)
|
||||
|
||||
if runtime.IsNotRegisteredError(err) {
|
||||
patchType = types.MergePatchType
|
||||
} else if err != nil {
|
||||
return patchType, nil, err
|
||||
} else {
|
||||
patchType = types.StrategicMergePatchType
|
||||
lookupPatchMeta, err = strategicpatch.NewPatchMetaFromStruct(versionedObject)
|
||||
if err != nil {
|
||||
return patchType, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
patchCacheLock.Lock()
|
||||
patchCache[gvk] = patchCacheEntry{
|
||||
patchType: patchType,
|
||||
lookup: lookupPatchMeta,
|
||||
}
|
||||
patchCacheLock.Unlock()
|
||||
|
||||
return patchType, lookupPatchMeta, nil
|
||||
}
|
15
vendor/github.com/rancher/wrangler/pkg/schemas/reflection.go
generated
vendored
15
vendor/github.com/rancher/wrangler/pkg/schemas/reflection.go
generated
vendored
@@ -70,7 +70,18 @@ func (s *Schemas) Import(obj interface{}, externalOverrides ...interface{}) (*Sc
|
||||
types = append(types, reflect.TypeOf(override))
|
||||
}
|
||||
|
||||
return s.importType(reflect.TypeOf(obj), types...)
|
||||
var (
|
||||
v = reflect.ValueOf(obj)
|
||||
t reflect.Type
|
||||
)
|
||||
|
||||
if v.Kind() == reflect.Ptr {
|
||||
t = v.Elem().Type()
|
||||
} else {
|
||||
t = v.Type()
|
||||
}
|
||||
|
||||
return s.importType(t, types...)
|
||||
}
|
||||
|
||||
func (s *Schemas) newSchemaFromType(t reflect.Type, typeName string) (*Schema, error) {
|
||||
@@ -245,6 +256,8 @@ func (s *Schemas) readFields(schema *Schema, t reflect.Type) error {
|
||||
|
||||
schemaField := Field{
|
||||
CodeName: field.Name,
|
||||
Create: true,
|
||||
Update: true,
|
||||
}
|
||||
|
||||
fieldType := field.Type
|
||||
|
2
vendor/github.com/rancher/wrangler/pkg/summary/summarizers.go
generated
vendored
2
vendor/github.com/rancher/wrangler/pkg/summary/summarizers.go
generated
vendored
@@ -44,11 +44,13 @@ var (
|
||||
"Saved": "saving",
|
||||
"Updated": "updating",
|
||||
"Updating": "updating",
|
||||
"Upgraded": "upgrading",
|
||||
"Waiting": "waiting",
|
||||
"InitialRolesPopulated": "activating",
|
||||
"ScalingActive": "pending",
|
||||
"AbleToScale": "pending",
|
||||
"RunCompleted": "running",
|
||||
"Processed": "processed",
|
||||
}
|
||||
|
||||
// True == error
|
||||
|
20
vendor/github.com/rancher/wrangler/pkg/summary/summary.go
generated
vendored
20
vendor/github.com/rancher/wrangler/pkg/summary/summary.go
generated
vendored
@@ -14,6 +14,25 @@ type Summary struct {
|
||||
Message []string
|
||||
}
|
||||
|
||||
func dedupMessage(messages []string) []string {
|
||||
if len(messages) <= 1 {
|
||||
return messages
|
||||
}
|
||||
|
||||
seen := map[string]bool{}
|
||||
var result []string
|
||||
|
||||
for _, message := range messages {
|
||||
if seen[message] {
|
||||
continue
|
||||
}
|
||||
seen[message] = true
|
||||
result = append(result, message)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func Summarize(unstr *unstructured.Unstructured) Summary {
|
||||
var (
|
||||
obj data.Object
|
||||
@@ -35,5 +54,6 @@ func Summarize(unstr *unstructured.Unstructured) Summary {
|
||||
}
|
||||
|
||||
summary.State = strings.ToLower(summary.State)
|
||||
summary.Message = dedupMessage(summary.Message)
|
||||
return summary
|
||||
}
|
||||
|
Reference in New Issue
Block a user