Beispiel #1
0
func NewFakeKubeRuntimeManager(runtimeService internalApi.RuntimeService, imageService internalApi.ImageManagerService, networkPlugin network.NetworkPlugin, osInterface kubecontainer.OSInterface) (*kubeGenericRuntimeManager, error) {
	recorder := &record.FakeRecorder{}
	kubeRuntimeManager := &kubeGenericRuntimeManager{
		recorder:            recorder,
		cpuCFSQuota:         false,
		livenessManager:     proberesults.NewManager(),
		containerRefManager: kubecontainer.NewRefManager(),
		osInterface:         osInterface,
		networkPlugin:       networkPlugin,
		runtimeHelper:       &fakeRuntimeHelper{},
		runtimeService:      runtimeService,
		imageService:        imageService,
		keyring:             credentialprovider.NewDockerKeyring(),
	}

	typedVersion, err := runtimeService.Version(kubeRuntimeAPIVersion)
	if err != nil {
		return nil, err
	}

	kubeRuntimeManager.containerGC = NewContainerGC(runtimeService, newFakePodGetter(), kubeRuntimeManager)
	kubeRuntimeManager.runtimeName = typedVersion.GetRuntimeName()
	kubeRuntimeManager.imagePuller = images.NewImageManager(
		kubecontainer.FilterEventRecorder(recorder),
		kubeRuntimeManager,
		flowcontrol.NewBackOff(time.Second, 300*time.Second),
		false)
	kubeRuntimeManager.runner = lifecycle.NewHandlerRunner(
		&fakeHTTP{},
		kubeRuntimeManager,
		kubeRuntimeManager)

	return kubeRuntimeManager, nil
}
Beispiel #2
0
// New creates the hyper container runtime which implements the container runtime interface.
func New(generator kubecontainer.RunContainerOptionsGenerator,
	recorder record.EventRecorder,
	networkPlugin network.NetworkPlugin,
	containerRefManager *kubecontainer.RefManager,
	livenessManager proberesults.Manager,
	volumeGetter volumeGetter,
	kubeClient client.Interface,
	imageBackOff *util.Backoff,
	serializeImagePulls bool,
	httpClient kubetypes.HttpGetter,
	disableHyperInternalService bool,
	containerLogsDir string,
	os kubecontainer.OSInterface,
) (kubecontainer.Runtime, error) {
	// check hyper has already installed
	hyperBinAbsPath, err := exec.LookPath(hyperBinName)
	if err != nil {
		glog.Errorf("Hyper: can't find hyper binary")
		return nil, fmt.Errorf("cannot find hyper binary: %v", err)
	}

	hyper := &runtime{
		hyperBinAbsPath:             hyperBinAbsPath,
		dockerKeyring:               credentialprovider.NewDockerKeyring(),
		containerLogsDir:            containerLogsDir,
		containerRefManager:         containerRefManager,
		generator:                   generator,
		livenessManager:             livenessManager,
		os:                          os,
		recorder:                    recorder,
		networkPlugin:               networkPlugin,
		volumeGetter:                volumeGetter,
		hyperClient:                 NewHyperClient(),
		kubeClient:                  kubeClient,
		disableHyperInternalService: disableHyperInternalService,
	}

	if serializeImagePulls {
		hyper.imagePuller = kubecontainer.NewSerializedImagePuller(recorder, hyper, imageBackOff)
	} else {
		hyper.imagePuller = kubecontainer.NewImagePuller(recorder, hyper, imageBackOff)
	}

	version, err := hyper.hyperClient.Version()
	if err != nil {
		return nil, fmt.Errorf("cannot get hyper version: %v", err)
	}

	hyperVersion, err := parseVersion(version)
	if err != nil {
		return nil, fmt.Errorf("cannot get hyper version: %v", err)
	}

	hyper.version = hyperVersion

	hyper.runner = lifecycle.NewHandlerRunner(httpClient, hyper, hyper)

	return hyper, nil
}
Beispiel #3
0
// New creates the hyper container runtime which implements the container runtime interface.
func New(runtimeHelper kubecontainer.RuntimeHelper,
	recorder record.EventRecorder,
	networkPlugin network.NetworkPlugin,
	containerRefManager *kubecontainer.RefManager,
	livenessManager proberesults.Manager,
	kubeClient clientset.Interface,
	imageBackOff *flowcontrol.Backoff,
	serializeImagePulls bool,
	httpClient kubetypes.HttpGetter,
	disableHyperInternalService bool,
	containerLogsDir string,
	os kubecontainer.OSInterface,
) (kubecontainer.Runtime, error) {
	hyperClient, err := NewHyperClient()
	if err != nil {
		return nil, err
	}

	hyper := &runtime{
		dockerKeyring:               credentialprovider.NewDockerKeyring(),
		containerLogsDir:            containerLogsDir,
		containerRefManager:         containerRefManager,
		runtimeHelper:               runtimeHelper,
		livenessManager:             livenessManager,
		os:                          os,
		recorder:                    recorder,
		networkPlugin:               networkPlugin,
		hyperClient:                 hyperClient,
		kubeClient:                  kubeClient,
		disableHyperInternalService: disableHyperInternalService,
	}

	if serializeImagePulls {
		hyper.imagePuller = kubecontainer.NewSerializedImagePuller(recorder, hyper, imageBackOff)
	} else {
		hyper.imagePuller = kubecontainer.NewImagePuller(recorder, hyper, imageBackOff)
	}

	version, err := hyper.hyperClient.Version()
	if err != nil {
		return nil, fmt.Errorf("cannot get hyper version: %v", err)
	}

	hyperVersion, err := parseVersion(version)
	if err != nil {
		return nil, fmt.Errorf("cannot get hyper version: %v", err)
	}

	hyper.version = hyperVersion

	hyper.runner = lifecycle.NewHandlerRunner(httpClient, hyper, hyper)

	return hyper, nil
}
// NewKubeGenericRuntimeManager creates a new kubeGenericRuntimeManager
func NewKubeGenericRuntimeManager(
	recorder record.EventRecorder,
	livenessManager proberesults.Manager,
	containerRefManager *kubecontainer.RefManager,
	osInterface kubecontainer.OSInterface,
	networkPlugin network.NetworkPlugin,
	runtimeHelper kubecontainer.RuntimeHelper,
	httpClient types.HttpGetter,
	imageBackOff *flowcontrol.Backoff,
	serializeImagePulls bool,
	cpuCFSQuota bool,
	runtimeService internalApi.RuntimeService,
	imageService internalApi.ImageManagerService,
) (*kubeGenericRuntimeManager, error) {
	kubeRuntimeManager := &kubeGenericRuntimeManager{
		recorder:            recorder,
		cpuCFSQuota:         cpuCFSQuota,
		livenessManager:     livenessManager,
		containerRefManager: containerRefManager,
		osInterface:         osInterface,
		networkPlugin:       networkPlugin,
		runtimeHelper:       runtimeHelper,
		runtimeService:      runtimeService,
		imageService:        imageService,
		keyring:             credentialprovider.NewDockerKeyring(),
	}

	typedVersion, err := kubeRuntimeManager.runtimeService.Version(kubeRuntimeAPIVersion)
	if err != nil {
		glog.Errorf("Get runtime version failed: %v", err)
		return nil, err
	}

	// Only matching kubeRuntimeAPIVersion is supported now
	// TODO: Runtime API machinery is under discussion at https://github.com/kubernetes/kubernetes/issues/28642
	if typedVersion.GetVersion() != kubeRuntimeAPIVersion {
		glog.Errorf("Runtime api version %s is not supported, only %s is supported now",
			typedVersion.GetVersion(),
			kubeRuntimeAPIVersion)
		return nil, ErrVersionNotSupported
	}

	kubeRuntimeManager.runtimeName = typedVersion.GetRuntimeName()
	glog.Infof("Container runtime %s initialized, version: %s, apiVersion: %s",
		typedVersion.GetRuntimeName(),
		typedVersion.GetRuntimeVersion(),
		typedVersion.GetRuntimeApiVersion())

	// If the container logs directory does not exist, create it.
	// TODO: create podLogsRootDirectory at kubelet.go when kubelet is refactored to
	// new runtime interface
	if _, err := osInterface.Stat(podLogsRootDirectory); os.IsNotExist(err) {
		if err := osInterface.MkdirAll(podLogsRootDirectory, 0755); err != nil {
			glog.Errorf("Failed to create directory %q: %v", podLogsRootDirectory, err)
		}
	}

	kubeRuntimeManager.imagePuller = images.NewImageManager(
		kubecontainer.FilterEventRecorder(recorder),
		kubeRuntimeManager,
		imageBackOff,
		serializeImagePulls)
	kubeRuntimeManager.runner = lifecycle.NewHandlerRunner(httpClient, kubeRuntimeManager, kubeRuntimeManager)

	return kubeRuntimeManager, nil
}