2016-08-02 23:25:02 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
|
|
|
|
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 kuberuntime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2016-09-25 02:07:43 +00:00
|
|
|
cadvisorapi "github.com/google/cadvisor/info/v1"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2017-01-30 18:39:54 +00:00
|
|
|
"k8s.io/client-go/tools/record"
|
2017-01-23 18:37:22 +00:00
|
|
|
"k8s.io/client-go/util/flowcontrol"
|
2016-08-08 07:40:53 +00:00
|
|
|
"k8s.io/kubernetes/pkg/credentialprovider"
|
2017-02-23 00:05:05 +00:00
|
|
|
internalapi "k8s.io/kubernetes/pkg/kubelet/apis/cri"
|
2017-09-01 17:46:39 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubelet/cm"
|
2016-08-02 23:25:02 +00:00
|
|
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
2016-08-08 07:40:53 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubelet/images"
|
|
|
|
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
2016-08-02 23:25:02 +00:00
|
|
|
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
|
|
|
|
)
|
|
|
|
|
2017-11-22 02:49:23 +00:00
|
|
|
const (
|
|
|
|
fakeSeccompProfileRoot = "/fakeSeccompProfileRoot"
|
|
|
|
)
|
|
|
|
|
2016-08-02 23:25:02 +00:00
|
|
|
type fakeHTTP struct {
|
|
|
|
url string
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeHTTP) Get(url string) (*http.Response, error) {
|
|
|
|
f.url = url
|
|
|
|
return nil, f.err
|
|
|
|
}
|
|
|
|
|
2017-09-28 16:37:21 +00:00
|
|
|
type fakePodStateProvider struct {
|
|
|
|
existingPods map[types.UID]struct{}
|
|
|
|
runningPods map[types.UID]struct{}
|
2016-08-24 04:48:13 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 16:37:21 +00:00
|
|
|
func newFakePodStateProvider() *fakePodStateProvider {
|
|
|
|
return &fakePodStateProvider{
|
|
|
|
existingPods: make(map[types.UID]struct{}),
|
|
|
|
runningPods: make(map[types.UID]struct{}),
|
2017-08-28 17:43:43 +00:00
|
|
|
}
|
2016-08-24 04:48:13 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 16:37:21 +00:00
|
|
|
func (f *fakePodStateProvider) IsPodDeleted(uid types.UID) bool {
|
|
|
|
_, found := f.existingPods[uid]
|
|
|
|
return !found
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakePodStateProvider) IsPodTerminated(uid types.UID) bool {
|
|
|
|
_, found := f.runningPods[uid]
|
2017-08-28 17:43:43 +00:00
|
|
|
return !found
|
2016-08-24 04:48:13 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 01:42:29 +00:00
|
|
|
func NewFakeKubeRuntimeManager(runtimeService internalapi.RuntimeService, imageService internalapi.ImageManagerService, machineInfo *cadvisorapi.MachineInfo, osInterface kubecontainer.OSInterface, runtimeHelper kubecontainer.RuntimeHelper, keyring credentialprovider.DockerKeyring) (*kubeGenericRuntimeManager, error) {
|
2016-08-08 07:40:53 +00:00
|
|
|
recorder := &record.FakeRecorder{}
|
|
|
|
kubeRuntimeManager := &kubeGenericRuntimeManager{
|
|
|
|
recorder: recorder,
|
|
|
|
cpuCFSQuota: false,
|
|
|
|
livenessManager: proberesults.NewManager(),
|
|
|
|
containerRefManager: kubecontainer.NewRefManager(),
|
2016-09-25 02:07:43 +00:00
|
|
|
machineInfo: machineInfo,
|
2016-08-08 07:40:53 +00:00
|
|
|
osInterface: osInterface,
|
2017-02-27 04:07:49 +00:00
|
|
|
runtimeHelper: runtimeHelper,
|
2016-08-08 07:40:53 +00:00
|
|
|
runtimeService: runtimeService,
|
|
|
|
imageService: imageService,
|
2017-05-04 01:42:29 +00:00
|
|
|
keyring: keyring,
|
2017-11-22 02:49:23 +00:00
|
|
|
seccompProfileRoot: fakeSeccompProfileRoot,
|
2017-09-01 17:46:39 +00:00
|
|
|
internalLifecycle: cm.NewFakeInternalContainerLifecycle(),
|
2016-08-08 07:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedVersion, err := runtimeService.Version(kubeRuntimeAPIVersion)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-09-28 16:37:21 +00:00
|
|
|
kubeRuntimeManager.containerGC = NewContainerGC(runtimeService, newFakePodStateProvider(), kubeRuntimeManager)
|
2017-01-20 01:55:56 +00:00
|
|
|
kubeRuntimeManager.runtimeName = typedVersion.RuntimeName
|
2016-08-08 07:40:53 +00:00
|
|
|
kubeRuntimeManager.imagePuller = images.NewImageManager(
|
|
|
|
kubecontainer.FilterEventRecorder(recorder),
|
|
|
|
kubeRuntimeManager,
|
2016-08-02 23:25:02 +00:00
|
|
|
flowcontrol.NewBackOff(time.Second, 300*time.Second),
|
2016-09-21 21:26:17 +00:00
|
|
|
false,
|
|
|
|
0, // Disable image pull throttling by setting QPS to 0,
|
|
|
|
0,
|
|
|
|
)
|
2016-08-08 07:40:53 +00:00
|
|
|
kubeRuntimeManager.runner = lifecycle.NewHandlerRunner(
|
|
|
|
&fakeHTTP{},
|
|
|
|
kubeRuntimeManager,
|
|
|
|
kubeRuntimeManager)
|
|
|
|
|
|
|
|
return kubeRuntimeManager, nil
|
2016-08-02 23:25:02 +00:00
|
|
|
}
|