Skip to content

Commit f78d0ff

Browse files
committed
PR feedback
- Change versionErr -> featuresErr - Move work inside of the sync.Once out to its own function so we can use standard return err error handling and simply assign the output in GetCachedSupportedFeatures - Mark GetSupportedFeatures as deprecated. Signed-off-by: Daniel Canter <[email protected]>
1 parent 112b5e7 commit f78d0ff

1 file changed

Lines changed: 17 additions & 46 deletions

File tree

hcn/hcnsupport.go

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var (
1212
// featuresOnce handles assigning the supported features and printing the supported info to stdout only once to avoid unnecessary work
1313
// multiple times.
1414
featuresOnce sync.Once
15-
versionErr error
15+
featuresErr error
1616
supportedFeatures SupportedFeatures
1717
)
1818

@@ -59,60 +59,31 @@ func GetCachedSupportedFeatures() (SupportedFeatures, error) {
5959
// spam of these anytime a check needs to be made for if an HCN feature is supported. This is a common occurrence in kube-proxy
6060
// for example.
6161
featuresOnce.Do(func() {
62-
globals, err := GetGlobals()
63-
if err != nil {
64-
// It's expected if this fails once, it should always fail. It should fail on pre 1803 builds for example.
65-
versionErr = errors.Wrap(err, "failed to query HCN version number: this is expected on pre 1803 builds.")
66-
} else {
67-
supportedFeatures.Acl = AclFeatures{
68-
AclAddressLists: isFeatureSupported(globals.Version, HNSVersion1803),
69-
AclNoHostRulePriority: isFeatureSupported(globals.Version, HNSVersion1803),
70-
AclPortRanges: isFeatureSupported(globals.Version, HNSVersion1803),
71-
AclRuleId: isFeatureSupported(globals.Version, HNSVersion1803),
72-
}
73-
74-
supportedFeatures.Api = ApiSupport{
75-
V2: isFeatureSupported(globals.Version, V2ApiSupport),
76-
V1: true, // HNSCall is still available.
77-
}
78-
79-
supportedFeatures.RemoteSubnet = isFeatureSupported(globals.Version, RemoteSubnetVersion)
80-
supportedFeatures.HostRoute = isFeatureSupported(globals.Version, HostRouteVersion)
81-
supportedFeatures.DSR = isFeatureSupported(globals.Version, DSRVersion)
82-
supportedFeatures.Slash32EndpointPrefixes = isFeatureSupported(globals.Version, Slash32EndpointPrefixesVersion)
83-
supportedFeatures.AclSupportForProtocol252 = isFeatureSupported(globals.Version, AclSupportForProtocol252Version)
84-
supportedFeatures.SessionAffinity = isFeatureSupported(globals.Version, SessionAffinityVersion)
85-
supportedFeatures.IPv6DualStack = isFeatureSupported(globals.Version, IPv6DualStackVersion)
86-
supportedFeatures.SetPolicy = isFeatureSupported(globals.Version, SetPolicyVersion)
87-
supportedFeatures.VxlanPort = isFeatureSupported(globals.Version, VxlanPortVersion)
88-
supportedFeatures.L4Proxy = isFeatureSupported(globals.Version, L4ProxyPolicyVersion)
89-
supportedFeatures.L4WfpProxy = isFeatureSupported(globals.Version, L4WfpProxyPolicyVersion)
90-
supportedFeatures.TierAcl = isFeatureSupported(globals.Version, TierAclPolicyVersion)
91-
supportedFeatures.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion)
92-
supportedFeatures.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion)
93-
94-
logrus.WithFields(logrus.Fields{
95-
"version": fmt.Sprintf("%+v", globals.Version),
96-
"supportedFeatures": fmt.Sprintf("%+v", supportedFeatures),
97-
}).Info("HCN feature check")
98-
}
62+
supportedFeatures, featuresErr = getSupportedFeatures()
9963
})
10064

101-
return supportedFeatures, versionErr
65+
return supportedFeatures, featuresErr
10266
}
10367

104-
// GetSupportedFeatures returns the features supported by the Service. Prefer `GetCachedSupportedFeatures` as this method will query hns and validate
105-
// every feature is supported on every invocation.
68+
// Deprecated: Use GetCachedSupportedFeatures instead.
69+
// GetSupportedFeatures returns the features supported by the Service.
10670
func GetSupportedFeatures() SupportedFeatures {
107-
var features SupportedFeatures
108-
109-
globals, err := GetGlobals()
71+
features, err := GetCachedSupportedFeatures()
11072
if err != nil {
11173
// Expected on pre-1803 builds, all features will be false/unsupported
112-
logrus.Debugf("Unable to obtain globals: %s", err)
74+
logrus.Errorf("Unable to obtain globals: %s", err)
11375
return features
11476
}
77+
return features
78+
}
11579

80+
func getSupportedFeatures() (SupportedFeatures, error) {
81+
var features SupportedFeatures
82+
globals, err := GetGlobals()
83+
if err != nil {
84+
// It's expected if this fails once, it should always fail. It should fail on pre 1803 builds for example.
85+
return SupportedFeatures{}, errors.Wrap(err, "failed to query HCN version number: this is expected on pre 1803 builds.")
86+
}
11687
features.Acl = AclFeatures{
11788
AclAddressLists: isFeatureSupported(globals.Version, HNSVersion1803),
11889
AclNoHostRulePriority: isFeatureSupported(globals.Version, HNSVersion1803),
@@ -145,7 +116,7 @@ func GetSupportedFeatures() SupportedFeatures {
145116
"supportedFeatures": fmt.Sprintf("%+v", features),
146117
}).Info("HCN feature check")
147118

148-
return features
119+
return features, nil
149120
}
150121

151122
func isFeatureSupported(currentVersion Version, versionsSupported VersionRanges) bool {

0 commit comments

Comments
 (0)