mirror of
https://github.com/rancher/norman.git
synced 2025-09-17 15:49:53 +00:00
Switch offspring controller to patch
This commit is contained in:
@@ -7,7 +7,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/rancher/norman/clientbase"
|
"github.com/rancher/norman/clientbase"
|
||||||
|
"github.com/rancher/norman/types/values"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -447,10 +450,10 @@ func (w *Reconciliation) updateObject(reference ObjectReference, oldObj runtime.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if data, changed := compareMaps(oldMeta.GetLabels(), newMeta.GetLabels()); changed {
|
if data, changed := compareMaps(oldMeta.GetLabels(), newMeta.GetLabels()); changed {
|
||||||
changes["labels"] = data
|
values.PutValue(changes, data, "metadata", "labels")
|
||||||
}
|
}
|
||||||
if data, changed := compareMaps(oldMeta.GetAnnotations(), newMeta.GetAnnotations()); changed {
|
if data, changed := compareMaps(oldMeta.GetAnnotations(), newMeta.GetAnnotations()); changed {
|
||||||
changes["annotations"] = data
|
values.PutValue(changes, data, "metadata", "annotations")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oldField := oldValue.FieldByName(key)
|
oldField := oldValue.FieldByName(key)
|
||||||
@@ -461,32 +464,23 @@ func (w *Reconciliation) updateObject(reference ObjectReference, oldObj runtime.
|
|||||||
oldField.Set(newField)
|
oldField.Set(newField)
|
||||||
changeName := jsonName(newValue, key)
|
changeName := jsonName(newValue, key)
|
||||||
if changeName != "-" {
|
if changeName != "-" {
|
||||||
changes[changeName] = newValue
|
changes[changeName] = newIValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(changes) > 0 {
|
if len(changes) > 0 {
|
||||||
//newObj := &unstructured.Unstructured{}
|
meta, err := apimeta.Accessor(oldObj)
|
||||||
//newObj.Object = changes
|
if err == nil {
|
||||||
//newMeta, err := apimeta.Accessor(newObj)
|
values.PutValue(changes, meta.GetResourceVersion(), "metadata", "resourceVersion")
|
||||||
//if err != nil {
|
}
|
||||||
// return nil, err
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//newTypeMeta, err := apimeta.TypeAccessor(newObj)
|
|
||||||
//if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//newMeta.SetName(reference.Name)
|
|
||||||
//newMeta.SetNamespace(reference.Namespace)
|
|
||||||
//newTypeMeta.SetKind(reference.Kind)
|
|
||||||
//newTypeMeta.SetAPIVersion(reference.APIVersion)
|
|
||||||
|
|
||||||
fmt.Println("!!!!!!!!!!!!!! UPDATE! !!!!!!!!!!!!!!")
|
data, err := json.Marshal(changes)
|
||||||
return client.Update(reference.Name, oldObj)
|
if err != nil {
|
||||||
|
return newObj, err
|
||||||
|
}
|
||||||
|
return client.Patch(reference.Name, oldObj, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return newObj, nil
|
return newObj, nil
|
||||||
|
Reference in New Issue
Block a user