Browse code

Fix a multiple-pointers-to-single-loop-variable bug in EgressNetworkPolicy

Dan Winship authored on 2016/11/29 03:04:59
Showing 3 changed files
... ...
@@ -332,7 +332,7 @@ func (plugin *OsdnNode) SetupSDN() (bool, error) {
332 332
 	return true, nil
333 333
 }
334 334
 
335
-func policyNames(policies []*osapi.EgressNetworkPolicy) string {
335
+func policyNames(policies []osapi.EgressNetworkPolicy) string {
336 336
 	names := make([]string, len(policies))
337 337
 	for i, policy := range policies {
338 338
 		names[i] = policy.Namespace + ":" + policy.Name
... ...
@@ -24,7 +24,7 @@ func (plugin *OsdnNode) SetupEgressNetworkPolicy() error {
24 24
 			glog.Warningf("Could not find netid for namespace %q: %v", policy.Namespace, err)
25 25
 			continue
26 26
 		}
27
-		plugin.egressPolicies[vnid] = append(plugin.egressPolicies[vnid], &policy)
27
+		plugin.egressPolicies[vnid] = append(plugin.egressPolicies[vnid], policy)
28 28
 	}
29 29
 
30 30
 	for vnid := range plugin.egressPolicies {
... ...
@@ -55,7 +55,7 @@ func (plugin *OsdnNode) watchEgressNetworkPolicies() {
55 55
 			}
56 56
 		}
57 57
 		if delta.Type != cache.Deleted && len(policy.Spec.Egress) > 0 {
58
-			policies = append(policies, policy)
58
+			policies = append(policies, *policy)
59 59
 		}
60 60
 		plugin.egressPolicies[vnid] = policies
61 61
 
... ...
@@ -73,7 +73,7 @@ func (plugin *OsdnNode) UpdateEgressNetworkPolicyVNID(namespace string, oldVnid,
73 73
 	policies := plugin.egressPolicies[oldVnid]
74 74
 	for i, oldPolicy := range policies {
75 75
 		if oldPolicy.Namespace == namespace {
76
-			policy = oldPolicy
76
+			policy = &oldPolicy
77 77
 			plugin.egressPolicies[oldVnid] = append(policies[:i], policies[i+1:]...)
78 78
 			err := plugin.updateEgressNetworkPolicyRules(oldVnid)
79 79
 			if err != nil {
... ...
@@ -84,7 +84,7 @@ func (plugin *OsdnNode) UpdateEgressNetworkPolicyVNID(namespace string, oldVnid,
84 84
 	}
85 85
 
86 86
 	if policy != nil {
87
-		plugin.egressPolicies[newVnid] = append(plugin.egressPolicies[newVnid], policy)
87
+		plugin.egressPolicies[newVnid] = append(plugin.egressPolicies[newVnid], *policy)
88 88
 		err := plugin.updateEgressNetworkPolicyRules(newVnid)
89 89
 		if err != nil {
90 90
 			return err
... ...
@@ -44,7 +44,7 @@ type OsdnNode struct {
44 44
 	vnids              *nodeVNIDMap
45 45
 	iptablesSyncPeriod time.Duration
46 46
 	mtu                uint32
47
-	egressPolicies     map[uint32][]*osapi.EgressNetworkPolicy
47
+	egressPolicies     map[uint32][]osapi.EgressNetworkPolicy
48 48
 
49 49
 	host             knetwork.Host
50 50
 	kubeletCniPlugin knetwork.NetworkPlugin
... ...
@@ -99,7 +99,7 @@ func NewNodePlugin(pluginName string, osClient *osclient.Client, kClient *kclien
99 99
 		kubeletInitReady:   make(chan struct{}),
100 100
 		iptablesSyncPeriod: iptablesSyncPeriod,
101 101
 		mtu:                mtu,
102
-		egressPolicies:     make(map[uint32][]*osapi.EgressNetworkPolicy),
102
+		egressPolicies:     make(map[uint32][]osapi.EgressNetworkPolicy),
103 103
 	}
104 104
 
105 105
 	if err := plugin.dockerPreCNICleanup(); err != nil {