Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: make runtime choosing supported in CRI managers for Kubernetes #1593

Merged
merged 1 commit into from
Jul 5, 2018
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
19 changes: 19 additions & 0 deletions cri/annotations/annotations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package annotations

// ContainerType values
const (
// ContainerTypeSandbox represents a pod sandbox container
ContainerTypeSandbox = "sandbox"

// ContainerTypeContainer represents a container running within a pod
ContainerTypeContainer = "container"

// ContainerType is the container type (sandbox or container) annotation
ContainerType = "io.kubernetes.cri-o.ContainerType"

// SandboxName is the sandbox name annotation
SandboxName = "io.kubernetes.cri-o.SandboxName"

// KubernetesRuntime is the runtime
KubernetesRuntime = "io.kubernetes.runtime"
)
14 changes: 11 additions & 3 deletions cri/v1alpha1/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

apitypes "github.com/alibaba/pouch/apis/types"
anno "github.com/alibaba/pouch/cri/annotations"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/pkg/errtypes"
Expand Down Expand Up @@ -236,6 +237,7 @@ func (c *CriManager) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
ID: id,
Config: config,
NetNSPath: netnsPath,
Runtime: config.Annotations[anno.KubernetesRuntime],
}
c.SandboxStore.Put(sandboxMeta)

Expand Down Expand Up @@ -462,6 +464,11 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
if iSpec := config.GetImage(); iSpec != nil {
image = iSpec.Image
}

specAnnotation := make(map[string]string)
specAnnotation[anno.ContainerType] = anno.ContainerTypeContainer
specAnnotation[anno.SandboxName] = podSandboxID

createConfig := &apitypes.ContainerCreateConfig{
ContainerConfig: apitypes.ContainerConfig{
Entrypoint: config.Command,
Expand All @@ -471,9 +478,10 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
WorkingDir: config.WorkingDir,
Labels: labels,
// Interactive containers:
OpenStdin: config.Stdin,
StdinOnce: config.StdinOnce,
Tty: config.Tty,
OpenStdin: config.Stdin,
StdinOnce: config.StdinOnce,
Tty: config.Tty,
SpecAnnotation: specAnnotation,
},
HostConfig: &apitypes.HostConfig{
Binds: generateMountBindings(config.GetMounts()),
Expand Down
3 changes: 3 additions & 0 deletions cri/v1alpha1/cri_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type SandboxMeta struct {

// NetNSPath is the network namespace used by the sandbox.
NetNSPath string

// Runtime is the runtime of sandbox
Runtime string
}

// Key returns sandbox's id.
Expand Down
17 changes: 17 additions & 0 deletions cri/v1alpha1/cri_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

apitypes "github.com/alibaba/pouch/apis/types"
anno "github.com/alibaba/pouch/cri/annotations"
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/pkg/utils"
"github.com/go-openapi/strfmt"
Expand Down Expand Up @@ -242,6 +243,12 @@ func makeSandboxPouchConfig(config *runtime.PodSandboxConfig, image string) (*ap
labels[containerTypeLabelKey] = containerTypeLabelSandbox

hc := &apitypes.HostConfig{}

// Apply runtime options.
if annotations := config.GetAnnotations(); annotations != nil {
hc.Runtime = annotations[anno.KubernetesRuntime]
}

createConfig := &apitypes.ContainerCreateConfig{
ContainerConfig: apitypes.ContainerConfig{
Hostname: strfmt.Hostname(config.Hostname),
Expand Down Expand Up @@ -607,6 +614,16 @@ func applyContainerSecurityContext(lc *runtime.LinuxContainerConfig, podSandboxI

// Apply Linux-specific options if applicable.
func (c *CriManager) updateCreateConfig(createConfig *apitypes.ContainerCreateConfig, config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, podSandboxID string) error {
// Apply runtime options.
res, err := c.SandboxStore.Get(podSandboxID)
if err != nil {
return fmt.Errorf("failed to get metadata of %q from SandboxStore: %v", podSandboxID, err)
}
sandboxMeta := res.(*SandboxMeta)
if sandboxMeta.Runtime != "" {
createConfig.HostConfig.Runtime = sandboxMeta.Runtime
}

if lc := config.GetLinux(); lc != nil {
// TODO: resource restriction.

Expand Down
14 changes: 11 additions & 3 deletions cri/v1alpha2/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

apitypes "github.com/alibaba/pouch/apis/types"
anno "github.com/alibaba/pouch/cri/annotations"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/pkg/errtypes"
Expand Down Expand Up @@ -236,6 +237,7 @@ func (c *CriManager) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
ID: id,
Config: config,
NetNSPath: netnsPath,
Runtime: config.Annotations[anno.KubernetesRuntime],
}
c.SandboxStore.Put(sandboxMeta)

Expand Down Expand Up @@ -470,6 +472,11 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
if iSpec := config.GetImage(); iSpec != nil {
image = iSpec.Image
}

specAnnotation := make(map[string]string)
specAnnotation[anno.ContainerType] = anno.ContainerTypeContainer
specAnnotation[anno.SandboxName] = podSandboxID

createConfig := &apitypes.ContainerCreateConfig{
ContainerConfig: apitypes.ContainerConfig{
Entrypoint: config.Command,
Expand All @@ -479,9 +486,10 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
WorkingDir: config.WorkingDir,
Labels: labels,
// Interactive containers:
OpenStdin: config.Stdin,
StdinOnce: config.StdinOnce,
Tty: config.Tty,
OpenStdin: config.Stdin,
StdinOnce: config.StdinOnce,
Tty: config.Tty,
SpecAnnotation: specAnnotation,
},
HostConfig: &apitypes.HostConfig{
Binds: generateMountBindings(config.GetMounts()),
Expand Down
3 changes: 3 additions & 0 deletions cri/v1alpha2/cri_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type SandboxMeta struct {

// NetNSPath is the network namespace used by the sandbox.
NetNSPath string

// Runtime is the runtime of sandbox
Runtime string
}

// Key returns sandbox's id.
Expand Down
18 changes: 17 additions & 1 deletion cri/v1alpha2/cri_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

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

Expand Down Expand Up @@ -240,8 +241,13 @@ func makeSandboxPouchConfig(config *runtime.PodSandboxConfig, image string) (*ap
labels := makeLabels(config.GetLabels(), config.GetAnnotations())
// Apply a label to distinguish sandboxes from regular containers.
labels[containerTypeLabelKey] = containerTypeLabelSandbox

hc := &apitypes.HostConfig{}

// Apply runtime options.
if annotations := config.GetAnnotations(); annotations != nil {
hc.Runtime = annotations[anno.KubernetesRuntime]
}

createConfig := &apitypes.ContainerCreateConfig{
ContainerConfig: apitypes.ContainerConfig{
Hostname: strfmt.Hostname(config.Hostname),
Expand Down Expand Up @@ -610,6 +616,16 @@ func applyContainerSecurityContext(lc *runtime.LinuxContainerConfig, podSandboxI

// Apply Linux-specific options if applicable.
func (c *CriManager) updateCreateConfig(createConfig *apitypes.ContainerCreateConfig, config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, podSandboxID string) error {
// Apply runtime options.
res, err := c.SandboxStore.Get(podSandboxID)
if err != nil {
return fmt.Errorf("failed to get metadata of %q from SandboxStore: %v", podSandboxID, err)
}
sandboxMeta := res.(*SandboxMeta)
if sandboxMeta.Runtime != "" {
createConfig.HostConfig.Runtime = sandboxMeta.Runtime
}

if lc := config.GetLinux(); lc != nil {
// TODO: resource restriction.

Expand Down