Skip to content

Commit 42d159a

Browse files
author
Daniel Richer
authored
Merge pull request #9 from kaloom/add-podagent-skip
Add podagent skip
2 parents cf98fb5 + e2de7b6 commit 42d159a

File tree

8 files changed

+537
-13
lines changed

8 files changed

+537
-13
lines changed

controller/pods.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,19 @@ type cniPodNetwork struct {
3939
kc.NetworkConfig
4040
}
4141

42+
func (c *cniPodNetwork) ToProperty() cniPodNetworkProperty {
43+
return cniPodNetworkProperty{
44+
IfMAC: c.IfMAC,
45+
IsPrimary: c.IsPrimary,
46+
PodagentSkip: c.PodagentSkip,
47+
}
48+
}
49+
4250
type cniPodNetworkProperty struct {
4351
IfMAC string
4452
IsPrimary bool
53+
// PodagentSkip makes podagent skip configuring this network
54+
PodagentSkip bool
4555
}
4656

4757
type cniPodNetworks []cniPodNetwork
@@ -97,10 +107,8 @@ func getNetworkSet(networks string) (gset.GSet, error) {
97107
netSetBuilder := gset.NewBuilder()
98108
err := json.Unmarshal([]byte(networks), &nets)
99109
if err == nil {
100-
np := cniPodNetworkProperty{}
101110
for _, n := range nets {
102-
np.IfMAC = n.IfMAC
103-
np.IsPrimary = n.IsPrimary
111+
np := n.ToProperty()
104112
netSetBuilder.Add(n.NetworkName, np)
105113
}
106114
}
@@ -158,6 +166,11 @@ func (c *Controller) addNetwork(podObj *apiv1.Pod, networkName string, np cniPod
158166
if np.IsPrimary {
159167
return nil
160168
}
169+
if np.PodagentSkip {
170+
glog.V(3).Infof("Skipping adding pod's %s network %s", podObj.GetName(), networkName)
171+
return nil
172+
}
173+
161174
cniParams, err := c.getCNIParams(podObj, networkName, np)
162175
if err != nil {
163176
return err
@@ -172,6 +185,11 @@ func (c *Controller) delNetwork(podObj *apiv1.Pod, networkName string, np cniPod
172185
if np.IsPrimary {
173186
return nil
174187
}
188+
if np.PodagentSkip {
189+
glog.V(3).Infof("Skipping deleting pod's %s network %s", podObj.GetName(), networkName)
190+
return nil
191+
}
192+
175193
cniParams, err := c.getCNIParams(podObj, networkName, np)
176194
if err != nil {
177195
return err
@@ -236,10 +254,8 @@ func (c *Controller) podUpdated(oldObj, newObj interface{}) {
236254
glog.V(4).Infof("Failed to unmarshall pod's %s old networks annotation, ignore: %s", podName, err)
237255
return
238256
}
239-
np := cniPodNetworkProperty{}
240257
for _, n := range nets {
241-
np.IfMAC = n.IfMAC
242-
np.IsPrimary = n.IsPrimary
258+
np := n.ToProperty()
243259
err := c.delNetwork(newPod, n.NetworkName, np)
244260
if err != nil {
245261
glog.Errorf("Failed to delete network %s on pod %s", n.NetworkName, podName)
@@ -260,10 +276,8 @@ func (c *Controller) addNetworks(pod *apiv1.Pod, networkAnnotation string) {
260276
return
261277
}
262278

263-
np := cniPodNetworkProperty{}
264279
for _, n := range nets {
265-
np.IfMAC = n.IfMAC
266-
np.IsPrimary = n.IsPrimary
280+
np := n.ToProperty()
267281
err := c.addNetwork(pod, n.NetworkName, np)
268282
if err != nil {
269283
glog.Errorf("Failed to add network %s on pod %s", n.NetworkName, podName)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ packageRepo=github.com/kaloom/kubernetes-podagent
22
binDir=bin
33
execName=podagent
44
goVersion=1.11.5
5-
version=0.1.7
5+
version=0.1.8

vendor/github.com/kaloom/kubernetes-common/LICENSE

Lines changed: 201 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/kaloom/kubernetes-common/go.mod

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/kaloom/kubernetes-common/go.sum

Whitespace-only changes.

0 commit comments

Comments
 (0)