Skip to content

Commit

Permalink
Merge pull request #165 from liwenwu-amazon/pod-network
Browse files Browse the repository at this point in the history
Add a configuration knob to allow Pod to use different VPC SecurityGroups and Subnet
  • Loading branch information
liwenwu-amazon committed Sep 21, 2018
2 parents 6177612 + ddbe248 commit c30ede2
Show file tree
Hide file tree
Showing 4,508 changed files with 1,233,430 additions and 531,380 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
489 changes: 84 additions & 405 deletions Gopkg.lock

Large diffs are not rendered by default.

46 changes: 35 additions & 11 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
# version = "2.4.0"


[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.12.14"
version = "1.15.22"

[[constraint]]
name = "github.com/cihub/seelog"
Expand All @@ -39,32 +35,60 @@

[[constraint]]
name = "github.com/coreos/go-iptables"
version = "0.2.0"
version = "0.4.0"

[[constraint]]
name = "github.com/docker/docker"
version = "1.13.1"

[[constraint]]
name = "github.com/golang/mock"
version = "1.0.0"
version = "1.1.1"

[[constraint]]
branch = "master"
name = "github.com/golang/protobuf"
version = "1.2.0"

[[constraint]]
name = "github.com/operator-framework/operator-sdk"
branch = "master"
# version = "0.0.5"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"

[[constraint]]
name = "github.com/prometheus/client_golang"
version = "0.8.0"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.1.4"
version = "1.2.2"

[[constraint]]
branch = "master"
name = "github.com/vishvananda/netlink"
version = "1.0.0"

[[constraint]]
branch = "master"
name = "golang.org/x/net"

[[constraint]]
name = "google.golang.org/grpc"
version = "1.7.0"
version = "1.14.0"

[[constraint]]
name = "k8s.io/api"
# revision for tag "kubernetes-1.10.1"
revision = "73d903622b7391f3312dcbac6483fed484e185f8"

[[constraint]]
name = "k8s.io/apimachinery"
# revision for tag "kubernetes-1.10.1"
revision = "302974c03f7e50f16561ba237db776ab93594ef6"

[[constraint]]
name = "k8s.io/client-go"
# revision for tag "kubernetes-1.10.1"
revision = "989be4278f353e42f26c416c53757d16fcff77db"
130 changes: 130 additions & 0 deletions config/v1.2/aws-k8s-cni.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
apiVersion: rbac.authorization.k8s.io/v1
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: aws-node
rules:
- apiGroups:
- crd.k8s.amazonaws.com
resources:
- "*"
- namespaecs
verbs:
- "*"
- apiGroups: [""]
resources:
- pods
- nodes
- namespaces
verbs: ["list", "watch", "get"]
- apiGroups: ["extensions"]
resources:
- daemonsets
verbs: ["list", "watch"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: aws-node
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: aws-node
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: aws-node
subjects:
- kind: ServiceAccount
name: aws-node
namespace: kube-system
---
kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
name: aws-node
namespace: kube-system
labels:
k8s-app: aws-node
spec:
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
k8s-app: aws-node
template:
metadata:
labels:
k8s-app: aws-node
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ''
spec:
serviceAccountName: aws-node
hostNetwork: true
tolerations:
- operator: Exists
containers:
- image: 602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon-k8s-cni:1.2.0
imagePullPolicy: Always
ports:
- containerPort: 60000
name: metrics
name: aws-node
env:
- name: AWS_VPC_K8S_CNI_LOGLEVEL
value: DEBUG
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
resources:
requests:
cpu: 10m
securityContext:
privileged: true
volumeMounts:
- mountPath: /host/opt/cni/bin
name: cni-bin-dir
- mountPath: /host/etc/cni/net.d
name: cni-net-dir
- mountPath: /host/var/log
name: log-dir
- mountPath: /var/run/docker.sock
name: dockersock
volumes:
- name: cni-bin-dir
hostPath:
path: /opt/cni/bin
- name: cni-net-dir
hostPath:
path: /etc/cni/net.d
- name: log-dir
hostPath:
path: /var/log
- name: dockersock
hostPath:
path: /var/run/docker.sock
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: eniconfigs.crd.k8s.amazonaws.com
spec:
scope: Cluster
group: crd.k8s.amazonaws.com
version: v1alpha1
names:
scope: Cluster
plural: eniconfigs
singuar: eniconfig
kind: ENIConfig


6 changes: 5 additions & 1 deletion ipamd/datastore/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,12 @@ func (ds *DataStore) getDeletableENI() *ENIIPPool {
}

// GetENINeedsIP finds out the eni in datastore which failed to get secondary IP address
func (ds *DataStore) GetENINeedsIP(maxIPperENI int64) *ENIIPPool {
func (ds *DataStore) GetENINeedsIP(maxIPperENI int64, skipPrimary bool) *ENIIPPool {
for _, eni := range ds.eniIPPools {
if skipPrimary && eni.IsPrimary {
log.Debugf("Skip the primary ENI for need IP check")
continue
}
if int64(len(eni.IPv4Addresses)) < maxIPperENI {
log.Debugf("Found eni %s that have less IP address allocated: cur=%d, max=%d",
eni.ID, len(eni.IPv4Addresses), maxIPperENI)
Expand Down
34 changes: 30 additions & 4 deletions ipamd/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ func (c *IPAMContext) SetupHTTP() {

func (c *IPAMContext) setupServer() *http.Server {
serverFunctions := map[string]func(w http.ResponseWriter, r *http.Request){
"/v1/enis": eniV1RequestHandler(c),
"/v1/pods": podV1RequestHandler(c),
"/v1/env-settings": envV1RequestHandler(c),
"/v1/enis": eniV1RequestHandler(c),
"/v1/pods": podV1RequestHandler(c),
"/v1/networkutils-env-settings": networkEnvV1RequestHandler(c),
"/v1/ipamd-env-settings": ipamdEnvV1RequestHandler(c),
"/v1/eni-configs": eniConfigRequestHandler(c),
}
paths := make([]string, 0, len(serverFunctions))
for path := range serverFunctions {
Expand Down Expand Up @@ -134,7 +136,19 @@ func podV1RequestHandler(ipam *IPAMContext) func(http.ResponseWriter, *http.Requ
}
}

func envV1RequestHandler(ipam *IPAMContext) func(http.ResponseWriter, *http.Request) {
func eniConfigRequestHandler(ipam *IPAMContext) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
responseJSON, err := json.Marshal(ipam.eniConfig.Getter())
if err != nil {
log.Error("Failed to marshal pod data: %v", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.Write(responseJSON)
}
}

func networkEnvV1RequestHandler(ipam *IPAMContext) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
responseJSON, err := json.Marshal(networkutils.GetConfigForDebug())
if err != nil {
Expand All @@ -146,6 +160,18 @@ func envV1RequestHandler(ipam *IPAMContext) func(http.ResponseWriter, *http.Requ
}
}

func ipamdEnvV1RequestHandler(ipam *IPAMContext) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
responseJSON, err := json.Marshal(GetConfigForDebug())
if err != nil {
log.Error("Failed to marshal env var data: %v", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.Write(responseJSON)
}
}

func metricsHandler(ipam *IPAMContext) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
promhttp.Handler()
Expand Down
Loading

0 comments on commit c30ede2

Please sign in to comment.