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

[Placement Group] Add support for soft anti affinity #148

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pkg/cluster/compute/affinityrule/affinityrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package affinityrule

import (
"strings"
"time"

"github.com/microsoft/wmi/pkg/base/host"
Expand Down Expand Up @@ -97,3 +98,45 @@ func GetAffinityRule(whost *host.WmiHost, affinityRuleName string) (caffinityRul
caffinityRule = &AffinityRule{wmiafRule}
return
}

// SetAffinityRule updates an existing affinity rule
bgriddaluru marked this conversation as resolved.
Show resolved Hide resolved
func SetAffinityRule(whost *host.WmiHost, name string, ruleType int, softAntiAffinity bool) (err error) {
affinityRule, err := GetAffinityRule(whost, name)
if err != nil {
return
}
defer affinityRule.Close()

propeties := affinityRule.GetClass().GetPropertiesNames()
if len(propeties) == 0 {
err = errors.Wrapf(errors.Unknown, "Failed to get the properties of MSCluster_AffinityRule")
return
}

softAntiAffinitySupported := false
bgriddaluru marked this conversation as resolved.
Show resolved Hide resolved
for _, property := range propeties {
if strings.EqualFold(property, "SoftAntiAffinity") {
softAntiAffinitySupported = true
break
}
}

// SoftAntiAffinity is supported on platforms 24H2 or higher
if softAntiAffinitySupported {
softAntiAffinityValue := 0
if softAntiAffinity {
softAntiAffinityValue = 1
}
_, err = affinityRule.InvokeMethod("SetAffinityRule", int(ruleType), 1 /* Enabled */, softAntiAffinityValue /* SoftAntiAffinity */)
if err != nil {
return
}
} else {
_, err = affinityRule.SetAffinityRule(uint32(ruleType), 1 /* Enabled */)
if err != nil {
return
}
}

return
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"path/filepath"
"strings"

"reflect"

"github.com/microsoft/wmi/pkg/base/host"
"github.com/microsoft/wmi/pkg/base/instance"
"github.com/microsoft/wmi/pkg/base/query"
fcconstant "github.com/microsoft/wmi/pkg/cluster/constant"
"github.com/microsoft/wmi/pkg/constant"
"github.com/microsoft/wmi/pkg/errors"
"reflect"

"github.com/microsoft/wmi/pkg/cluster/compute/resource"
wmi "github.com/microsoft/wmi/pkg/wmiinstance"
Expand Down Expand Up @@ -96,7 +97,9 @@ func GetClusterSharedVolumebyName(whost *host.WmiHost, name string) (cvolume *Cl
return
}
matchingPath := strings.ToLower(filepath.Clean(instanceName))
if strings.Contains(inPath, matchingPath) {
// Append "\\" to eliminate false positive due to partial match
// e.g. "C:\ClusterStorage\Volume10\image" and "C:\ClusterStorage\Volume1"
if strings.HasPrefix(inPath+"\\", matchingPath+"\\") {
tmpInstance, err1 := instance.Clone()
if err1 != nil {
err = err1
Expand Down