Skip to content

Commit 152ce38

Browse files
authored
Merge pull request #63 from cloudnativelabs/aws-src-dst-check
When running on AWS disable source-destination checks automatically
2 parents 33dc111 + beb39cc commit 152ce38

File tree

2,433 files changed

+1538877
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,433 files changed

+1538877
-2
lines changed

app/controllers/network_routes_controller.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ package controllers
33
import (
44
"errors"
55
"fmt"
6+
"net/url"
67
"net"
78
"strconv"
89
"strings"
910
"sync"
1011
"time"
1112

13+
"github.com/aws/aws-sdk-go/aws"
14+
"github.com/aws/aws-sdk-go/aws/ec2metadata"
15+
"github.com/aws/aws-sdk-go/aws/session"
16+
"github.com/aws/aws-sdk-go/service/ec2"
1217
"github.com/cloudnativelabs/kube-router/app/options"
1318
"github.com/cloudnativelabs/kube-router/app/watchers"
1419
"github.com/cloudnativelabs/kube-router/utils"
@@ -66,6 +71,9 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr
6671
}
6772
}
6873

74+
// In case of cluster provisioned on AWS disable source-destination check
75+
nrc.disableSourceDestinationCheck()
76+
6977
t := time.NewTicker(nrc.syncPeriod)
7078
defer t.Stop()
7179
defer wg.Done()
@@ -222,6 +230,47 @@ func (nrc *NetworkRoutingController) injectRoute(path *table.Path) error {
222230
func (nrc *NetworkRoutingController) Cleanup() {
223231
}
224232

233+
func (nrc *NetworkRoutingController) disableSourceDestinationCheck() {
234+
235+
nodes, err := nrc.clientset.Core().Nodes().List(metav1.ListOptions{})
236+
if err != nil {
237+
glog.Errorf("Failed to list nodes from API server due to: %s. Can not perform BGP peer sync", err.Error())
238+
return
239+
}
240+
241+
for _, node := range nodes.Items {
242+
if node.Spec.ProviderID == "" || !strings.HasPrefix(node.Spec.ProviderID, "aws") {
243+
return
244+
}
245+
providerID := strings.Replace(node.Spec.ProviderID, "///", "//", 1)
246+
url, err := url.Parse(providerID)
247+
instanceID := url.Path
248+
instanceID = strings.Trim(instanceID, "/")
249+
glog.Infof("Disabling source destination check for the instance: " + instanceID)
250+
251+
sess, _ := session.NewSession(aws.NewConfig().WithMaxRetries(5))
252+
metadataClient := ec2metadata.New(sess)
253+
region, err := metadataClient.Region()
254+
if err != nil {
255+
glog.Errorf("Failed to disable source destination check due to: " + err.Error())
256+
return
257+
}
258+
sess.Config.Region = aws.String(region)
259+
ec2Client := ec2.New(sess)
260+
_, err = ec2Client.ModifyInstanceAttribute(
261+
&ec2.ModifyInstanceAttributeInput{
262+
InstanceId: aws.String(instanceID),
263+
SourceDestCheck: &ec2.AttributeBooleanValue{
264+
Value: aws.Bool(false),
265+
},
266+
},
267+
)
268+
if err != nil {
269+
glog.Errorf("Failed to disable source destination check due to: " + err.Error())
270+
}
271+
}
272+
}
273+
225274
// Refresh the peer relationship rest of the nodes in the cluster. Node add/remove
226275
// events should ensure peer relationship with only currently active nodes. In case
227276
// we miss any events from API server this method which is called periodically

glide.lock

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

glide.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ import:
5656
version: master
5757
- package: github.com/hkwi/nlgo
5858
version: master
59+
- package: github.com/aws/aws-sdk-go/
60+
version: ^v1.8.36

vendor/github.com/aws/aws-sdk-go/.github/ISSUE_TEMPLATE.md

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

vendor/github.com/aws/aws-sdk-go/.github/PULL_REQUEST_TEMPLATE.md

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/aws/aws-sdk-go/.gitignore

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

vendor/github.com/aws/aws-sdk-go/.godoc_config

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

vendor/github.com/aws/aws-sdk-go/.travis.yml

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

0 commit comments

Comments
 (0)