Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Commit

Permalink
Implement multi endpoint sidecar approach
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Morales <[email protected]>
  • Loading branch information
electrocucaracha committed Dec 8, 2020
1 parent 22ce765 commit e20cc81
Show file tree
Hide file tree
Showing 10 changed files with 348 additions and 53 deletions.
30 changes: 21 additions & 9 deletions examples/4g-network/k8s/endpoint-mme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ spec:
networkservicemesh.io/app: "mme"
template:
metadata:
annotations:
ns.networkservicemesh.io/endpoints: |
{
"name": "4g-network",
"tracerEnabled": true,
"networkServices": [
{"link": "s1-mme", "labels": "app=mme", "ipaddress": "10.60.1.0/24"},
{"link": "s6a", "labels": "app=mme", "ipaddress": "10.60.2.0/24"},
{"link": "s11", "labels": "app=mme", "ipaddress": "10.60.3.0/24"}
]
}
labels:
networkservicemesh.io/app: "mme"
networkservicemesh.io/impl: "4g-network"
Expand All @@ -16,22 +27,23 @@ spec:
- name: sidecar-nse
image: networkservicemesh/4g-network-sidecar-nse:latest
imagePullPolicy: IfNotPresent
env:
- name: ENDPOINT_NETWORK_SERVICE
value: "4g-network"
- name: ENDPOINT_LABELS
value: "app=mme"
- name: TRACER_ENABLED
value: "true"
- name: IP_ADDRESS
value: "10.60.1.0/24"
resources:
limits:
networkservicemesh.io/socket: 1
volumeMounts:
- name: nsm-endpoints
mountPath: /etc/nsminfo
- name: mme
image: alpine:latest
command: ["tail", "-f", "/dev/null"]
imagePullPolicy: IfNotPresent
volumes:
- name: nsm-endpoints
downwardAPI:
items:
- path: endpoints
fieldRef:
fieldPath: metadata.annotations['ns.networkservicemesh.io/endpoints']
metadata:
name: mme
namespace: default
30 changes: 21 additions & 9 deletions examples/4g-network/k8s/endpoint-p-gw-c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ spec:
networkservicemesh.io/app: "p-gw-c"
template:
metadata:
annotations:
ns.networkservicemesh.io/endpoints: |
{
"name": "4g-network",
"tracerEnabled": true,
"networkServices": [
{"link": "s5s8-c", "labels": "app=p-gw-c", "ipAddress": "10.60.4.0/24"},
{"link": "gx", "labels": "app=p-gw-c", "ipAddress": "10.60.5.0/24"},
{"link": "sxb", "labels": "app=p-gw-c", "ipAddress": "10.60.6.0/24"}
]
}
labels:
networkservicemesh.io/app: "p-gw-c"
networkservicemesh.io/impl: "4g-network"
Expand All @@ -16,22 +27,23 @@ spec:
- name: sidecar-nse
image: networkservicemesh/4g-network-sidecar-nse:latest
imagePullPolicy: IfNotPresent
env:
- name: ENDPOINT_NETWORK_SERVICE
value: "4g-network"
- name: ENDPOINT_LABELS
value: "app=p-gw-c"
- name: TRACER_ENABLED
value: "true"
- name: IP_ADDRESS
value: "10.60.2.0/24"
resources:
limits:
networkservicemesh.io/socket: 1
volumeMounts:
- name: nsm-endpoints
mountPath: /etc/nsminfo
- name: p-gw-c
image: alpine:latest
command: ["tail", "-f", "/dev/null"]
imagePullPolicy: IfNotPresent
volumes:
- name: nsm-endpoints
downwardAPI:
items:
- path: endpoints
fieldRef:
fieldPath: metadata.annotations['ns.networkservicemesh.io/endpoints']
metadata:
name: p-gw-c
namespace: default
30 changes: 21 additions & 9 deletions examples/4g-network/k8s/endpoint-s-gw-u.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ spec:
networkservicemesh.io/app: "s-gw-u"
template:
metadata:
annotations:
ns.networkservicemesh.io/endpoints: |
{
"name": "4g-network",
"tracerEnabled": true,
"networkServices": [
{"link": "s1-u", "labels": "app=s-gw-u", "ipAddress": "10.60.7.0/24"},
{"link": "sxa", "labels": "app=s-gw-u", "ipAddress": "10.60.8.0/24"},
{"link": "s5s8-u", "labels": "app=s-gw-u", "ipAddress": "10.60.9.0/24"}
]
}
labels:
networkservicemesh.io/app: "s-gw-u"
networkservicemesh.io/impl: "4g-network"
Expand All @@ -16,22 +27,23 @@ spec:
- name: sidecar-nse
image: networkservicemesh/4g-network-sidecar-nse:latest
imagePullPolicy: IfNotPresent
env:
- name: ENDPOINT_NETWORK_SERVICE
value: "4g-network"
- name: ENDPOINT_LABELS
value: "app=s-gw-u"
- name: TRACER_ENABLED
value: "true"
- name: IP_ADDRESS
value: "10.60.3.0/24"
resources:
limits:
networkservicemesh.io/socket: 1
volumeMounts:
- name: nsm-endpoints
mountPath: /etc/nsminfo
- name: s-gw-u
image: alpine:latest
command: ["tail", "-f", "/dev/null"]
imagePullPolicy: IfNotPresent
volumes:
- name: nsm-endpoints
downwardAPI:
items:
- path: endpoints
fieldRef:
fieldPath: metadata.annotations['ns.networkservicemesh.io/endpoints']
metadata:
name: s-gw-u
namespace: default
29 changes: 20 additions & 9 deletions examples/4g-network/k8s/endpoint-tdf-u.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ spec:
networkservicemesh.io/app: "tdf-u"
template:
metadata:
annotations:
ns.networkservicemesh.io/endpoints: |
{
"name": "4g-network",
"tracerEnabled": true,
"networkServices": [
{"link": "sgi", "labels": "app=tdf-u", "ipAddress": "10.60.10.0/24"},
{"link": "sxc", "labels": "app=tdf-u", "ipAddress": "10.60.11.0/24"}
]
}
labels:
networkservicemesh.io/app: "tdf-u"
networkservicemesh.io/impl: "4g-network"
Expand All @@ -16,22 +26,23 @@ spec:
- name: sidecar-nse
image: networkservicemesh/4g-network-sidecar-nse:latest
imagePullPolicy: IfNotPresent
env:
- name: ENDPOINT_NETWORK_SERVICE
value: "4g-network"
- name: ENDPOINT_LABELS
value: "app=tdf-u"
- name: TRACER_ENABLED
value: "true"
- name: IP_ADDRESS
value: "10.60.4.0/24"
resources:
limits:
networkservicemesh.io/socket: 1
volumeMounts:
- name: nsm-endpoints
mountPath: /etc/nsminfo
- name: tdf-u
image: alpine:latest
command: ["tail", "-f", "/dev/null"]
imagePullPolicy: IfNotPresent
volumes:
- name: nsm-endpoints
downwardAPI:
items:
- path: endpoints
fieldRef:
fieldPath: metadata.annotations['ns.networkservicemesh.io/endpoints']
metadata:
name: tdf-u
namespace: default
44 changes: 44 additions & 0 deletions examples/4g-network/sidecar-nse/cmd/endpoints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2020 Samsung Electronics
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import "encoding/json"

// Endpoint contains the information to create NSM objects
type Endpoint struct {
Name string `json:"name"`
TracerEnabled bool `json:"tracerEnabled"`
NetworkServices []NetworkService `json:"networkServices"`
}

// NetworkService contains the information to create NSM objects
type NetworkService struct {
Link string `json:"link"`
Labels string `json:"labels"`
IPAddress string `json:"ipAddress"`
Route string `json:"route"`
}

// GetEndpoint parses a stream of bytes to a Endpoint struct
func GetEndpoint(endpointsFile []byte) (Endpoint, error) {
var endpointsConfig Endpoint

if err := json.Unmarshal(endpointsFile, &endpointsConfig); err != nil {
return endpointsConfig, err
}

return endpointsConfig, nil
}
87 changes: 87 additions & 0 deletions examples/4g-network/sidecar-nse/cmd/endpoints_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2020 Samsung Electronics
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"reflect"
"strings"
"testing"
)

func TestRead(t *testing.T) {
testCases := []struct {
label string
input []byte
expectedError string
expected Endpoint
}{
{
label: "Empty annotation file",
input: []byte(``),
expectedError: "unexpected end of JSON input",
},
{
label: "Invalid annotation format",
input: []byte(`{}`),
},
{
label: "Read annotations file successfuly",
input: []byte(`{
"name": "lte-network",
"networkServices": [
{"link": "s5u", "labels": "app=pgw-s5u", "ipAddress": "172.25.0.0/24"},
{"link": "sgi", "labels": "app=http-server-sgi", "ipAddress": "10.0.1.0/24", "route": "10.0.3.0/24"}
]
}`),
expected: Endpoint{
Name: "lte-network",
NetworkServices: []NetworkService{
NetworkService{
Link: "s5u",
Labels: "app=pgw-s5u",
IPAddress: "172.25.0.0/24",
},
NetworkService{
Link: "sgi",
Labels: "app=http-server-sgi",
IPAddress: "10.0.1.0/24",
Route: "10.0.3.0/24",
},
},
},
},
}

for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
got, err := GetEndpoint(testCase.input)
if err != nil {
if testCase.expectedError == "" {
t.Fatalf("GetEndpoints returned an unexpected error %s", err)
}
if !strings.Contains(err.Error(), testCase.expectedError) {
t.Fatalf("GetEndpoints returned an unexpected error %s", err)
}
} else {
if !reflect.DeepEqual(testCase.expected, got) {
t.Errorf("GetEndpoints returned unexpected result: got %v;"+
" expected %v", got, testCase.expected)
}
}
})
}

}
Loading

0 comments on commit e20cc81

Please sign in to comment.