Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/kubernetes_service: Update external_ips correctly on K8S 1.8+ #127

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion kubernetes/resource_kubernetes_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,14 @@ func resourceKubernetesServiceUpdate(d *schema.ResourceData, meta interface{}) e

ops := patchMetadata("metadata.0.", "/metadata/", d)
if d.HasChange("spec") {
diffOps := patchServiceSpec("spec.0.", "/spec/", d)
serverVersion, err := conn.ServerVersion()
if err != nil {
return err
}
diffOps, err := patchServiceSpec("spec.0.", "/spec/", d, serverVersion)
if err != nil {
return err
}
ops = append(ops, diffOps...)
}
data, err := ops.MarshalJSON()
Expand Down
23 changes: 16 additions & 7 deletions kubernetes/structure_service_spec.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package kubernetes

import (
gversion "github.com/hashicorp/go-version"
"github.com/hashicorp/terraform/helper/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/pkg/api/v1"
)

Expand Down Expand Up @@ -141,7 +143,7 @@ func expandServiceSpec(l []interface{}) v1.ServiceSpec {

// Patch Ops

func patchServiceSpec(keyPrefix, pathPrefix string, d *schema.ResourceData) PatchOperations {
func patchServiceSpec(keyPrefix, pathPrefix string, d *schema.ResourceData, v *version.Info) (PatchOperations, error) {
ops := make([]PatchOperation, 0, 0)
if d.HasChange(keyPrefix + "selector") {
ops = append(ops, &ReplaceOperation{
Expand Down Expand Up @@ -180,11 +182,18 @@ func patchServiceSpec(keyPrefix, pathPrefix string, d *schema.ResourceData) Patc
})
}
if d.HasChange(keyPrefix + "external_ips") {
// If we haven't done this the deprecated field would have priority
ops = append(ops, &ReplaceOperation{
Path: pathPrefix + "deprecatedPublicIPs",
Value: nil,
})
k8sVersion, err := gversion.NewVersion(v.String())
if err != nil {
return nil, err
}
v1_8_0, _ := gversion.NewVersion("1.8.0")
if k8sVersion.LessThan(v1_8_0) {
// If we haven't done this the deprecated field would have priority
ops = append(ops, &ReplaceOperation{
Path: pathPrefix + "deprecatedPublicIPs",
Value: nil,
})
}

ops = append(ops, &ReplaceOperation{
Path: pathPrefix + "externalIPs",
Expand All @@ -197,5 +206,5 @@ func patchServiceSpec(keyPrefix, pathPrefix string, d *schema.ResourceData) Patc
Value: d.Get(keyPrefix + "external_name").(string),
})
}
return ops
return ops, nil
}