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

Don't allow duplicate values in NodeAddresses #5116

Merged
merged 1 commit into from
Mar 9, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1405,3 +1405,19 @@ const (

PortHeader = "port"
)

// Appends the NodeAddresses to the passed-by-pointer slice, only if they do not already exist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not define the method.

func AddToNodeAddresses(addresses *[]NodeAddress, addAddresses ...NodeAddress) {
for _, add := range addAddresses {
exists := false
for _, existing := range *addresses {
if existing.Address == add.Address && existing.Type == add.Type {
exists = true
break
}
}
if !exists {
*addresses = append(*addresses, add)
}
}
}
2 changes: 1 addition & 1 deletion pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ func init() {
}

if in.HostIP != "" {
out.Status.Addresses = append(out.Status.Addresses,
newer.AddToNodeAddresses(&out.Status.Addresses,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check whether NodeLegacyHostIP exists or not here.

newer.NodeAddress{Type: newer.NodeLegacyHostIP, Address: in.HostIP})
}
out.Spec.PodCIDR = in.PodCIDR
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func init() {
}

if in.HostIP != "" {
out.Status.Addresses = append(out.Status.Addresses,
newer.AddToNodeAddresses(&out.Status.Addresses,
newer.NodeAddress{Type: newer.NodeLegacyHostIP, Address: in.HostIP})
}
out.Spec.PodCIDR = in.PodCIDR
Expand Down
6 changes: 3 additions & 3 deletions pkg/cloudprovider/controller/nodecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (s *NodeController) PopulateAddresses(nodes *api.NodeList) (*api.NodeList,
glog.Errorf("error getting instance ip address for %s: %v", node.Name, err)
} else {
address := api.NodeAddress{Type: api.NodeLegacyHostIP, Address: hostIP.String()}
node.Status.Addresses = append(node.Status.Addresses, address)
api.AddToNodeAddresses(&node.Status.Addresses, address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can override the address here: node.Status.Addresses = []api.Nodeaddress{address}

}
}
} else {
Expand All @@ -287,7 +287,7 @@ func (s *NodeController) PopulateAddresses(nodes *api.NodeList) (*api.NodeList,
addr := net.ParseIP(node.Name)
if addr != nil {
address := api.NodeAddress{Type: api.NodeLegacyHostIP, Address: addr.String()}
node.Status.Addresses = append(node.Status.Addresses, address)
api.AddToNodeAddresses(&node.Status.Addresses, address)
} else {
addrs, err := lookupIP(node.Name)
if err != nil {
Expand All @@ -296,7 +296,7 @@ func (s *NodeController) PopulateAddresses(nodes *api.NodeList) (*api.NodeList,
glog.Errorf("No ip address for node %v", node.Name)
} else {
address := api.NodeAddress{Type: api.NodeLegacyHostIP, Address: addrs[0].String()}
node.Status.Addresses = append(node.Status.Addresses, address)
api.AddToNodeAddresses(&node.Status.Addresses, address)
}
}
}
Expand Down