diff --git a/hcn/hcnsupport.go b/hcn/hcnsupport.go index 033428f1c2..4be8df17db 100644 --- a/hcn/hcnsupport.go +++ b/hcn/hcnsupport.go @@ -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"` @@ -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 } @@ -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