1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-25 14:46:57 +00:00

Fix update

This commit is contained in:
Darren Shepherd
2017-12-29 19:14:59 -07:00
parent 5f0c700068
commit b80039523f
2 changed files with 52 additions and 6 deletions

View File

@@ -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,

View File

@@ -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,15 +238,40 @@ 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) {
p.toInternal(schema.Mapper, data) if p.supportPatch {
p.toInternal(schema.Mapper, data)
namespace, id := splitID(id)
req := p.common(namespace, p.k8sClient.Patch(patchtype.StrategicMergePatchType)).
Body(&unstructured.Unstructured{
Object: data,
}).
Name(id).
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) namespace, id := splitID(id)
req := p.common(namespace, p.k8sClient.Patch(patchtype.StrategicMergePatchType)). values.PutValue(existing, resourceVersion, "metadata", "resourceVersion")
req := p.common(namespace, p.k8sClient.Put()).
Body(&unstructured.Unstructured{ Body(&unstructured.Unstructured{
Object: data, Object: existing,
}). }).
Name(id). Name(id)
SetHeader("Content-Type", string(patchtype.StrategicMergePatchType))
_, result, err := p.singleResult(apiContext, schema, req) _, result, err := p.singleResult(apiContext, schema, req)
return result, err return result, err