mirror of
https://github.com/rancher/norman.git
synced 2025-09-25 22:54:28 +00:00
Fix update
This commit is contained in:
@@ -119,7 +119,7 @@ func (c *Store) AddSchemas(ctx context.Context, schemas ...*types.Schema) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
for schema, crd := range schemaStatus {
|
for schema, crd := range schemaStatus {
|
||||||
c.schemaStores[key(schema)] = proxy.NewProxyStore(c.k8sClient,
|
c.schemaStores[key(schema)] = proxy.NewProxyStoreForCRD(c.k8sClient,
|
||||||
[]string{"apis"},
|
[]string{"apis"},
|
||||||
crd.Spec.Group,
|
crd.Spec.Group,
|
||||||
crd.Spec.Version,
|
crd.Spec.Version,
|
||||||
|
@@ -37,12 +37,33 @@ type Store struct {
|
|||||||
kind string
|
kind string
|
||||||
resourcePlural string
|
resourcePlural string
|
||||||
authContext map[string]string
|
authContext map[string]string
|
||||||
|
supportPatch bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProxyStore(k8sClient rest.Interface,
|
func NewProxyStore(k8sClient rest.Interface,
|
||||||
prefix []string, group, version, kind, resourcePlural string) types.Store {
|
prefix []string, group, version, kind, resourcePlural string) types.Store {
|
||||||
return &errorStore{
|
return &errorStore{
|
||||||
Store: &Store{
|
Store: &Store{
|
||||||
|
supportPatch: true,
|
||||||
|
k8sClient: k8sClient,
|
||||||
|
prefix: prefix,
|
||||||
|
group: group,
|
||||||
|
version: version,
|
||||||
|
kind: kind,
|
||||||
|
resourcePlural: resourcePlural,
|
||||||
|
authContext: map[string]string{
|
||||||
|
"apiGroup": group,
|
||||||
|
"resource": resourcePlural,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewProxyStoreForCRD(k8sClient rest.Interface,
|
||||||
|
prefix []string, group, version, kind, resourcePlural string) types.Store {
|
||||||
|
return &errorStore{
|
||||||
|
Store: &Store{
|
||||||
|
supportPatch: false,
|
||||||
k8sClient: k8sClient,
|
k8sClient: k8sClient,
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
group: group,
|
group: group,
|
||||||
@@ -217,6 +238,7 @@ func (p *Store) toInternal(mapper types.Mapper, data map[string]interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
|
func (p *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
|
||||||
|
if p.supportPatch {
|
||||||
p.toInternal(schema.Mapper, data)
|
p.toInternal(schema.Mapper, data)
|
||||||
namespace, id := splitID(id)
|
namespace, id := splitID(id)
|
||||||
|
|
||||||
@@ -227,6 +249,30 @@ func (p *Store) Update(apiContext *types.APIContext, schema *types.Schema, data
|
|||||||
Name(id).
|
Name(id).
|
||||||
SetHeader("Content-Type", string(patchtype.StrategicMergePatchType))
|
SetHeader("Content-Type", string(patchtype.StrategicMergePatchType))
|
||||||
|
|
||||||
|
_, result, err := p.singleResult(apiContext, schema, req)
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceVersion, existing, err := p.byID(apiContext, schema, id)
|
||||||
|
if err != nil {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range data {
|
||||||
|
existing[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
p.toInternal(schema.Mapper, existing)
|
||||||
|
namespace, id := splitID(id)
|
||||||
|
|
||||||
|
values.PutValue(existing, resourceVersion, "metadata", "resourceVersion")
|
||||||
|
|
||||||
|
req := p.common(namespace, p.k8sClient.Put()).
|
||||||
|
Body(&unstructured.Unstructured{
|
||||||
|
Object: existing,
|
||||||
|
}).
|
||||||
|
Name(id)
|
||||||
|
|
||||||
_, result, err := p.singleResult(apiContext, schema, req)
|
_, result, err := p.singleResult(apiContext, schema, req)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user