mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-19 07:49:17 +00:00
shim: add kata builtin shim type
When set, the kata shim will not be created. Fixes: #172 Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
26
virtcontainers/kata_builtin_shim.go
Normal file
26
virtcontainers/kata_builtin_shim.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2018 HyperHQ Inc.
|
||||||
|
//
|
||||||
|
// 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 virtcontainers
|
||||||
|
|
||||||
|
type kataBuiltInShim struct{}
|
||||||
|
|
||||||
|
// start is the kataBuiltInShim start implementation for kata builtin shim.
|
||||||
|
// It does nothing. The shim functionality is provided by the virtcontainers
|
||||||
|
// library.
|
||||||
|
func (s *kataBuiltInShim) start(pod Pod, params ShimParams) (int, error) {
|
||||||
|
return -1, nil
|
||||||
|
}
|
@@ -40,6 +40,9 @@ const (
|
|||||||
|
|
||||||
// KataShimType is the Kata Containers shim type.
|
// KataShimType is the Kata Containers shim type.
|
||||||
KataShimType ShimType = "kataShim"
|
KataShimType ShimType = "kataShim"
|
||||||
|
|
||||||
|
// KataBuiltInShimType is the Kata Containers builtin shim type.
|
||||||
|
KataBuiltInShimType ShimType = "kataBuiltInShim"
|
||||||
)
|
)
|
||||||
|
|
||||||
var waitForShimTimeout = 10.0
|
var waitForShimTimeout = 10.0
|
||||||
@@ -71,16 +74,16 @@ func (pType *ShimType) Set(value string) error {
|
|||||||
switch value {
|
switch value {
|
||||||
case "noopShim":
|
case "noopShim":
|
||||||
*pType = NoopShimType
|
*pType = NoopShimType
|
||||||
return nil
|
|
||||||
case "ccShim":
|
case "ccShim":
|
||||||
*pType = CCShimType
|
*pType = CCShimType
|
||||||
return nil
|
|
||||||
case "kataShim":
|
case "kataShim":
|
||||||
*pType = KataShimType
|
*pType = KataShimType
|
||||||
return nil
|
case "kataBuiltInShim":
|
||||||
|
*pType = KataBuiltInShimType
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown shim type %s", value)
|
return fmt.Errorf("Unknown shim type %s", value)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// String converts a shim type to a string.
|
// String converts a shim type to a string.
|
||||||
@@ -92,6 +95,8 @@ func (pType *ShimType) String() string {
|
|||||||
return string(CCShimType)
|
return string(CCShimType)
|
||||||
case KataShimType:
|
case KataShimType:
|
||||||
return string(KataShimType)
|
return string(KataShimType)
|
||||||
|
case KataBuiltInShimType:
|
||||||
|
return string(KataBuiltInShimType)
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -106,6 +111,8 @@ func newShim(pType ShimType) (shim, error) {
|
|||||||
return &ccShim{}, nil
|
return &ccShim{}, nil
|
||||||
case KataShimType:
|
case KataShimType:
|
||||||
return &kataShim{}, nil
|
return &kataShim{}, nil
|
||||||
|
case KataBuiltInShimType:
|
||||||
|
return &kataBuiltInShim{}, nil
|
||||||
default:
|
default:
|
||||||
return &noopShim{}, nil
|
return &noopShim{}, nil
|
||||||
}
|
}
|
||||||
@@ -114,7 +121,7 @@ func newShim(pType ShimType) (shim, error) {
|
|||||||
// newShimConfig returns a shim config from a generic PodConfig interface.
|
// newShimConfig returns a shim config from a generic PodConfig interface.
|
||||||
func newShimConfig(config PodConfig) interface{} {
|
func newShimConfig(config PodConfig) interface{} {
|
||||||
switch config.ShimType {
|
switch config.ShimType {
|
||||||
case NoopShimType:
|
case NoopShimType, KataBuiltInShimType:
|
||||||
return nil
|
return nil
|
||||||
case CCShimType, KataShimType:
|
case CCShimType, KataShimType:
|
||||||
var shimConfig ShimConfig
|
var shimConfig ShimConfig
|
||||||
@@ -147,6 +154,10 @@ func signalShim(pid int, sig syscall.Signal) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stopShim(pid int) error {
|
func stopShim(pid int) error {
|
||||||
|
if pid <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := signalShim(pid, syscall.SIGKILL); err != nil && err != syscall.ESRCH {
|
if err := signalShim(pid, syscall.SIGKILL); err != nil && err != syscall.ESRCH {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -233,6 +244,10 @@ func startShim(args []string, params ShimParams) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isShimRunning(pid int) (bool, error) {
|
func isShimRunning(pid int) (bool, error) {
|
||||||
|
if pid <= 0 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
process, err := os.FindProcess(pid)
|
process, err := os.FindProcess(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
Reference in New Issue
Block a user