Skip to content
Merged
Changes from all 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
20 changes: 16 additions & 4 deletions hcn/hcnsupport.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package hcn

import (
"fmt"
"sync"

"github.com/sirupsen/logrus"
)

var versionOnce sync.Once

// SupportedFeatures are the features provided by the Service.
type SupportedFeatures struct {
Acl AclFeatures `json:"ACL"`
Expand Down Expand Up @@ -76,6 +81,17 @@ func GetSupportedFeatures() SupportedFeatures {
features.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion)
features.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion)

// Only print the HCN version and features supported once, instead of everytime this is invoked. These logs are useful to
// debug incidents where there's confusion on if a feature is supported on the host machine. The sync.Once helps to avoid redundant
// spam of these anytime a check needs to be made for if an HCN feature is supported. This is a common occurrence in kubeproxy
// for example.
versionOnce.Do(func() {
logrus.WithFields(logrus.Fields{
"version": fmt.Sprintf("%+v", globals.Version),
"supportedFeatures": fmt.Sprintf("%+v", features),
}).Info("HCN feature check")
})

return features
}

Expand All @@ -91,19 +107,15 @@ func isFeatureSupported(currentVersion Version, versionsSupported VersionRanges)

func isFeatureInRange(currentVersion Version, versionRange VersionRange) bool {
if currentVersion.Major < versionRange.MinVersion.Major {
logrus.Infof("currentVersion.Major < versionRange.MinVersion.Major: %v, %v", currentVersion.Major, versionRange.MinVersion.Major)
return false
}
if currentVersion.Major > versionRange.MaxVersion.Major {
logrus.Infof("currentVersion.Major > versionRange.MaxVersion.Major: %v, %v", currentVersion.Major, versionRange.MaxVersion.Major)
return false
}
if currentVersion.Major == versionRange.MinVersion.Major && currentVersion.Minor < versionRange.MinVersion.Minor {
logrus.Infof("currentVersion.Minor < versionRange.MinVersion.Major: %v, %v", currentVersion.Minor, versionRange.MinVersion.Minor)
return false
}
if currentVersion.Major == versionRange.MaxVersion.Major && currentVersion.Minor > versionRange.MaxVersion.Minor {
logrus.Infof("currentVersion.Minor > versionRange.MaxVersion.Major: %v, %v", currentVersion.Minor, versionRange.MaxVersion.Minor)
return false
}
return true
Expand Down