Skip to content

Commit

Permalink
Merge pull request #9 from containerum/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MargoTuleninova committed Jul 20, 2018
2 parents c2eea33 + 9dc1ab9 commit 3134fab
Show file tree
Hide file tree
Showing 168 changed files with 19,884 additions and 12,638 deletions.
71 changes: 37 additions & 34 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pkg/kubernetes/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ const (
quotaName = "quota"
)

//GetNamespaceList returns namespaces list
func (k *Kube) GetNamespaceList(owner string) (*api_core.NamespaceList, error) {
quotas, err := k.CoreV1().Namespaces().List(api_meta.ListOptions{
LabelSelector: getOwnerLabel(owner),
})
if err != nil {
log.WithField("Owner", owner).Error(err)
return nil, err
}
return quotas, nil
}

//GetNamespaceQuotaList returns namespaces (quotas) list
func (k *Kube) GetNamespaceQuotaList(owner string) (*api_core.ResourceQuotaList, error) {
quotas, err := k.CoreV1().ResourceQuotas("").List(api_meta.ListOptions{
Expand Down
14 changes: 5 additions & 9 deletions pkg/model/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,16 @@ func makeContainerVolumes(volumes []kube_types.ContainerVolume, configMaps []kub

func makeContainerEnv(env []kube_types.Env) []api_core.EnvVar {
envvar := make([]api_core.EnvVar, 0)
if env != nil {
for _, v := range env {
envvar = append(envvar, api_core.EnvVar{Name: v.Name, Value: v.Value})
}
for _, v := range env {
envvar = append(envvar, api_core.EnvVar{Name: v.Name, Value: v.Value})
}
return envvar
}

func makeContainerPorts(ports []kube_types.ContainerPort) []api_core.ContainerPort {
contports := make([]api_core.ContainerPort, 0)
if ports != nil {
for _, v := range ports {
contports = append(contports, api_core.ContainerPort{ContainerPort: int32(v.Port), Protocol: api_core.Protocol(v.Protocol), Name: v.Name})
}
for _, v := range ports {
contports = append(contports, api_core.ContainerPort{ContainerPort: int32(v.Port), Protocol: api_core.Protocol(v.Protocol), Name: v.Name})
}
return contports
}
Expand Down Expand Up @@ -376,7 +372,7 @@ func UpdateImage(deployment interface{}, containerName, newimage string) (*api_a
break
}
}
if updated == false {
if !updated {
return nil, fmt.Errorf(noContainer, containerName)
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/model/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ func (endpoint *Endpoint) ToKube(nsName string, labels map[string]string) (*api_

func makeEndpointPorts(ports []Port) []api_core.EndpointPort {
endpointports := make([]api_core.EndpointPort, 0)
if ports != nil {
for _, v := range ports {
endpointports = append(endpointports, api_core.EndpointPort{Name: v.Name, Protocol: api_core.Protocol(v.Protocol), Port: int32(v.Port)})
}
for _, v := range ports {
endpointports = append(endpointports, api_core.EndpointPort{Name: v.Name, Protocol: api_core.Protocol(v.Protocol), Port: int32(v.Port)})
}
return endpointports
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
const (
ownerLabel = "owner"

minNamespaceCPU = 300 //m
minNamespaceMemory = 512 //Mi
minNamespaceCPU = 10 //m
minNamespaceMemory = 10 //Mi
maxNamespaceCPU = 12000 //m
maxNamespaceMemory = 28672 //Mi
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ParseKubePod(pod interface{}, parseforuser bool) kube_types.Pod {
return newPod
}

func getContainers(cListi interface{}, mode map[string]int32, storageName map[string]string, replicas int) (containers []model.Container, totalcpu api_resource.Quantity, totalmem api_resource.Quantity) {
func getContainers(cListi interface{}, mode map[string]int32, storageName map[string]string, replicas int) (containers []model.Container, totalcpu, totalmem api_resource.Quantity) {
cList := cListi.([]api_core.Container)
for _, c := range cList {
env := getEnv(c.Env)
Expand Down
6 changes: 2 additions & 4 deletions pkg/model/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ func (secret *SecretWithParam) ToKube(nsName string, labels map[string]string) (

func makeSecretData(data map[string]string) map[string][]byte {
newData := make(map[string][]byte, 0)
if data != nil {
for k, v := range data {
newData[k] = []byte(v)
}
for k, v := range data {
newData[k] = []byte(v)
}
return newData
}
Expand Down
20 changes: 9 additions & 11 deletions pkg/model/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,16 @@ func (service *ServiceWithParam) ToKube(nsName string, labels map[string]string)

func makeServicePorts(ports []kube_types.ServicePort) []api_core.ServicePort {
var serviceports []api_core.ServicePort
if ports != nil {
for _, port := range ports {
if port.Port == nil {
port.Port = &port.TargetPort
}
serviceports = append(serviceports, api_core.ServicePort{
Name: port.Name,
Protocol: api_core.Protocol(port.Protocol),
Port: int32(*port.Port),
TargetPort: intstr.FromInt(port.TargetPort),
})
for _, port := range ports {
if port.Port == nil {
port.Port = &port.TargetPort
}
serviceports = append(serviceports, api_core.ServicePort{
Name: port.Name,
Protocol: api_core.Protocol(port.Protocol),
Port: int32(*port.Port),
TargetPort: intstr.FromInt(port.TargetPort),
})
}
return serviceports
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/model/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ import "github.com/google/uuid"
//IsValidUUID checks if UUID is valid
func IsValidUUID(u string) bool {
_, err := uuid.Parse(u)
if err != nil {
return false
}
return true
return err == nil
}
38 changes: 25 additions & 13 deletions pkg/router/handlers/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package handlers
import (
"net/http"

"sync"

"git.containerum.net/ch/kube-api/pkg/kubeErrors"
"git.containerum.net/ch/kube-api/pkg/kubernetes"
"git.containerum.net/ch/kube-api/pkg/model"
Expand All @@ -12,6 +14,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)

const (
Expand Down Expand Up @@ -347,20 +350,29 @@ func GetSelectedConfigMaps(ctx *gin.Context) {
role := ctx.MustGet(m.UserRole).(string)
if role == m.RoleUser {
nsList := ctx.MustGet(m.UserNamespaces).(*model.UserHeaderDataMap)
var g errgroup.Group
var mutex = &sync.Mutex{}
for _, n := range *nsList {
cmList, err := kube.GetConfigMapList(n.ID)
if err != nil {
gonic.Gonic(kubeErrors.ErrUnableGetResourcesList(), ctx)
return
}

cm, err := model.ParseKubeConfigMapList(cmList, role == m.RoleUser)
if err != nil {
gonic.Gonic(kubeErrors.ErrUnableGetResourcesList(), ctx)
return
}

ret[n.ID] = *cm
currentNs := n
g.Go(func() error {
cmList, err := kube.GetConfigMapList(currentNs.ID)
if err != nil {
return err
}
cm, err := model.ParseKubeConfigMapList(cmList, role == m.RoleUser)
if err != nil {
return err
}
mutex.Lock()
ret[currentNs.ID] = *cm
mutex.Unlock()
return nil
})
}
if err := g.Wait(); err != nil {
ctx.Error(err)
gonic.Gonic(kubeErrors.ErrUnableGetResourcesList(), ctx)
return
}
}

Expand Down
Loading

0 comments on commit 3134fab

Please sign in to comment.