Skip to content

Commit

Permalink
add .pre-commit-commit.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
yunlzheng committed Feb 24, 2020
1 parent f442720 commit c827ca7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- repo: git://github.com/dnephin/pre-commit-golang
rev: master
hooks:
- id: go-fmt
- id: go-lint
- id: go-imports
20 changes: 20 additions & 0 deletions docs/developer/pre-commit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pre Commit
---

> https://pre-commit.com/
## Install

Install pre-commit:

```
pip install pre-commit
# or
brew install pre-commit
```

Apply to local

```
pre-commit install
```
14 changes: 13 additions & 1 deletion pkg/apiserver/controllers/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"k8s.io/apimachinery/pkg/labels"
)

// ClusterController provide kubernetes cluster api
type ClusterController struct {
Context common.Context
}

// Namespaces list namespaces
func (c *ClusterController) Namespaces(context *gin.Context) {
namespaces, err := c.Context.NamespaceLister().List(labels.Everything())
if err != nil {
Expand All @@ -28,6 +30,7 @@ func (c *ClusterController) Namespaces(context *gin.Context) {
context.JSON(200, namespaces)
}

// Services list services
func (c *ClusterController) Services(context *gin.Context) {
namespace := context.Param("namespace")
services, err := c.Context.ServiceLister().Services(namespace).List(labels.Everything())
Expand All @@ -40,19 +43,21 @@ func (c *ClusterController) Services(context *gin.Context) {
context.JSON(200, services)
}

// Service get service instance
func (c *ClusterController) Service(context *gin.Context) {
namespace := context.Param("namespace")
name := context.Param("name")
service, err := c.Context.Client().CoreV1().Services(namespace).Get(name, metav1.GetOptions{})
if err != nil {
context.JSON(500, gin.H{
"message": "fail get service",
"message": "fail get service " + name,
})
return
}
context.JSON(200, service)
}

// Endpoints list endpoints
func (c *ClusterController) Endpoints(context *gin.Context) {
namespace := context.Param("namespace")
endpoints, err := c.Context.EndpointsLister().Endpoints(namespace).List(labels.Everything())
Expand All @@ -65,6 +70,7 @@ func (c *ClusterController) Endpoints(context *gin.Context) {
context.JSON(200, endpoints)
}

// Endpoint get endpoint instance
func (c *ClusterController) Endpoint(context *gin.Context) {
namespace := context.Param("namespace")
name := context.Param("name")
Expand All @@ -78,6 +84,7 @@ func (c *ClusterController) Endpoint(context *gin.Context) {
context.JSON(200, endpoint)
}

// Deployments list deployments
func (c *ClusterController) Deployments(context *gin.Context) {
namespace := context.Param("namespace")
selector := context.Query("selector")
Expand Down Expand Up @@ -106,6 +113,7 @@ func (c *ClusterController) Deployments(context *gin.Context) {
context.JSON(200, resource)
}

// Deployment get deployment instance
func (c *ClusterController) Deployment(context *gin.Context) {
namespace := context.Param("namespace")
name := context.Param("name")
Expand All @@ -119,6 +127,7 @@ func (c *ClusterController) Deployment(context *gin.Context) {
context.JSON(200, resource)
}

// ReplicaSet get replicaSet instance
func (c *ClusterController) ReplicaSet(context *gin.Context) {
namespace := context.Param("namespace")
name := context.Param("name")
Expand All @@ -132,6 +141,7 @@ func (c *ClusterController) ReplicaSet(context *gin.Context) {
context.JSON(200, resource)
}

// Pods list pods
func (c *ClusterController) Pods(context *gin.Context) {
namespace := context.Param("namespace")
selector := context.Query("selector")
Expand All @@ -156,6 +166,7 @@ func (c *ClusterController) Pods(context *gin.Context) {
context.JSON(200, pods)
}

// Pod get pod instance
func (c *ClusterController) Pod(context *gin.Context) {
namespace := context.Param("namespace")
name := context.Param("name")
Expand All @@ -170,6 +181,7 @@ func (c *ClusterController) Pod(context *gin.Context) {
context.JSON(200, pod)
}

// PodLog get pod log
func (c *ClusterController) PodLog(context *gin.Context) {
namespace := context.Param("namespace")
podID := context.Param("name")
Expand Down

0 comments on commit c827ca7

Please sign in to comment.