Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/hcsshim
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.12.3
Choose a base ref
...
head repository: microsoft/hcsshim
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.12.4
Choose a head ref
  • 3 commits
  • 9 files changed
  • 3 contributors

Commits on Jun 7, 2024

  1. OutBoundNATPolicy Schema changes (#2106)

    Signed-off-by: Debjit Mondal <debjitmondal@microsoft.com>
    (cherry picked from commit c79a631)
    Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
    mdebjit authored and kiashok committed Jun 7, 2024
    Copy the full SHA
    62f86c0 View commit details
  2. Changes for checking the global version for modify policy version sup…

    …port. (#2139)
    
    Signed-off-by: Prince Pereira <ppereira@microsoft.com>
    (cherry picked from commit 8beabac)
    Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
    princepereira authored and kiashok committed Jun 7, 2024
    Copy the full SHA
    44e4ec0 View commit details
  3. Adding support for loadbalancer policy update in hns. (#2085)

    Signed-off-by: Prince Pereira <ppereira@microsoft.com>
    (cherry picked from commit 0f7d8de)
    Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
    princepereira authored and kiashok committed Jun 7, 2024
    Copy the full SHA
    c6a8327 View commit details
Showing with 171 additions and 7 deletions.
  1. +12 −0 hcn/hcn.go
  2. +5 −0 hcn/hcnerrors.go
  3. +2 −0 hcn/hcnglobals.go
  4. +60 −0 hcn/hcnloadbalancer.go
  5. +64 −0 hcn/hcnloadbalancer_test.go
  6. +5 −4 hcn/hcnpolicy.go
  7. +2 −0 hcn/hcnsupport.go
  8. +17 −0 hcn/hcnutils_test.go
  9. +4 −3 internal/hns/hnspolicy.go
12 changes: 12 additions & 0 deletions hcn/hcn.go
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions hcn/hcnerrors.go
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions hcn/hcnglobals.go
Original file line number Diff line number Diff line change
@@ -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.
60 changes: 60 additions & 0 deletions hcn/hcnloadbalancer.go
Original file line number Diff line number Diff line change
@@ -163,6 +163,49 @@ func createLoadBalancer(settings string) (*HostComputeLoadBalancer, error) {
return &outputLoadBalancer, nil
}

func updateLoadBalancer(loadbalancerId string, settings string) (*HostComputeLoadBalancer, error) {
loadBalancerGuid, err := guid.FromString(loadbalancerId)
if err != nil {
return nil, errInvalidLoadBalancerID
}
// Update loadBalancer.
var (
loadBalancerHandle hcnLoadBalancer
resultBuffer *uint16
propertiesBuffer *uint16
)
hr := hcnOpenLoadBalancer(&loadBalancerGuid, &loadBalancerHandle, &resultBuffer)
if err := checkForErrors("hcnOpenLoadBalancer", hr, resultBuffer); err != nil {
return nil, err
}
hr = hcnModifyLoadBalancer(loadBalancerHandle, settings, &resultBuffer)
if err := checkForErrors("hcnModifyLoadBalancer", hr, resultBuffer); err != nil {
return nil, err
}
// Query loadBalancer.
hcnQuery := defaultQuery()
query, err := json.Marshal(hcnQuery)
if err != nil {
return nil, err
}
hr = hcnQueryLoadBalancerProperties(loadBalancerHandle, string(query), &propertiesBuffer, &resultBuffer)
if err := checkForErrors("hcnQueryLoadBalancerProperties", hr, resultBuffer); err != nil {
return nil, err
}
properties := interop.ConvertAndFreeCoTaskMemString(propertiesBuffer)
// Close loadBalancer.
hr = hcnCloseLoadBalancer(loadBalancerHandle)
if err := checkForErrors("hcnCloseLoadBalancer", hr, nil); err != nil {
return nil, err
}
// Convert output to HostComputeLoadBalancer
var outputLoadBalancer HostComputeLoadBalancer
if err := json.Unmarshal([]byte(properties), &outputLoadBalancer); err != nil {
return nil, err
}
return &outputLoadBalancer, nil
}

func deleteLoadBalancer(loadBalancerID string) error {
loadBalancerGUID, err := guid.FromString(loadBalancerID)
if err != nil {
@@ -237,6 +280,23 @@ func (loadBalancer *HostComputeLoadBalancer) Create() (*HostComputeLoadBalancer,
return loadBalancer, nil
}

// Update Loadbalancer.
func (loadBalancer *HostComputeLoadBalancer) Update(hnsLoadbalancerID string) (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::Create id=%s", hnsLoadbalancerID)

jsonString, err := json.Marshal(loadBalancer)
if err != nil {
return nil, err
}

logrus.Debugf("hcn::HostComputeLoadBalancer::Update JSON: %s", jsonString)
loadBalancer, hcnErr := updateLoadBalancer(hnsLoadbalancerID, string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return loadBalancer, nil
}

// Delete LoadBalancer.
func (loadBalancer *HostComputeLoadBalancer) Delete() error {
logrus.Debugf("hcn::HostComputeLoadBalancer::Delete id=%s", loadBalancer.Id)
64 changes: 64 additions & 0 deletions hcn/hcnloadbalancer_test.go
Original file line number Diff line number Diff line change
@@ -42,6 +42,70 @@ func TestCreateDeleteLoadBalancer(t *testing.T) {
}
}

func TestCreateUpdateDeleteLoadBalancer(t *testing.T) {
network, err := CreateTestOverlayNetwork()
if err != nil {
t.Fatal(err)
}
endpoint, err := HcnCreateTestEndpoint(network)
if err != nil {
t.Fatal(err)
}
loadBalancer, err := HcnCreateTestLoadBalancer(endpoint)
if err != nil {
t.Fatal(err)
}
jsonString, err := json.Marshal(loadBalancer)
if err != nil {
t.Fatal(err)
}
fmt.Printf("LoadBalancer JSON:\n%s \n", jsonString)

secondEndpoint, err := HcnCreateTestEndpoint(network)
if err != nil {
t.Fatal(err)
}

HcnLoadBalancerTestAddBackend(loadBalancer, secondEndpoint.Id)

loadBalancer, err = loadBalancer.Update(loadBalancer.Id)
if err != nil {
t.Fatal(err)
}

if len(loadBalancer.HostComputeEndpoints) != 2 {
t.Fatalf("Update loadBalancer with backend add failed")
}

HcnLoadBalancerTestRemoveBackend(loadBalancer, secondEndpoint.Id)

loadBalancer, err = loadBalancer.Update(loadBalancer.Id)
if err != nil {
t.Fatal(err)
}

if len(loadBalancer.HostComputeEndpoints) != 1 {
t.Fatalf("Update loadBalancer with backend remove failed")
}

err = loadBalancer.Delete()
if err != nil {
t.Fatal(err)
}
err = secondEndpoint.Delete()
if err != nil {
t.Fatal(err)
}
err = endpoint.Delete()
if err != nil {
t.Fatal(err)
}
err = network.Delete()
if err != nil {
t.Fatal(err)
}
}

func TestGetLoadBalancerById(t *testing.T) {
network, err := CreateTestOverlayNetwork()
if err != nil {
9 changes: 5 additions & 4 deletions hcn/hcnpolicy.go
Original file line number Diff line number Diff line change
@@ -144,10 +144,11 @@ type QosPolicySetting struct {

// OutboundNatPolicySetting sets outbound Network Address Translation on an Endpoint.
type OutboundNatPolicySetting struct {
VirtualIP string `json:",omitempty"`
Exceptions []string `json:",omitempty"`
Destinations []string `json:",omitempty"`
Flags NatFlags `json:",omitempty"`
VirtualIP string `json:",omitempty"`
Exceptions []string `json:",omitempty"`
Destinations []string `json:",omitempty"`
Flags NatFlags `json:",omitempty"`
MaxPortPoolUsage uint16 `json:",omitempty"`
}

// SDNRoutePolicySetting sets SDN Route on an Endpoint.
2 changes: 2 additions & 0 deletions hcn/hcnsupport.go
Original file line number Diff line number Diff line change
@@ -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,
17 changes: 17 additions & 0 deletions hcn/hcnutils_test.go
Original file line number Diff line number Diff line change
@@ -317,6 +317,23 @@ func HcnCreateTestLoadBalancer(endpoint *HostComputeEndpoint) (*HostComputeLoadB
return loadBalancer.Create()
}

func HcnLoadBalancerTestAddBackend(loadBalancer *HostComputeLoadBalancer, endpointId string) {
endpointIds := loadBalancer.HostComputeEndpoints
endpointIds = append(endpointIds, endpointId)
loadBalancer.HostComputeEndpoints = endpointIds
}

func HcnLoadBalancerTestRemoveBackend(loadBalancer *HostComputeLoadBalancer, endpointId string) {
endpointIds := loadBalancer.HostComputeEndpoints
for i, v := range endpointIds {
if v == endpointId {
endpointIds = append(endpointIds[:i], endpointIds[i+1:]...)
break
}
}
loadBalancer.HostComputeEndpoints = endpointIds
}

func HcnCreateTestRemoteSubnetRoute() (*PolicyNetworkRequest, error) {
rsr := RemoteSubnetRoutePolicySetting{
DestinationPrefix: "192.168.2.0/24",
7 changes: 4 additions & 3 deletions internal/hns/hnspolicy.go
Original file line number Diff line number Diff line change
@@ -57,9 +57,10 @@ type PaPolicy struct {

type OutboundNatPolicy struct {
Policy
VIP string `json:"VIP,omitempty"`
Exceptions []string `json:"ExceptionList,omitempty"`
Destinations []string `json:",omitempty"`
VIP string `json:"VIP,omitempty"`
Exceptions []string `json:"ExceptionList,omitempty"`
Destinations []string `json:",omitempty"`
MaxPortPoolUsage uint16 `json:",omitempty"`
}

type ProxyPolicy struct {