Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task] add endpoint for getting ovs shell info #328

Merged
merged 5 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [Get Network](#get-network)
- [Get Network Status](#get-network-status)
- [Delete Network](#delete-network)
- [Get Open vSwitch Shell Infomation](#get-open-vswitch-shell-information)
- [Storage](#storage)
- [Create Storage](#create-storage)
- [List Storage](#list-storage)
Expand Down Expand Up @@ -480,6 +481,26 @@ Response Data:
}
```

### Get Open vSwitch Shell Information

**DELETE /v1/networks/[nodeName]/shell**

Example:

```
curl -X GET http://localhost:7890/v1/networks/node-1/shell
```

Response Data:

```json
{
"namespace": "vortex",
"podName": "openvswitch-exec-df12a",
"containerName": "openvswitch-exec"
}
```

## Storage
### Create Storage

Expand Down
3 changes: 3 additions & 0 deletions config/k8s.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"registry": {
"url": "https://dockerhub.pw"
},
"kubernetes": {
"systemNamespace": "vortex"
},
"logger": {
"dir": "./logs",
"level": "debug",
Expand Down
3 changes: 3 additions & 0 deletions config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"registry": {
"url": "https://dockerhub.pw"
},
"kubernetes": {
"systemNamespace": "vortex"
},
"logger": {
"dir": "./logs",
"level": "debug",
Expand Down
3 changes: 3 additions & 0 deletions config/testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"registry": {
"url": "https://dockerhub.pw"
},
"kubernetes": {
"systemNamespace": "vortex"
},
"logger": {
"dir": "./logs",
"level": "debug",
Expand Down
1 change: 1 addition & 0 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
Mongo *mongo.MongoConfig `json:"mongo"`
Prometheus *prometheusprovider.PrometheusConfig `json:"prometheus"`
Registry *registry.Config `json:"registry"`
Kubernetes *kubernetesConfig `json:"kubernetes"`
Logger logger.LoggerConfig `json:"logger"`

// the version settings of the current application
Expand Down
5 changes: 5 additions & 0 deletions src/config/kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package config

type kubernetesConfig struct {
SystemNamespace string `json:"systemNamespace"`
}
46 changes: 46 additions & 0 deletions src/server/handler_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"net/http"
"strconv"
"strings"

"github.com/linkernetworks/utils/timeutils"
"github.com/linkernetworks/vortex/src/entity"
Expand All @@ -19,6 +20,12 @@ import (
"gopkg.in/mgo.v2/bson"
)

type shellOVSInfoResponse struct {
Namespace string `json:"namespace"`
PodName string `json:"podName"`
ContainerName string `json:"containerName"`
}

func createNetworkHandler(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
userID, ok := req.Attribute("UserID").(string)
Expand Down Expand Up @@ -247,3 +254,42 @@ func deleteNetworkHandler(ctx *web.Context) {
Message: "Delete success",
})
}

func getOVSShellInfoHandler(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
nodeName := req.PathParameter("node")

pods, err := sp.KubeCtl.GetPods(sp.Config.Kubernetes.SystemNamespace)
if err != nil {
response.InternalServerError(req.Request, resp.ResponseWriter, err)
return
}

var podName, containerName string
if len(pods) == 0 {
resp.WriteHeaderAndEntity(http.StatusNotFound, shellOVSInfoResponse{
Namespace: sp.Config.Kubernetes.SystemNamespace,
PodName: "none",
ContainerName: "none",
})
return
}

for _, pod := range pods {
// find all pod list in right node
if nodeName == pod.Spec.NodeName {
// find the openvswitch-exec pod
if strings.HasPrefix(pod.ObjectMeta.Name, "openvswitch-exec") {
podName = pod.ObjectMeta.Name
// openvswitch-exec should only has one container
containerName = pod.Spec.Containers[0].Name
}
}
}

resp.WriteHeaderAndEntity(http.StatusOK, shellOVSInfoResponse{
Namespace: sp.Config.Kubernetes.SystemNamespace,
PodName: podName,
ContainerName: containerName,
})
}
11 changes: 11 additions & 0 deletions src/server/handler_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,14 @@ func (suite *NetworkTestSuite) TestListNetworkWithInvalidPage() {
suite.wc.Dispatch(httpWriter, httpRequest)
assertResponseCode(suite.T(), http.StatusInternalServerError, httpWriter)
}

func (suite *NetworkTestSuite) TestGetOVSShellInfoNotFound() {
notFoundNodeName := "node-55"
httpRequest, err := http.NewRequest("GET", "http://localhost:7890/v1/networks/"+notFoundNodeName+"/shell", nil)
suite.NoError(err)
httpRequest.Header.Add("Authorization", suite.JWTBearer)

httpWriter := httptest.NewRecorder()
suite.wc.Dispatch(httpWriter, httpRequest)
assertResponseCode(suite.T(), http.StatusNotFound, httpWriter)
}
1 change: 1 addition & 0 deletions src/server/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func newNetworkService(sp *serviceprovider.Container) *restful.WebService {
webService.Route(webService.GET("/status/{id}").To(handler.RESTfulServiceHandler(sp, getNetworkStatusHandler)))
webService.Route(webService.POST("/").To(handler.RESTfulServiceHandler(sp, createNetworkHandler)))
webService.Route(webService.DELETE("/{id}").To(handler.RESTfulServiceHandler(sp, deleteNetworkHandler)))
webService.Route(webService.GET("/{node}/shell").To(handler.RESTfulServiceHandler(sp, getOVSShellInfoHandler)))
return webService
}

Expand Down