Skip to content

Commit

Permalink
roolback the code about CRI of version v1alpha1
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <starnop@163.com>
  • Loading branch information
starnop committed Jul 23, 2018
1 parent 2f0b5cf commit 92de646
Show file tree
Hide file tree
Showing 18 changed files with 2,233 additions and 4,149 deletions.
1,209 changes: 0 additions & 1,209 deletions cri/apis/v1alpha1/api.proto

This file was deleted.

13 changes: 2 additions & 11 deletions cri/v1alpha1/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

apitypes "github.com/alibaba/pouch/apis/types"
anno "github.com/alibaba/pouch/cri/annotations"
runtime "github.com/alibaba/pouch/cri/apis/v1alpha1"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/pkg/errtypes"
Expand All @@ -25,6 +24,7 @@ import (
// NOTE: "golang.org/x/net/context" is compatible with standard "context" in golang1.7+.
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/sirupsen/logrus"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

const (
Expand Down Expand Up @@ -497,7 +497,6 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
specAnnotation[anno.ContainerType] = anno.ContainerTypeContainer
specAnnotation[anno.SandboxName] = podSandboxID

resources := r.GetConfig().GetLinux().GetResources()
createConfig := &apitypes.ContainerCreateConfig{
ContainerConfig: apitypes.ContainerConfig{
Entrypoint: config.Command,
Expand All @@ -511,12 +510,9 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
StdinOnce: config.StdinOnce,
Tty: config.Tty,
SpecAnnotation: specAnnotation,
NetPriority: config.NetPriority,
DiskQuota: resources.GetDiskQuota(),
},
HostConfig: &apitypes.HostConfig{
Binds: generateMountBindings(config.GetMounts()),
Resources: parseResourcesFromCRI(resources),
Binds: generateMountBindings(config.GetMounts()),
},
NetworkingConfig: &apitypes.NetworkingConfig{},
}
Expand Down Expand Up @@ -717,8 +713,6 @@ func (c *CriManager) ContainerStatus(ctx context.Context, r *runtime.ContainerSt
imageRef = imageInfo.RepoDigests[0]
}

resources := container.HostConfig.Resources
diskQuota := container.Config.DiskQuota
status := &runtime.ContainerStatus{
Id: container.ID,
Metadata: metadata,
Expand All @@ -735,8 +729,6 @@ func (c *CriManager) ContainerStatus(ctx context.Context, r *runtime.ContainerSt
Labels: labels,
Annotations: annotations,
// TODO: LogPath.
Volumes: parseVolumesFromPouch(container.Config.Volumes),
Resources: parseResourcesFromPouch(resources, diskQuota),
}

return &runtime.ContainerStatusResponse{Status: status}, nil
Expand Down Expand Up @@ -803,7 +795,6 @@ func (c *CriManager) UpdateContainerResources(ctx context.Context, r *runtime.Up
resources := r.GetLinux()
updateConfig := &apitypes.UpdateConfig{
Resources: parseResourcesFromCRI(resources),
DiskQuota: resources.GetDiskQuota(),
}
err = c.ContainerMgr.Update(ctx, containerID, updateConfig)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cri/v1alpha1/cri_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"os"
"strings"

runtime "github.com/alibaba/pouch/cri/apis/v1alpha1"
"github.com/alibaba/pouch/cri/config"

"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/sirupsen/logrus"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

// CniMgr as an interface defines all operations against CNI.
Expand Down
2 changes: 1 addition & 1 deletion cri/v1alpha1/cri_types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1alpha1

import (
runtime "github.com/alibaba/pouch/cri/apis/v1alpha1"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

// SandboxMeta represents the sandbox's meta data.
Expand Down
135 changes: 7 additions & 128 deletions cri/v1alpha1/cri_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

apitypes "github.com/alibaba/pouch/apis/types"
anno "github.com/alibaba/pouch/cri/annotations"
runtime "github.com/alibaba/pouch/cri/apis/v1alpha1"
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/pkg/utils"

Expand All @@ -25,6 +24,7 @@ import (
"github.com/go-openapi/strfmt"
"golang.org/x/net/context"
"golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

const uuidDir = "/dev/disk/by-uuid"
Expand Down Expand Up @@ -771,7 +771,6 @@ func imageToCriImage(image *apitypes.ImageInfo) (*runtime.Image, error) {
Size_: size,
Uid: uid,
Username: username,
Volumes: parseVolumesFromPouch(image.Config.Volumes),
}, nil
}

Expand Down Expand Up @@ -946,132 +945,12 @@ func blkrdev(device string) (uint64, error) {

// parseResourceFromCRI parse Resources from runtime.LinuxContainerResources to apitypes.Resources
func parseResourcesFromCRI(runtimeResources *runtime.LinuxContainerResources) apitypes.Resources {
var memorySwappiness *int64
if runtimeResources.GetMemorySwappiness() != nil {
memorySwappiness = &runtimeResources.GetMemorySwappiness().Value
}

return apitypes.Resources{
CPUPeriod: runtimeResources.GetCpuPeriod(),
CPUQuota: runtimeResources.GetCpuQuota(),
CPUShares: runtimeResources.GetCpuShares(),
Memory: runtimeResources.GetMemoryLimitInBytes(),
CpusetCpus: runtimeResources.GetCpusetCpus(),
CpusetMems: runtimeResources.GetCpusetMems(),
BlkioWeight: uint16(runtimeResources.GetBlkioWeight()),
BlkioWeightDevice: parseWeightDeviceFromCRI(runtimeResources.GetBlkioWeightDevice()),
BlkioDeviceReadBps: parseThrottleDeviceFromCRI(runtimeResources.GetBlkioDeviceReadBps()),
BlkioDeviceWriteBps: parseThrottleDeviceFromCRI(runtimeResources.GetBlkioDeviceWriteBps()),
BlkioDeviceReadIOps: parseThrottleDeviceFromCRI(runtimeResources.GetBlkioDeviceRead_IOps()),
BlkioDeviceWriteIOps: parseThrottleDeviceFromCRI(runtimeResources.GetBlkioDeviceWrite_IOps()),
KernelMemory: runtimeResources.GetKernelMemory(),
MemoryReservation: runtimeResources.GetMemoryReservation(),
MemorySwappiness: memorySwappiness,
Ulimits: parseUlimitFromCRI(runtimeResources.GetUlimits()),
}
}

// parseResourceFromPouch parse Resources from apitypes.Resources to runtime.LinuxContainerResources
func parseResourcesFromPouch(apitypesResources apitypes.Resources, diskQuota map[string]string) *runtime.LinuxContainerResources {
var memorySwappiness *runtime.Int64Value
if apitypesResources.MemorySwappiness != nil {
memorySwappiness = &runtime.Int64Value{Value: *apitypesResources.MemorySwappiness}
}

return &runtime.LinuxContainerResources{
CpuPeriod: apitypesResources.CPUPeriod,
CpuQuota: apitypesResources.CPUQuota,
CpuShares: apitypesResources.CPUShares,
MemoryLimitInBytes: apitypesResources.Memory,
CpusetCpus: apitypesResources.CpusetCpus,
CpusetMems: apitypesResources.CpusetMems,
BlkioWeight: uint32(apitypesResources.BlkioWeight),
BlkioWeightDevice: parseWeightDeviceFromPouch(apitypesResources.BlkioWeightDevice),
BlkioDeviceReadBps: parseThrottleDeviceFromPouch(apitypesResources.BlkioDeviceReadBps),
BlkioDeviceWriteBps: parseThrottleDeviceFromPouch(apitypesResources.BlkioDeviceWriteBps),
BlkioDeviceRead_IOps: parseThrottleDeviceFromPouch(apitypesResources.BlkioDeviceReadIOps),
BlkioDeviceWrite_IOps: parseThrottleDeviceFromPouch(apitypesResources.BlkioDeviceWriteIOps),
KernelMemory: apitypesResources.KernelMemory,
MemoryReservation: apitypesResources.MemoryReservation,
MemorySwappiness: memorySwappiness,
Ulimits: parseUlimitFromPouch(apitypesResources.Ulimits),
DiskQuota: diskQuota,
}
}

// parseWeightDeviceFromCRI parse WeightDevice from runtime.WeightDevice to apitypes.WeightDevice
func parseWeightDeviceFromCRI(runtimeWeightDevices []*runtime.WeightDevice) (weightDevices []*apitypes.WeightDevice) {
for _, v := range runtimeWeightDevices {
weightDevices = append(weightDevices, &apitypes.WeightDevice{
Path: v.GetPath(),
Weight: uint16(v.GetWeight()),
})
}
return
}

// parseWeightDeviceFromPouch parse WeightDevice from apitypes.WeightDevice to runtime.WeightDevice
func parseWeightDeviceFromPouch(apitypesWeightDevices []*apitypes.WeightDevice) (weightDevices []*runtime.WeightDevice) {
for _, v := range apitypesWeightDevices {
weightDevices = append(weightDevices, &runtime.WeightDevice{
Path: v.Path,
Weight: uint32(v.Weight),
})
}
return
}

// parseThrottleDeviceFromCRI parse ThrottleDevice from runtime.ThrottleDevice to apitypes.ThrottleDevice
func parseThrottleDeviceFromCRI(runtimeThrottleDevices []*runtime.ThrottleDevice) (throttleDevices []*apitypes.ThrottleDevice) {
for _, v := range runtimeThrottleDevices {
throttleDevices = append(throttleDevices, &apitypes.ThrottleDevice{
Path: v.GetPath(),
Rate: v.GetRate(),
})
}
return
}

// parseThrottleDeviceFromPouch parse ThrottleDevice from apitypes.ThrottleDevice to runtime.ThrottleDevice
func parseThrottleDeviceFromPouch(apitypesThrottleDevices []*apitypes.ThrottleDevice) (throttleDevices []*runtime.ThrottleDevice) {
for _, v := range apitypesThrottleDevices {
throttleDevices = append(throttleDevices, &runtime.ThrottleDevice{
Path: v.Path,
Rate: v.Rate,
})
}
return
}

// parseUlimitFromCRI parse Ulimit from runtime.Ulimit to apitypes.Ulimit
func parseUlimitFromCRI(runtimeUlimits []*runtime.Ulimit) (ulimits []*apitypes.Ulimit) {
for _, v := range runtimeUlimits {
ulimits = append(ulimits, &apitypes.Ulimit{
Hard: v.GetHard(),
Name: v.GetName(),
Soft: v.GetSoft(),
})
}
return
}

// parseUlimitFromPouch parse Ulimit from apitypes.Ulimit to runtime.Ulimit
func parseUlimitFromPouch(apitypesUlimits []*apitypes.Ulimit) (ulimits []*runtime.Ulimit) {
for _, v := range apitypesUlimits {
ulimits = append(ulimits, &runtime.Ulimit{
Hard: v.Hard,
Name: v.Name,
Soft: v.Soft,
})
}
return
}

// parseVolumesFromPouch parse Volumes from map[string]interface{} to map[string]*runtime.Volume
func parseVolumesFromPouch(containerVolumes map[string]interface{}) map[string]*runtime.Volume {
volumes := make(map[string]*runtime.Volume)
for k := range containerVolumes {
volumes[k] = &runtime.Volume{}
CPUPeriod: runtimeResources.GetCpuPeriod(),
CPUQuota: runtimeResources.GetCpuQuota(),
CPUShares: runtimeResources.GetCpuShares(),
Memory: runtimeResources.GetMemoryLimitInBytes(),
CpusetCpus: runtimeResources.GetCpusetCpus(),
CpusetMems: runtimeResources.GetCpusetMems(),
}
return volumes
}
Loading

0 comments on commit 92de646

Please sign in to comment.