From 44e4ec0bc9d28c1a26e5bfdaa0e54e12eff35bf1 Mon Sep 17 00:00:00 2001 From: PRINCE PEREIRA Date: Tue, 4 Jun 2024 21:22:05 +0530 Subject: [PATCH] Changes for checking the global version for modify policy version support. (#2139) Signed-off-by: Prince Pereira (cherry picked from commit 8beabacfc2d21767a07c20f8dd5f9f3932dbf305) Signed-off-by: Kirtana Ashok --- hcn/hcn.go | 12 ++++++++++++ hcn/hcnerrors.go | 5 +++++ hcn/hcnglobals.go | 2 ++ hcn/hcnsupport.go | 2 ++ 4 files changed, 21 insertions(+) diff --git a/hcn/hcn.go b/hcn/hcn.go index d458c5f3de..34f3b205df 100644 --- a/hcn/hcn.go +++ b/hcn/hcn.go @@ -264,6 +264,18 @@ func SetPolicySupported() error { return platformDoesNotSupportError("SetPolicy") } +// ModifyLoadbalancerSupported returns an error if the HCN version does not support ModifyLoadbalancer. +func ModifyLoadbalancerSupported() error { + supported, err := GetCachedSupportedFeatures() + if err != nil { + return err + } + if supported.ModifyLoadbalancer { + return nil + } + return platformDoesNotSupportError("ModifyLoadbalancer") +} + // VxlanPortSupported returns an error if the HCN version does not support configuring the VXLAN TCP port. func VxlanPortSupported() error { supported, err := GetCachedSupportedFeatures() diff --git a/hcn/hcnerrors.go b/hcn/hcnerrors.go index 66390cf0d3..c043adf396 100644 --- a/hcn/hcnerrors.go +++ b/hcn/hcnerrors.go @@ -52,6 +52,7 @@ type ErrorCode uint32 const ( ERROR_NOT_FOUND = ErrorCode(windows.ERROR_NOT_FOUND) HCN_E_PORT_ALREADY_EXISTS ErrorCode = ErrorCode(windows.HCN_E_PORT_ALREADY_EXISTS) + HCN_E_NOTIMPL ErrorCode = ErrorCode(windows.E_NOTIMPL) ) type HcnError struct { @@ -79,6 +80,10 @@ func IsPortAlreadyExistsError(err error) bool { return CheckErrorWithCode(err, HCN_E_PORT_ALREADY_EXISTS) } +func IsNotImplemented(err error) bool { + return CheckErrorWithCode(err, HCN_E_NOTIMPL) +} + func new(hr error, title string, rest string) error { err := &HcnError{} hcsError := hcserror.New(hr, title, rest) diff --git a/hcn/hcnglobals.go b/hcn/hcnglobals.go index fdda88e763..9fb8ab8a1d 100644 --- a/hcn/hcnglobals.go +++ b/hcn/hcnglobals.go @@ -87,6 +87,8 @@ var ( //HNS 15.1 allows support for DisableHostPort flag. DisableHostPortVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 15, Minor: 1}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}} + // HNS 15.4 allows for Modify Loadbalancer support + ModifyLoadbalancerVersion = VersionRanges{VersionRange{MinVersion: Version{Major: 15, Minor: 4}, MaxVersion: Version{Major: math.MaxInt32, Minor: math.MaxInt32}}} ) // GetGlobals returns the global properties of the HCN Service. diff --git a/hcn/hcnsupport.go b/hcn/hcnsupport.go index ed750593e5..eae02de7d5 100644 --- a/hcn/hcnsupport.go +++ b/hcn/hcnsupport.go @@ -38,6 +38,7 @@ type SupportedFeatures struct { NetworkACL bool `json:"NetworkACL"` NestedIpSet bool `json:"NestedIpSet"` DisableHostPort bool `json:"DisableHostPort"` + ModifyLoadbalancer bool `json:"ModifyLoadbalancer"` } // AclFeatures are the supported ACL possibilities. @@ -116,6 +117,7 @@ func getSupportedFeatures() (SupportedFeatures, error) { features.NetworkACL = isFeatureSupported(globals.Version, NetworkACLPolicyVersion) features.NestedIpSet = isFeatureSupported(globals.Version, NestedIpSetVersion) features.DisableHostPort = isFeatureSupported(globals.Version, DisableHostPortVersion) + features.ModifyLoadbalancer = isFeatureSupported(globals.Version, ModifyLoadbalancerVersion) log.L.WithFields(logrus.Fields{ "version": globals.Version,