|
12 | 12 | // featuresOnce handles assigning the supported features and printing the supported info to stdout only once to avoid unnecessary work |
13 | 13 | // multiple times. |
14 | 14 | featuresOnce sync.Once |
15 | | - versionErr error |
| 15 | + featuresErr error |
16 | 16 | supportedFeatures SupportedFeatures |
17 | 17 | ) |
18 | 18 |
|
@@ -59,60 +59,31 @@ func GetCachedSupportedFeatures() (SupportedFeatures, error) { |
59 | 59 | // 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 |
60 | 60 | // for example. |
61 | 61 | 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() |
99 | 63 | }) |
100 | 64 |
|
101 | | - return supportedFeatures, versionErr |
| 65 | + return supportedFeatures, featuresErr |
102 | 66 | } |
103 | 67 |
|
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. |
106 | 70 | func GetSupportedFeatures() SupportedFeatures { |
107 | | - var features SupportedFeatures |
108 | | - |
109 | | - globals, err := GetGlobals() |
| 71 | + features, err := GetCachedSupportedFeatures() |
110 | 72 | if err != nil { |
111 | 73 | // 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) |
113 | 75 | return features |
114 | 76 | } |
| 77 | + return features |
| 78 | +} |
115 | 79 |
|
| 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 | + } |
116 | 87 | features.Acl = AclFeatures{ |
117 | 88 | AclAddressLists: isFeatureSupported(globals.Version, HNSVersion1803), |
118 | 89 | AclNoHostRulePriority: isFeatureSupported(globals.Version, HNSVersion1803), |
@@ -145,7 +116,7 @@ func GetSupportedFeatures() SupportedFeatures { |
145 | 116 | "supportedFeatures": fmt.Sprintf("%+v", features), |
146 | 117 | }).Info("HCN feature check") |
147 | 118 |
|
148 | | - return features |
| 119 | + return features, nil |
149 | 120 | } |
150 | 121 |
|
151 | 122 | func isFeatureSupported(currentVersion Version, versionsSupported VersionRanges) bool { |
|
0 commit comments