Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
3,434 changes: 2,645 additions & 789 deletions ...belet/apis/cri/v1alpha1/runtime/api.pb.go → cri/apis/v1alpha1/api.pb.go

Large diffs are not rendered by default.

1,209 changes: 1,209 additions & 0 deletions cri/apis/v1alpha1/api.proto

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package runtime
package v1alpha1

// This file contains all constants defined in CRI.

Expand Down
File renamed without changes.
3,144 changes: 2,500 additions & 644 deletions ...belet/apis/cri/runtime/v1alpha2/api.pb.go → cri/apis/v1alpha2/api.pb.go

Large diffs are not rendered by default.

1,281 changes: 1,281 additions & 0 deletions cri/apis/v1alpha2/api.proto

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions cri/v1alpha1/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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 @@ -24,7 +25,6 @@ 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,6 +497,7 @@ 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 @@ -510,9 +511,12 @@ 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()),
Binds: generateMountBindings(config.GetMounts()),
Resources: parseResourcesFromCRI(resources),
},
NetworkingConfig: &apitypes.NetworkingConfig{},
}
Expand Down Expand Up @@ -713,6 +717,8 @@ 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 @@ -729,6 +735,8 @@ 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 @@ -794,14 +802,8 @@ func (c *CriManager) UpdateContainerResources(ctx context.Context, r *runtime.Up

resources := r.GetLinux()
updateConfig := &apitypes.UpdateConfig{
Resources: apitypes.Resources{
CPUPeriod: resources.GetCpuPeriod(),
CPUQuota: resources.GetCpuQuota(),
CPUShares: resources.GetCpuShares(),
Memory: resources.GetMemoryLimitInBytes(),
CpusetCpus: resources.GetCpusetCpus(),
CpusetMems: resources.GetCpusetMems(),
},
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 (
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
runtime "github.com/alibaba/pouch/cri/apis/v1alpha1"
)

// SandboxMeta represents the sandbox's meta data.
Expand Down
137 changes: 136 additions & 1 deletion cri/v1alpha1/cri_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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 @@ -24,7 +25,6 @@ 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,6 +771,7 @@ func imageToCriImage(image *apitypes.ImageInfo) (*runtime.Image, error) {
Size_: size,
Uid: uid,
Username: username,
Volumes: parseVolumesFromPouch(image.Config.Volumes),
}, nil
}

Expand Down Expand Up @@ -940,3 +941,137 @@ func blkrdev(device string) (uint64, error) {
}
return 0, fmt.Errorf("cannot get stat of device %s", device)
}

// CRI extension related tool functions.

// 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{}
}
return volumes
}
Loading