diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..47a43cf0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +- repo: git://github.com/dnephin/pre-commit-golang + rev: master + hooks: + - id: go-fmt + - id: go-lint + - id: go-imports \ No newline at end of file diff --git a/docs/developer/pre-commit.md b/docs/developer/pre-commit.md new file mode 100644 index 00000000..d8a9be79 --- /dev/null +++ b/docs/developer/pre-commit.md @@ -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 +``` diff --git a/pkg/apiserver/controllers/cluster.go b/pkg/apiserver/controllers/cluster.go index e1e12a9b..2189a688 100644 --- a/pkg/apiserver/controllers/cluster.go +++ b/pkg/apiserver/controllers/cluster.go @@ -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 { @@ -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()) @@ -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()) @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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")