Skip to content

Commit

Permalink
Merge pull request #75 from flanksource/fix-apply
Browse files Browse the repository at this point in the history
fix: apply on loadbalancer services
  • Loading branch information
moshloop authored Sep 19, 2021
2 parents a1f7783 + 8344fee commit e44afa9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,24 @@ func (c *Client) copyImmutable(from, to *unstructured.Unstructured) {
}
if IsService(to) {
spec := to.Object["spec"].(map[string]interface{})
spec["clusterIP"] = from.Object["spec"].(map[string]interface{})["clusterIP"]
spec["type"] = from.Object["spec"].(map[string]interface{})["type"]
spec["sessionAffinity"] = from.Object["spec"].(map[string]interface{})["sessionAffinity"]
fromSpec := from.Object["spec"].(map[string]interface{})
spec["clusterIP"] = fromSpec["clusterIP"]
spec["type"] = fromSpec["type"]
spec["sessionAffinity"] = fromSpec["sessionAffinity"]
if fromSpec["healthCheckNodePort"] != nil {
spec["healthCheckNodePort"] = fromSpec["healthCheckNodePort"]
}
spec["clusterIPs"] = fromSpec["clusterIPs"]

if fromSpec["type"] == "LoadBalancer" {
ports := spec["ports"].([]interface{})
fromPorts := fromSpec["ports"].([]interface{})
for i, port := range ports {
if fromPorts[i].(map[string]interface{})["nodePort"] != nil {
port.(map[string]interface{})["nodePort"] = fromPorts[i].(map[string]interface{})["nodePort"]
}
}
}

} else if IsServiceAccount(to) {
to.Object["secrets"] = from.Object["secrets"]
Expand Down Expand Up @@ -66,6 +81,7 @@ func (c *Client) copyImmutable(from, to *unstructured.Unstructured) {
to.SetUID(from.GetUID())
to.SetCreationTimestamp(from.GetCreationTimestamp())
to.SetGeneration(from.GetGeneration())
to.SetFinalizers(from.GetFinalizers())
}

// Sanitize will remove "runtime" fields from objects that woulds otherwise increase the verbosity of diffs
Expand Down

0 comments on commit e44afa9

Please sign in to comment.