Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Automatically cherry-pick #152 and #153 #156

Merged
merged 4 commits into from
May 25, 2017
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
4 changes: 3 additions & 1 deletion cmd/frakti/frakti.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var (
"The endpoint of alternative runtime to communicate with")
enableAlternativeRuntime = pflag.Bool("enable-alternative-runtime", true, "Enable alternative runtime to handle OS containers, default is true")
cgroupDriver = pflag.String("cgroup-driver", "cgroupfs", "Driver that the frakti uses to manipulate cgroups on the host. *SHOULD BE SAME AS* kubelet cgroup driver configuration. Possible values: 'cgroupfs', 'systemd'")
defaultCPUNum = pflag.Int32("cpu", 1, "Default CPU in number for HyperVM when cpu limit is not specified for the pod")
defaultMemoryMB = pflag.Int32("memory", 64, "Default memory in MB for HyperVM when memory limit is not specified for the pod")
)

func main() {
Expand All @@ -75,7 +77,7 @@ func main() {

// 1. Initialize hyper runtime and streaming server
streamingConfig := getStreamingConfig()
hyperRuntime, streamingServer, err := hyper.NewHyperRuntime(*hyperEndpoint, streamingConfig, *cniNetDir, *cniPluginDir)
hyperRuntime, streamingServer, err := hyper.NewHyperRuntime(*hyperEndpoint, streamingConfig, *cniNetDir, *cniPluginDir, *defaultCPUNum, *defaultMemoryMB)
if err != nil {
glog.Errorf("Initialize hyper runtime failed: %v", err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ systemctl daemon-reload
### Setting up the master node

```sh
kubeadm init kubeadm init --pod-network-cidr 10.244.0.0/16 --kubernetes-version latest
kubeadm init --pod-network-cidr 10.244.0.0/16 --kubernetes-version latest
```

Optional: enable schedule pods on the master
Expand All @@ -234,7 +234,7 @@ kubectl taint nodes --all node-role.kubernetes.io/master:NoSchedule-
token=$(kubeadm token list | grep authentication,signing | awk '{print $1}')

# join master on worker nodes
kubeadm join --token $token ${master_ip}
kubeadm join --token $token ${master_ip:port}
```

### Setting CNI network routes
Expand Down
2 changes: 1 addition & 1 deletion pkg/hyper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (c *Client) RemoveImage(image, tag string) error {
repoSep = "@"
}

_, err := c.client.ImageRemove(ctx, &types.ImageRemoveRequest{Image: fmt.Sprintf("%s%s%s", image, repoSep, tag)})
_, err := c.client.ImageRemove(ctx, &types.ImageRemoveRequest{Image: fmt.Sprintf("%s%s%s", image, repoSep, tag), Force: true})
return err
}

Expand Down
16 changes: 7 additions & 9 deletions pkg/hyper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const (
// fraktiAnnotationLabel is used to save annotations into labels
fraktiAnnotationLabel = "io.kubernetes.frakti.annotations"

// default resources while the pod level qos of kubelet pod is not specified.
defaultCPUNumber = 1
defaultMemoryinMegabytes = 64
containerLogPathLabelKey = "io.kubernetes.container.logpath"

// More details about these: http://kubernetes.io/docs/user-guide/compute-resources/
// cpuQuotaCgroupFile is the `cfs_quota_us` value set by kubelet pod qos
Expand Down Expand Up @@ -296,7 +294,7 @@ func toKubeContainerState(state string) kubeapi.ContainerState {

// TODO(harry) These two methods will find subsystem mount point frequently, consider move FindCgroupMountpoint into a unified place.
// getCpuLimitFromCgroup get the cpu limit from given cgroupParent
func getCpuLimitFromCgroup(cgroupParent string) (int32, error) {
func (h *Runtime) getCpuLimitFromCgroup(cgroupParent string) (int32, error) {
mntPath, err := libcontainercgroups.FindCgroupMountpoint("cpu")
if err != nil {
return -1, err
Expand All @@ -317,8 +315,8 @@ func getCpuLimitFromCgroup(cgroupParent string) (int32, error) {

// This is needed when pod is burstable but no cpu limit is set, then cpuQuota will be -1, hyperCPUNumber
// will be calculate to 0
if hyperCPUNumber < defaultCPUNumber {
hyperCPUNumber = defaultCPUNumber
if hyperCPUNumber < h.defaultCPUNum {
hyperCPUNumber = h.defaultCPUNum
}

return hyperCPUNumber, nil
Expand All @@ -339,7 +337,7 @@ func readCgroupFileToInt64(cgroupPath, cgroupFile string) (int64, error) {
}

// getMemeoryLimitFromCgroup get the memory limit from given cgroupParent
func getMemeoryLimitFromCgroup(cgroupParent string) (int32, error) {
func (h *Runtime) getMemeoryLimitFromCgroup(cgroupParent string) (int32, error) {
mntPath, err := libcontainercgroups.FindCgroupMountpoint("memory")
if err != nil {
return -1, err
Expand All @@ -355,8 +353,8 @@ func getMemeoryLimitFromCgroup(cgroupParent string) (int32, error) {
// HyperContainer requires at least 64Mi memory
// And this also protect when pod is burstable but no memory limit is set,
// then frakti will read a illegal (larger than int32) value and got memoryinMegabytes < 0
if memoryinMegabytes < defaultMemoryinMegabytes {
memoryinMegabytes = defaultMemoryinMegabytes
if memoryinMegabytes < h.defaultMemoryMB {
memoryinMegabytes = h.defaultMemoryMB
}
return memoryinMegabytes, nil
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/hyper/hyper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ type Runtime struct {
streamingServer streaming.Server
netPlugin ocicni.CNIPlugin
checkpointHandler CheckpointHandler

defaultCPUNum int32
defaultMemoryMB int32
}

// NewHyperRuntime creates a new Runtime
func NewHyperRuntime(hyperEndpoint string, streamingConfig *streaming.Config, cniNetDir string, cniPluginDir string) (*Runtime, streaming.Server, error) {
func NewHyperRuntime(hyperEndpoint string, streamingConfig *streaming.Config, cniNetDir, cniPluginDir string, defaultCPUNum, defaultMemoryMB int32) (*Runtime, streaming.Server, error) {
hyperClient, err := NewClient(hyperEndpoint, hyperConnectionTimeout)
if err != nil {
glog.Fatalf("Initialize hyper client failed: %v", err)
Expand Down Expand Up @@ -76,6 +79,8 @@ func NewHyperRuntime(hyperEndpoint string, streamingConfig *streaming.Config, cn
streamingServer: streamingServer,
netPlugin: netPlugin,
checkpointHandler: persistentCheckpointHandler,
defaultCPUNum: defaultCPUNum,
defaultMemoryMB: defaultMemoryMB,
}

return rt, streamingServer, nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/hyper/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

// RunPodSandbox creates and starts a pod-level sandbox.
func (h *Runtime) RunPodSandbox(config *kubeapi.PodSandboxConfig) (string, error) {
userpod, err := buildUserPod(config)
userpod, err := h.buildUserPod(config)
if err != nil {
glog.Errorf("Build UserPod for sandbox %q failed: %v", config.String(), err)
return "", err
Expand Down Expand Up @@ -122,7 +122,7 @@ func addNetworkInterfaceForPod(userpod *types.UserPod, info *NetworkInfo) {

// buildUserPod builds hyperd's UserPod based kubelet PodSandboxConfig.
// TODO: support pod-level portmapping (depends on hyperd).
func buildUserPod(config *kubeapi.PodSandboxConfig) (*types.UserPod, error) {
func (h *Runtime) buildUserPod(config *kubeapi.PodSandboxConfig) (*types.UserPod, error) {
var (
cpuNumber, memoryinMegabytes int32
err error
Expand All @@ -133,11 +133,11 @@ func buildUserPod(config *kubeapi.PodSandboxConfig) (*types.UserPod, error) {
}

if len(cgroupParent) != 0 && !strings.Contains(cgroupParent, string(v1.PodQOSBestEffort)) {
cpuNumber, err = getCpuLimitFromCgroup(cgroupParent)
cpuNumber, err = h.getCpuLimitFromCgroup(cgroupParent)
if err != nil {
return nil, err
}
memoryinMegabytes, err = getMemeoryLimitFromCgroup(cgroupParent)
memoryinMegabytes, err = h.getMemeoryLimitFromCgroup(cgroupParent)
if err != nil {
return nil, err
}
Expand All @@ -146,8 +146,8 @@ func buildUserPod(config *kubeapi.PodSandboxConfig) (*types.UserPod, error) {
// If pod level QoS is disabled, or this pod is a BE, use default value instead.
// NOTE: thus actually changes BE to guaranteed. But generally, HyperContainer should not be used for BE workload,
// and we now allow multiple runtime in one node.
cpuNumber = int32(defaultCPUNumber)
memoryinMegabytes = int32(defaultMemoryinMegabytes)
cpuNumber = h.defaultCPUNum
memoryinMegabytes = h.defaultMemoryMB
}

spec := &types.UserPod{
Expand Down