provider/kubernetes: Use PATCH to update namespace (#13114)

This commit is contained in:
Radek Simko 2017-04-10 15:01:40 +01:00 committed by GitHub
parent 50b13c3b9b
commit 81e184deeb
1 changed files with 8 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
pkgApi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
api "k8s.io/kubernetes/pkg/api/v1"
kubernetes "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5"
@ -69,15 +70,14 @@ func resourceKubernetesNamespaceRead(d *schema.ResourceData, meta interface{}) e
func resourceKubernetesNamespaceUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*kubernetes.Clientset)
metadata := expandMetadata(d.Get("metadata").([]interface{}))
// This is necessary in case the name is generated
metadata.Name = d.Id()
namespace := api.Namespace{
ObjectMeta: metadata,
ops := patchMetadata("metadata.0.", "/metadata/", d)
data, err := ops.MarshalJSON()
if err != nil {
return fmt.Errorf("Failed to marshal update operations: %s", err)
}
log.Printf("[INFO] Updating namespace: %#v", namespace)
out, err := conn.CoreV1().Namespaces().Update(&namespace)
log.Printf("[INFO] Updating namespace: %s", ops)
out, err := conn.CoreV1().Namespaces().Patch(d.Id(), pkgApi.JSONPatchType, data)
if err != nil {
return err
}