Skip to content

Commit 7fb11e6

Browse files
committed
Review comments
1 parent 6f84cd1 commit 7fb11e6

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

pkg/hns/endpoint_windows.go

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// +build windows
2+
3+
// Copyright 2017 CNI authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
117
package hns
218

319
import (
@@ -8,6 +24,9 @@ import (
824
"strings"
925
)
1026

27+
// ConstructEndpointName constructs enpointId which is used to identify an endpoint from HNS
28+
// There is a special consideration for netNs name here, which is required for Windows Server 1709
29+
// containerID is the Id of the container on which the endpoint is worked on
1130
func ConstructEndpointName(containerID string, netNs string, networkName string) string {
1231
if netNs != "" {
1332
splits := strings.Split(netNs, ":")
@@ -19,6 +38,9 @@ func ConstructEndpointName(containerID string, netNs string, networkName string)
1938
return epName
2039
}
2140

41+
// DeprovisionEndpoint removes an endpoint from the container by sending a Detach request to HNS
42+
// For shared endpoint, ContainerDetach is used
43+
// for removing the endpoint completely, HotDetachEndpoint is used
2244
func DeprovisionEndpoint(epName string, netns string, containerID string) error {
2345
hnsEndpoint, err := hcsshim.GetHNSEndpointByName(epName)
2446
if err != nil {
@@ -52,6 +74,9 @@ func DeprovisionEndpoint(epName string, netns string, containerID string) error
5274

5375
type EndpointMakerFunc func() (*hcsshim.HNSEndpoint, error)
5476

77+
// ProvisionEndpoint provisions an endpoint to a container specified by containerID.
78+
// If an endpoint already exists, the endpoint is reused.
79+
// This call is idempotent
5580
func ProvisionEndpoint(epName string, expectedNetworkId string, containerID string, makeEndpoint EndpointMakerFunc) (*hcsshim.HNSEndpoint, error) {
5681
// check if endpoint already exists
5782
createEndpoint := true
@@ -87,6 +112,7 @@ func ProvisionEndpoint(epName string, expectedNetworkId string, containerID stri
87112
return hnsEndpoint, nil
88113
}
89114

115+
// ConstructResult constructs the CNI result for the endpoint
90116
func ConstructResult(hnsNetwork *hcsshim.HNSNetwork, hnsEndpoint *hcsshim.HNSEndpoint) (*current.Result, error) {
91117
resultInterface := &current.Interface{
92118
Name: hnsEndpoint.Name,

pkg/hns/netconf_windows.go

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1+
// +build windows
2+
3+
// Copyright 2017 CNI authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
117
package hns
218

319
import (
4-
"strings"
520
"encoding/json"
621
"github.com/containernetworking/cni/pkg/types"
22+
"strings"
723
)
824

25+
// NetConf is the CNI spec
926
type NetConf struct {
1027
types.NetConf
1128

12-
additionalArgs []policyArgument `json:"AdditionalArgs,omitempty"`
29+
additionalArgs []policyArgument `json:"AdditionalArgs,omitempty"`
1330
}
1431

1532
type policyArgument struct {
16-
Type string
33+
Type string
1734
Value map[string]interface{}
1835
}
1936

37+
// MarshalPolicies converts the Endpoint policies in AdditionalArgs
38+
// to HNS specific policies as Json raw bytes
2039
func (n *NetConf) MarshalPolicies() []json.RawMessage {
2140
if n.additionalArgs == nil {
2241
n.additionalArgs = []policyArgument{}
@@ -32,6 +51,8 @@ func (n *NetConf) MarshalPolicies() []json.RawMessage {
3251
return result
3352
}
3453

54+
// ApplyOutboundNatPolicy applies NAT Policy in VFP using HNS
55+
// Simultaneously an exception is added for the network that has to be Nat'd
3556
func (n *NetConf) ApplyOutboundNatPolicy(nwToNat string) {
3657
if n.additionalArgs == nil {
3758
n.additionalArgs = []policyArgument{}
@@ -84,9 +105,10 @@ func (n *NetConf) ApplyOutboundNatPolicy(nwToNat string) {
84105
n.additionalArgs = append(n.additionalArgs, natEntry)
85106
}
86107

108+
// ApplyDefaultPAPolicy is used to configure a endpoint PA policy in HNS
87109
func (n *NetConf) ApplyDefaultPAPolicy(paAddress string) {
88110
if n.additionalArgs == nil {
89-
n.additionalArgs = []policyArgument{}
111+
n.additionalArgs = []policyArgument{}
90112
}
91113

92114
// if its already present, leave untouched
@@ -118,4 +140,3 @@ func hasKey(m map[string]interface{}, k string) bool {
118140
_, ok := m[k]
119141
return ok
120142
}
121-

plugins/meta/flannel/flannel.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package main
2020

2121
import (
2222
"bufio"
23-
"encoding/binary"
2423
"encoding/json"
2524
"fmt"
2625
"io/ioutil"
@@ -31,7 +30,6 @@ import (
3130
"strconv"
3231
"strings"
3332

34-
"errors"
3533
"github.com/containernetworking/cni/pkg/invoke"
3634
"github.com/containernetworking/cni/pkg/skel"
3735
"github.com/containernetworking/cni/pkg/types"
@@ -267,11 +265,10 @@ func cmdAddWindows(containerID string, n *NetConf, fenv *subnetEnv) error {
267265
}
268266

269267
n.Delegate["ipam"] = map[string]interface{}{
270-
"type": "host-local",
271-
"subnet": fenv.sn.String(),
268+
"type": "host-local",
269+
"subnet": fenv.sn.String(),
272270
}
273271

274-
275272
return delegateAdd(containerID, n.DataDir, n.Delegate)
276273
}
277274

0 commit comments

Comments
 (0)