Skip to content

Commit

Permalink
Fix golint for types & functions need comment
Browse files Browse the repository at this point in the history
The files are:
- src/entity/{metrics_container.go, metrics_service.go, service.go}
- src/kubernetes/deployment.go
- src/net/http/{handler.go, responsetest/assert.go}
- src/networkprovider/network.go
- src/prometheuscontroller/query.go
- src/volume/volume.go
- src/web/context.go
  • Loading branch information
sufuf3 committed Jul 23, 2018
1 parent 6c5d2bc commit 180b050
Show file tree
Hide file tree
Showing 29 changed files with 100 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/linkernetworks/vortex/src/prometheusprovider"
)

// Config is the structure for vortex
type Config struct {
Redis *redis.RedisConfig `json:"redis"`
Mongo *mongo.MongoConfig `json:"mongo"`
Expand All @@ -21,20 +22,22 @@ type Config struct {
Version string `json:"version"`
}

// Read will read config file
func Read(path string) (c Config, err error) {
file, err := os.Open(path)
if err != nil {
return c, fmt.Errorf("Failed to open the config file: %v\n", err)
return c, fmt.Errorf("Failed to open the config file: %v", err)
}
defer file.Close()
decoder := json.NewDecoder(file)
if err := decoder.Decode(&c); err != nil {
return c, fmt.Errorf("Failed to load the config file: %v\n", err)
return c, fmt.Errorf("Failed to load the config file: %v", err)
}

return c, nil
}

// MustRead will read config path
func MustRead(path string) Config {
c, err := Read(path)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions src/entity/metrics_container.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package entity

// ContainerResourceMetrics is the sructure for Container Resource Metrics
type ContainerResourceMetrics struct {
CPUUsagePercentage float32 `json:"cpuUsagePercentage"`
MemoryUsageBytes float32 `json:"memoryUsageBytes"`
}

// ContainerStatusMetrics is the sructure for Container Status Metrics
type ContainerStatusMetrics struct {
Status string `json:"status"`
WaitingReason string `json:"waitingReason"`
TerminatedReason string `json:"terminatedReason"`
RestartTime int `json:"restartTime"`
}

// ContainerDetailMetrics is the sructure for Container Detail Metrics
type ContainerDetailMetrics struct {
ContainerName string `json:"containerName"`
CreatedAt int `json:"createAt"`
Expand All @@ -22,6 +25,8 @@ type ContainerDetailMetrics struct {
Command []string `json:"command"`
vNIC string `json:"vNic"`
}

// ContainerMetrics is the structure for Container Metrics
type ContainerMetrics struct {
Detail ContainerDetailMetrics `json:"detail"`
Status ContainerStatusMetrics `json:"status"`
Expand Down
1 change: 1 addition & 0 deletions src/entity/metrics_controller.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entity

// ControllerMetrics is the structure for Controller Metrics
type ControllerMetrics struct {
ControllerName string `json:"controllerName"`
Type string `json:"type"`
Expand Down
7 changes: 7 additions & 0 deletions src/entity/metrics_node.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package entity

// NICNetworkTrafficMetrics is the structure for NIC metwork traffic metrics
type NICNetworkTrafficMetrics struct {
ReceiveBytesTotal int `json:"receiveBytesTotal"`
TransmitBytesTotal int `json:"transmitBytesTotal"`
ReceivePacketsTotal int `json:"receivePacketsTotal"`
TransmitPacketsTotal int `json:"transmitPacketsTotal"`
}

// NICMetrics is the structure for NIC metrics
type NICMetrics struct {
Default bool `json:"default"`
Type string `json:"type"`
Expand All @@ -15,13 +17,15 @@ type NICMetrics struct {
NICNetworkTraffic NICNetworkTrafficMetrics `json:"nicNetworkTraffic"`
}

// NICOverviewMetrics is the structure for NIC overview metrics
type NICOverviewMetrics struct {
Name string `json:"name"`
Default bool `json:"default"`
Type string `json:"type"`
PCIID string `json:"pciID"`
}

// NodeResourceMetrics is the structure for node resource metrics
type NodeResourceMetrics struct {
CPURequests float32 `json:"cpuRequests"`
CPULimits float32 `json:"cpuLimits"`
Expand All @@ -37,6 +41,7 @@ type NodeResourceMetrics struct {
CapacityEphemeralStorage float32 `json:"capacityEphemeralStorage"`
}

// NodeDetailMetrics is the structure for node detail metrics
type NodeDetailMetrics struct {
Hostname string `json:"hostname"`
CreatedAt int `json:"createAt"`
Expand All @@ -48,10 +53,12 @@ type NodeDetailMetrics struct {
Labels map[string]string `json:"labels"`
}

// NodeNICsMetrics is the structure for node NICs metrics
type NodeNICsMetrics struct {
NICs []NICOverviewMetrics `json:"nics"`
}

// NodeMetrics is the structure for node metrics
type NodeMetrics struct {
Detail NodeDetailMetrics `json:"detail"`
Resource NodeResourceMetrics `json:"resource"`
Expand Down
1 change: 1 addition & 0 deletions src/entity/metrics_pod.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entity

// PodMetrics is the structure for Pod metrics
type PodMetrics struct {
PodName string `json:"podName"`
Namespace string `json:"namespace"`
Expand Down
1 change: 1 addition & 0 deletions src/entity/metrics_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"k8s.io/api/core/v1"
)

// ServiceMetrics is the structure for Service Metrics
type ServiceMetrics struct {
ServiceName string `json:"serviceName"`
Namespace string `json:"namespace"`
Expand Down
8 changes: 7 additions & 1 deletion src/entity/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,34 @@ import (
"gopkg.in/mgo.v2/bson"
)

// NetworkType is the string for network type
type NetworkType string

// These are const
const (
OVSKernelspaceNetworkType NetworkType = "system"
OVSUserspaceNetworkType NetworkType = "netdev"
FakeNetworkType NetworkType = "fake"
)

// The const for NetworkCollectionName
const (
NetworkCollectionName string = "networks"
)

// PhyInterface is the structure for physical interface
type PhyInterface struct {
Name string `bson:"name" json:"name" validate:"required"`
PCIID string `bson:"pciID" json:"pciID" validate:"-"`
}

// Node is the structure for node info
type Node struct {
Name string `bson:"name" json:"name" validate:"required"`
PhyInterfaces []PhyInterface `bson:"physicalInterfaces" json:"physicalInterfaces" validate:"required,dive,required"`
}

// Network is the structure for Network info
type Network struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Type NetworkType `bson:"type" json:"type" validate:"required"`
Expand All @@ -45,7 +51,7 @@ func (m Network) GetCollection() string {
return NetworkCollectionName
}

// Validate VLAN tags
// ValidateVLANTags will validate VLAN tags
func ValidateVLANTags(vlanTags []int32) error {
for _, tag := range vlanTags {
if tag < 0 || tag > 4095 {
Expand Down
7 changes: 6 additions & 1 deletion src/entity/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import (
"gopkg.in/mgo.v2/bson"
)

// PodCollectionName's const
const (
PodCollectionName string = "pods"
)

// Container is the structure for init Container info
type Container struct {
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Image string `bson:"image" json:"image" validate:"required"`
Command []string `bson:"command" json:"command" validate:"required,dive,required"`
}

// PodNetwork is the structure for pod network info
type PodNetwork struct {
Name string `bson:"name" json:"name"`
IfName string `bson:"ifName" json:"ifName"`
Expand All @@ -25,11 +28,13 @@ type PodNetwork struct {
BridgeName string `bson:"bridgeName" json:"bridgeName"` //its from the entity.Network entity
}

// PodVolume is the structure for pof volume info
type PodVolume struct {
Name string `bson:"name" json:"name" validate:"required"`
MountPath string `bson:"mountPath" json:"mountPath" validate:"required"`
}

// Pod is the structure for pod info
type Pod struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Expand All @@ -41,7 +46,7 @@ type Pod struct {
Networks []PodNetwork `bson:"networks,omitempty" json:"networks" validate:"required,dive,required"`
}

//GetCollection - get model mongo collection name.
// GetCollection - get model mongo collection name.
func (m Pod) GetCollection() string {
return PodCollectionName
}
1 change: 1 addition & 0 deletions src/entity/response.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entity

// Response is the structure for Response
type Response struct {
Status string `json:"status"`
Info interface{} `json:"info"`
Expand Down
3 changes: 3 additions & 0 deletions src/entity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import (
"gopkg.in/mgo.v2/bson"
)

// the const for ServiceCollectionName
const (
ServiceCollectionName string = "services"
)

// ServicePort is the structure for service port
type ServicePort struct {
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Port int32 `bson:"port" json:"port" validate:"required"`
TargetPort int `bson:"targetPort" json:"targetPort" validate:"required,max=65535,min=1"`
NodePort int32 `bson:"nodePort" json:"nodePort" validate:"max=32767,min=30000"`
}

// Service is the structure for service
type Service struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Expand Down
6 changes: 5 additions & 1 deletion src/entity/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import (
"gopkg.in/mgo.v2/bson"
)

// StorageType is string
type StorageType string

// The const for storage type
const (
NFSStorageType = "nfs"
FakeStorageType = "fake"
)

// The const for StorageCollectionName
const (
StorageCollectionName string = "storage"
)

// Storage is the Storage info
type Storage struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Type StorageType `bson:"type" json:"type" validate:"required"`
Expand All @@ -28,7 +32,7 @@ type Storage struct {
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty" validate:"-"`
}

//GetCollection - get model mongo collection name.
// GetCollection - get model mongo collection name.
func (m Storage) GetCollection() string {
return StorageCollectionName
}
1 change: 1 addition & 0 deletions src/entity/storage_fake.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package entity

// FakeStorage is the structure for Fake Storage
type FakeStorage struct {
FakeParameter string
IWantFail bool
Expand Down
10 changes: 5 additions & 5 deletions src/entity/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import (
corev1 "k8s.io/api/core/v1"
)

// The const for volume & PVC
const (
VolumeCollectionName string = "volume"
PVCNamePrefix string = "pvc-"
)

/*
Users will create the Volume from the storage and they can use those volumes in their containers
In the kubernetes implementation, it's PVC
So the Volume will create a PVC type and connect to a known StorageClass
*/
// Volume is the structure. Users will create the Volume from the storage and
// they can use those volumes in their containers. In the kubernetes implementation, it's PVC
// So the Volume will create a PVC type and connect to a known StorageClass
type Volume struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required"`
Expand All @@ -31,6 +30,7 @@ func (m Volume) GetCollection() string {
return VolumeCollectionName
}

// GetPVCName will get pvc name
func (m Volume) GetPVCName() string {
return PVCNamePrefix + m.ID.Hex()
}
3 changes: 3 additions & 0 deletions src/errors/network.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package errors

// ErrInvalidVLAN is the sturcture
type ErrInvalidVLAN struct {
message string
}

// NewErrInvalidVLAN will return error if new an invalid VLAN
func NewErrInvalidVLAN(message string) *ErrInvalidVLAN {
return &ErrInvalidVLAN{
message: message,
}
}

// Error will reture the error message
func (e *ErrInvalidVLAN) Error() string {
return e.message
}
5 changes: 4 additions & 1 deletion src/kubernetes/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

//Get the external IP address of node
// CreateDeployment will get the external IP address of node
func (kc *KubeCtl) CreateDeployment(deployment *appsv1.Deployment, namespace string) (*appsv1.Deployment, error) {
return kc.Clientset.AppsV1().Deployments(namespace).Create(deployment)
}

// GetDeployment will get deploy
func (kc *KubeCtl) GetDeployment(name string, namespace string) (*appsv1.Deployment, error) {
return kc.Clientset.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{})
}

// GetDeployments will get deploys
func (kc *KubeCtl) GetDeployments(namespace string) ([]*appsv1.Deployment, error) {
deployments := []*appsv1.Deployment{}
deploymentsList, err := kc.Clientset.AppsV1().Deployments(namespace).List(metav1.ListOptions{})
Expand All @@ -26,6 +28,7 @@ func (kc *KubeCtl) GetDeployments(namespace string) ([]*appsv1.Deployment, error
return deployments, nil
}

// DeleteDeployment will delete deploy
func (kc *KubeCtl) DeleteDeployment(name string, namespace string) error {
return kc.Clientset.AppsV1().Deployments(namespace).Delete(name, &metav1.DeleteOptions{})
}
8 changes: 4 additions & 4 deletions src/net/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/linkernetworks/vortex/src/web"
)

// The interface for native http handler(http.Request and http.ResponseWriter)
// NativeContextHandler is the interface for native http handler(http.Request and http.ResponseWriter)
type NativeContextHandler func(*web.NativeContext)

// CompositeServiceProvider apply mongo client to HandlerFunc
// CompositeServiceHandler apply mongo client to HandlerFunc
func CompositeServiceHandler(sp *serviceprovider.Container, handler NativeContextHandler) http.HandlerFunc {
return func(resp http.ResponseWriter, req *http.Request) {
logger.Infoln(req.Method, req.URL)
Expand All @@ -21,10 +21,10 @@ func CompositeServiceHandler(sp *serviceprovider.Container, handler NativeContex
}
}

// The interface for restfuul handler(restful.Request,restful.Response)
// RESTfulContextHandler is the interface for restfuul handler(restful.Request,restful.Response)
type RESTfulContextHandler func(*web.Context)

// The wrapper to combine the RESTfulContextHandler with our serviceprovider object
// RESTfulServiceHandler is the wrapper to combine the RESTfulContextHandler with our serviceprovider object
func RESTfulServiceHandler(sp *serviceprovider.Container, handler RESTfulContextHandler) restful.RouteFunction {
return func(req *restful.Request, resp *restful.Response) {
ctx := web.Context{sp, req, resp}
Expand Down
Loading

0 comments on commit 180b050

Please sign in to comment.