Skip to content

Commit

Permalink
Add the comment and change the restful handler to private
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchiu committed Jun 24, 2018
1 parent 195093e commit 1dde7c3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/kubernetes/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ import (
"k8s.io/client-go/kubernetes"
)

/*
KubeCtl object is used to interact with the kubernetes cluster.
Use the export function New to Get a KubeCtl object.
*/
type KubeCtl struct {
Clientset kubernetes.Interface
Namespace string
}

/*
The API to New a kubectl object and you need to pass two parameters
1. The kubernetes clientset object from the client-go library. You can also use the fake-client for testing
2. The namespace of the kubernetes you want to manipulate
*/
func New(clientset kubernetes.Interface, namespace string) *KubeCtl {
return &KubeCtl{
Clientset: clientset,
Expand Down
3 changes: 3 additions & 0 deletions src/kubernetes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

//Get the Node object by the node name
func (kc *KubeCtl) GetNode(name string) (*corev1.Node, error) {
return kc.Clientset.CoreV1().Nodes().Get(name, metav1.GetOptions{})
}

//Get all nodes from the k8s cluster
func (kc *KubeCtl) GetNodes() ([]*corev1.Node, error) {
nodes := []*corev1.Node{}
nodesList, err := kc.Clientset.CoreV1().Nodes().List(metav1.ListOptions{})
Expand All @@ -21,6 +23,7 @@ func (kc *KubeCtl) GetNodes() ([]*corev1.Node, error) {
return nodes, nil
}

//Get the external IP address of node
func (kc *KubeCtl) GetNodeExternalIP(name string) (string, error) {
node, err := kc.GetNode(name)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/server/handler_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/linkernetworks/vortex/src/serviceprovider"
)

func VersionHandler(sp *serviceprovider.Container) restful.RouteFunction {
func versionHandler(sp *serviceprovider.Container) restful.RouteFunction {
return func(req *restful.Request, resp *restful.Response) {
}
}
2 changes: 1 addition & 1 deletion src/server/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (a *App) AppRoute() *mux.Router {
func newVersionService(sp *serviceprovider.Container) *restful.WebService {
webService := new(restful.WebService)
webService.Path("/v1/versions").Consumes(restful.MIME_JSON, restful.MIME_JSON).Produces(restful.MIME_JSON, restful.MIME_JSON)
webService.Route(webService.GET("/").To(VersionHandler(sp)))
webService.Route(webService.GET("/").To(versionHandler(sp)))
return webService
}

Expand Down

0 comments on commit 1dde7c3

Please sign in to comment.