-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
API to autocreate subnets for external hosts #10621
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ func (master *OsdnMaster) SubnetStartMaster(clusterNetwork *net.IPNet, hostSubne | |
} | ||
|
||
go utilwait.Forever(master.watchNodes, 0) | ||
go utilwait.Forever(master.watchSubnets, 0) | ||
return nil | ||
} | ||
|
||
|
@@ -242,6 +243,41 @@ func (node *OsdnNode) initSelfSubnet() error { | |
return nil | ||
} | ||
|
||
// Only run on the master | ||
// Watch for all hostsubnet events and if one is found with the right annotation, use the SubnetAllocator to dole a real subnet | ||
func (master *OsdnMaster) watchSubnets() { | ||
RunEventQueue(master.osClient, HostSubnets, func(delta cache.Delta) error { | ||
hs := delta.Object.(*osapi.HostSubnet) | ||
name := hs.ObjectMeta.Name | ||
hostIP := hs.HostIP | ||
|
||
log.V(5).Infof("Watch %s event for HostSubnet %q", delta.Type, hs.ObjectMeta.Name) | ||
switch delta.Type { | ||
case cache.Sync, cache.Added, cache.Updated: | ||
if _, ok := hs.Annotations[AssignHostSubnetAnnotation]; ok { | ||
// Delete the annotated hostsubnet and create a new one with an assigned subnet | ||
// We do not update (instead of delete+create) because the watchSubnets on the nodes | ||
// will skip the event if it finds that the hostsubnet has the same host | ||
// And we cannot fix the watchSubnets code for node because it will break migration if | ||
// nodes are upgraded after the master | ||
err := master.osClient.HostSubnets().Delete(name) | ||
if err != nil { | ||
log.Errorf("Error in deleting annotated subnet from master, name: %s, ip %s: %v", name, hostIP, err) | ||
return nil | ||
} | ||
err = master.addNode(name, hostIP) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that addNode() is called from watchNodes() and watchSubnets() asynchronously, we need a mutex to synchronize GetNetwork/ReleaseNetwork. |
||
if err != nil { | ||
log.Errorf("Error creating subnet for node %s, ip %s: %v", name, hostIP, err) | ||
return nil | ||
} | ||
} | ||
case cache.Deleted: | ||
// ignore all deleted hostsubnets | ||
} | ||
return nil | ||
}) | ||
} | ||
|
||
// Only run on the nodes | ||
func (node *OsdnNode) watchSubnets() { | ||
subnets := make(map[string]*osapi.HostSubnet) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't just allowing the subnet field to be empty, it's allowing it to be invalid... that's not what we want is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this. The check is made only on empty field.