Skip to content

Commit

Permalink
scheduler: enable upgrade path for bridge network finger print
Browse files Browse the repository at this point in the history
This PR enables users of Nomad < 0.12 to upgrade to Nomad 0.12
and beyond. Nomad 0.12 introduced a network fingerprinter for
bridge networks, which is a contstraint checked for if bridge
network is being used. If users upgrade servers first as is
recommended, suddenly no clients running older versions of Nomad
will satisfy the bridge network resource constraint. Instead,
this change only enforces the constraint if the Nomad client
version is also >= 0.12.

Closes #8423
  • Loading branch information
shoenig committed Nov 13, 2020
1 parent feadd2b commit 3826e23
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
27 changes: 27 additions & 0 deletions scheduler/feasible.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ const (
FilterConstraintDevices = "missing devices"
)

var (
// predatesBridgeFingerprint returns true if the constraint matches a version
// of nomad that predates the addition of the bridge network finger-printer,
// which was added in Nomad v0.12
predatesBridgeFingerprint = mustBridgeConstraint()
)

func mustBridgeConstraint() version.Constraints {
versionC, err := version.NewConstraint("< 0.12")
if err != nil {
panic(err)
}
return versionC
}

// FeasibleIterator is used to iteratively yield nodes that
// match feasibility constraints. The iterators may manage
// some state for performance optimizations.
Expand Down Expand Up @@ -343,6 +358,18 @@ func (c *NetworkChecker) SetNetwork(network *structs.NetworkResource) {

func (c *NetworkChecker) Feasible(option *structs.Node) bool {
if !c.hasNetwork(option) {

// special case - if the client is running a version older than 0.12 but
// the server is 0.12 or newer, we need to maintain an upgrade path for
// jobs looking for a bridge network that will not have been fingerprinted
// on the client (which was added in 0.12)
if c.networkMode == "bridge" {
sv, err := version.NewSemver(option.Attributes["nomad.version"])
if err == nil && predatesBridgeFingerprint.Check(sv) {
return true
}
}

c.ctx.Metrics().FilterNode(option, "missing network")
return false
}
Expand Down
47 changes: 41 additions & 6 deletions scheduler/feasible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,19 @@ func TestCSIVolumeChecker(t *testing.T) {

func TestNetworkChecker(t *testing.T) {
_, ctx := testContext(t)

node := func(mode string) *structs.Node {
n := mock.Node()
n.NodeResources.Networks = append(n.NodeResources.Networks, &structs.NetworkResource{Mode: mode})
n.Attributes["nomad.version"] = "0.12.0" // mock version is 0.5.0
return n
}

nodes := []*structs.Node{
mock.Node(),
mock.Node(),
mock.Node(),
node("bridge"),
node("bridge"),
node("cni/mynet"),
}
nodes[0].NodeResources.Networks = append(nodes[0].NodeResources.Networks, &structs.NetworkResource{Mode: "bridge"})
nodes[1].NodeResources.Networks = append(nodes[1].NodeResources.Networks, &structs.NetworkResource{Mode: "bridge"})
nodes[2].NodeResources.Networks = append(nodes[2].NodeResources.Networks, &structs.NetworkResource{Mode: "cni/mynet"})

checker := NewNetworkChecker(ctx)
cases := []struct {
Expand Down Expand Up @@ -439,6 +444,36 @@ func TestNetworkChecker(t *testing.T) {
}
}

func TestNetworkChecker_bridge_upgrade_path(t *testing.T) {
_, ctx := testContext(t)

t.Run("older client", func(t *testing.T) {
// Create a client that is still on v0.11, which does not have the bridge
// network finger-printer (and thus no bridge network resource)
oldClient := mock.Node()
oldClient.Attributes["nomad.version"] = "0.11.0"

checker := NewNetworkChecker(ctx)
checker.SetNetwork(&structs.NetworkResource{Mode: "bridge"})

ok := checker.Feasible(oldClient)
require.True(t, ok)
})

t.Run("updated client", func(t *testing.T) {
// Create a client that is updated to 0.12, but did not detect a bridge
// network resource.
oldClient := mock.Node()
oldClient.Attributes["nomad.version"] = "0.12.0"

checker := NewNetworkChecker(ctx)
checker.SetNetwork(&structs.NetworkResource{Mode: "bridge"})

ok := checker.Feasible(oldClient)
require.False(t, ok)
})
}

func TestDriverChecker_DriverInfo(t *testing.T) {
_, ctx := testContext(t)
nodes := []*structs.Node{
Expand Down

0 comments on commit 3826e23

Please sign in to comment.