Skip to content

Instantly share code, notes, and snippets.

@eriknelson
Created August 5, 2021 20:35
Show Gist options
  • Save eriknelson/9372f300b6e3952c3141a78dea5ee032 to your computer and use it in GitHub Desktop.
Save eriknelson/9372f300b6e3952c3141a78dea5ee032 to your computer and use it in GitHub Desktop.
diff --git a/plugins/service/service.go b/plugins/service/service.go
index 1673e23..66d62db 100644
--- a/plugins/service/service.go
+++ b/plugins/service/service.go
@@ -29,6 +29,14 @@ func Run(u *unstructured.Unstructured, extras map[string]string) (transform.Plug
if !IsServiceClusterIPNone(*u) {
patchJSON := fmt.Sprintf(`[
{ "op": "remove", "path": "/spec/clusterIP"}
+]`)
+ intPatch, err = jsonpatch.DecodePatch([]byte(patchJSON))
+ patch = append(patch, intPatch...)
+ }
+
+ if !IsServiceClusterIPNone(*u) {
+ patchJSON := fmt.Sprintf(`[
+{ "op": "remove", "path": "/spec/clusterIPs"}
]`)
intPatch, err = jsonpatch.DecodePatch([]byte(patchJSON))
patch = append(patch, intPatch...)
@@ -84,3 +92,25 @@ func IsServiceClusterIPNone(u unstructured.Unstructured) bool {
}
return clusterIP == "None"
}
+
+func IsServiceClusterIPsNone(u unstructured.Unstructured) bool {
+ if u.GetKind() != "Service" {
+ return false
+ }
+ // Get Spec
+ spec, ok := u.UnstructuredContent()["spec"]
+ if !ok {
+ return false
+ }
+
+ specMap, ok := spec.(map[string]interface{})
+ if !ok {
+ return false
+ }
+ // Get type
+ clusterIPs, ok := specMap["clusterIPs"]
+ if !ok {
+ return false
+ }
+ return clusterIPs == "None"
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment