Merge pull request #3678 from afbjorklund/rkt
Add implementation of the deprecated rkt runtimepull/3688/head
commit
1473c36fb9
|
@ -79,6 +79,7 @@ var styles = map[string]style{
|
||||||
"celebrate": {Prefix: "🎉 "},
|
"celebrate": {Prefix: "🎉 "},
|
||||||
"container-runtime": {Prefix: "🎁 "},
|
"container-runtime": {Prefix: "🎁 "},
|
||||||
"Docker": {Prefix: "🐳 "},
|
"Docker": {Prefix: "🐳 "},
|
||||||
|
"rkt": {Prefix: "🚀 "},
|
||||||
"CRI-O": {Prefix: "🎁 "}, // This should be a snow-flake, but the emoji has a strange width on macOS
|
"CRI-O": {Prefix: "🎁 "}, // This should be a snow-flake, but the emoji has a strange width on macOS
|
||||||
"containerd": {Prefix: "📦 "},
|
"containerd": {Prefix: "📦 "},
|
||||||
"permissions": {Prefix: "🔑 "},
|
"permissions": {Prefix: "🔑 "},
|
||||||
|
|
|
@ -80,6 +80,8 @@ func New(c Config) (Manager, error) {
|
||||||
switch c.Type {
|
switch c.Type {
|
||||||
case "", "docker":
|
case "", "docker":
|
||||||
return &Docker{Socket: c.Socket, Runner: c.Runner}, nil
|
return &Docker{Socket: c.Socket, Runner: c.Runner}, nil
|
||||||
|
case "rkt":
|
||||||
|
return &Rkt{Socket: c.Socket, Runner: c.Runner}, nil
|
||||||
case "crio", "cri-o":
|
case "crio", "cri-o":
|
||||||
return &CRIO{Socket: c.Socket, Runner: c.Runner}, nil
|
return &CRIO{Socket: c.Socket, Runner: c.Runner}, nil
|
||||||
case "containerd":
|
case "containerd":
|
||||||
|
@ -92,7 +94,7 @@ func New(c Config) (Manager, error) {
|
||||||
// disableOthers disables all other runtimes except for me.
|
// disableOthers disables all other runtimes except for me.
|
||||||
func disableOthers(me Manager, cr CommandRunner) error {
|
func disableOthers(me Manager, cr CommandRunner) error {
|
||||||
// valid values returned by manager.Name()
|
// valid values returned by manager.Name()
|
||||||
runtimes := []string{"containerd", "crio", "docker"}
|
runtimes := []string{"containerd", "crio", "rkt", "docker"}
|
||||||
for _, name := range runtimes {
|
for _, name := range runtimes {
|
||||||
r, err := New(Config{Type: name, Runner: cr})
|
r, err := New(Config{Type: name, Runner: cr})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -33,6 +33,7 @@ func TestName(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{"", "Docker"},
|
{"", "Docker"},
|
||||||
{"docker", "Docker"},
|
{"docker", "Docker"},
|
||||||
|
{"rkt", "rkt"},
|
||||||
{"crio", "CRI-O"},
|
{"crio", "CRI-O"},
|
||||||
{"cri-o", "CRI-O"},
|
{"cri-o", "CRI-O"},
|
||||||
{"containerd", "containerd"},
|
{"containerd", "containerd"},
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cruntime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rkt contains rkt runtime state
|
||||||
|
type Rkt struct {
|
||||||
|
Socket string
|
||||||
|
Runner CommandRunner
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name is a human readable name for rkt
|
||||||
|
func (r *Rkt) Name() string {
|
||||||
|
return "rkt"
|
||||||
|
}
|
||||||
|
|
||||||
|
// SocketPath returns the path to the socket file for rkt/rktlet
|
||||||
|
func (r *Rkt) SocketPath() string {
|
||||||
|
if r.Socket != "" {
|
||||||
|
return r.Socket
|
||||||
|
}
|
||||||
|
return "/var/run/rktlet.sock"
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultCNI returns whether to use CNI networking by default
|
||||||
|
func (r *Rkt) DefaultCNI() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Active returns if rkt is active on the host
|
||||||
|
func (r *Rkt) Active() bool {
|
||||||
|
err := r.Runner.Run("systemctl is-active --quiet service rkt-api")
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Available returns an error if it is not possible to use this runtime on a host
|
||||||
|
func (r *Rkt) Available() error {
|
||||||
|
return r.Runner.Run("command -v rkt")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable idempotently enables rkt on a host
|
||||||
|
func (r *Rkt) Enable() error {
|
||||||
|
if err := disableOthers(r, r.Runner); err != nil {
|
||||||
|
glog.Warningf("disableOthers: %v", err)
|
||||||
|
}
|
||||||
|
if err := populateCRIConfig(r.Runner, r.SocketPath()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := enableIPForwarding(r.Runner); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err := r.Runner.Run("sudo systemctl start rkt-api")
|
||||||
|
if err == nil {
|
||||||
|
err = r.Runner.Run("sudo systemctl start rkt-metadata")
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
// Note: this is currently not included in minikube
|
||||||
|
err = r.Runner.Run("sudo systemctl start rktlet")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable idempotently disables rkt on a host
|
||||||
|
func (r *Rkt) Disable() error {
|
||||||
|
err := r.Runner.Run("sudo systemctl stop rkt-api")
|
||||||
|
if err == nil {
|
||||||
|
err = r.Runner.Run("sudo systemctl stop rkt-metadata")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadImage loads an image into this runtime
|
||||||
|
func (r *Rkt) LoadImage(path string) error {
|
||||||
|
glog.Infof("Loading image: %s", path)
|
||||||
|
// Note: this command (import) does not currently exist for rkt
|
||||||
|
return r.Runner.Run(fmt.Sprintf("sudo rkt image import %s", path))
|
||||||
|
}
|
||||||
|
|
||||||
|
// KubeletOptions returns kubelet options for a rkt
|
||||||
|
func (r *Rkt) KubeletOptions() map[string]string {
|
||||||
|
return map[string]string{
|
||||||
|
"container-runtime": "remote",
|
||||||
|
"container-runtime-endpoint": fmt.Sprintf("unix://%s", r.SocketPath()),
|
||||||
|
"image-service-endpoint": fmt.Sprintf("unix://%s", r.SocketPath()),
|
||||||
|
"runtime-request-timeout": "15m",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListContainers returns a list of managed by this container runtime
|
||||||
|
func (r *Rkt) ListContainers(filter string) ([]string, error) {
|
||||||
|
return listCRIContainers(r.Runner, filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// KillContainers removes containers based on ID
|
||||||
|
func (r *Rkt) KillContainers(ids []string) error {
|
||||||
|
return killCRIContainers(r.Runner, ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopContainers stops containers based on ID
|
||||||
|
func (r *Rkt) StopContainers(ids []string) error {
|
||||||
|
return stopCRIContainers(r.Runner, ids)
|
||||||
|
}
|
Loading…
Reference in New Issue