Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: Retain service clusterIPs if set
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Jun 16, 2021
1 parent 612f3ac commit e5e7f48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/controller/sync/dispatch/retain.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func retainServiceFields(desiredObj, clusterObj *unstructured.Unstructured) erro

// ClusterIP and NodePort are allocated to Service by cluster, so retain the same if any while updating

// Retain clusterip
// Retain clusterip and clusterips
clusterIP, ok, err := unstructured.NestedString(clusterObj.Object, "spec", "clusterIP")
if err != nil {
return errors.Wrap(err, "Error retrieving clusterIP from cluster service")
Expand All @@ -71,6 +71,17 @@ func retainServiceFields(desiredObj, clusterObj *unstructured.Unstructured) erro
return errors.Wrap(err, "Error setting clusterIP for service")
}
}
clusterIPs, ok, err := unstructured.NestedStringSlice(clusterObj.Object, "spec", "clusterIPs")
if err != nil {
return errors.Wrap(err, "Error retrieving clusterIPs from cluster service")
}
// !ok could indicate that cluster ips was not assigned
if ok && len(clusterIPs) > 0 {
err := unstructured.SetNestedField(desiredObj.Object, clusterIPs, "spec", "clusterIPs")
if err != nil {
return errors.Wrap(err, "Error setting clusterIPs for service")
}
}

// Retain nodeports
clusterPorts, ok, err := unstructured.NestedSlice(clusterObj.Object, "spec", "ports")
Expand Down
1 change: 1 addition & 0 deletions pkg/kubefedctl/federate/federate.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ func FederatedResourceFromTargetResource(typeConfig typeconfig.Interface, resour
}
}
unstructured.RemoveNestedField(targetResource.Object, "spec", "clusterIP")
unstructured.RemoveNestedField(targetResource.Object, "spec", "clusterIPs")
}
}

Expand Down

0 comments on commit e5e7f48

Please sign in to comment.