本文整理匯總了Golang中k8s/io/kubernetes/pkg/api.Container.ReadinessProbe方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.ReadinessProbe方法的具體用法?Golang Container.ReadinessProbe怎麽用?Golang Container.ReadinessProbe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/api.Container
的用法示例。
在下文中一共展示了Container.ReadinessProbe方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateContainer
func (o *ProbeOptions) updateContainer(container *kapi.Container) {
if o.Remove {
if o.Readiness {
container.ReadinessProbe = nil
}
if o.Liveness {
container.LivenessProbe = nil
}
return
}
if o.Readiness {
if container.ReadinessProbe == nil {
container.ReadinessProbe = &kapi.Probe{}
}
o.updateProbe(container.ReadinessProbe)
}
if o.Liveness {
if container.LivenessProbe == nil {
container.LivenessProbe = &kapi.Probe{}
}
o.updateProbe(container.LivenessProbe)
}
}
示例2: getTestPod
func getTestPod(probeType probeType, probeSpec api.Probe) api.Pod {
container := api.Container{
Name: containerName,
}
switch probeType {
case readiness:
container.ReadinessProbe = &probeSpec
case liveness:
container.LivenessProbe = &probeSpec
}
pod := api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{container},
RestartPolicy: api.RestartPolicyNever,
},
}
pod.UID = podUID
return pod
}
示例3: getTestPod
func getTestPod(probeType probeType, probeSpec api.Probe) api.Pod {
container := api.Container{
Name: testContainerName,
}
// All tests rely on the fake exec prober.
probeSpec.Handler = api.Handler{
Exec: &api.ExecAction{},
}
// Apply test defaults, overwridden for test speed.
defaults := map[string]int64{
"TimeoutSeconds": 1,
"PeriodSeconds": 1,
"SuccessThreshold": 1,
"FailureThreshold": 1,
}
for field, value := range defaults {
f := reflect.ValueOf(&probeSpec).Elem().FieldByName(field)
if f.Int() == 0 {
f.SetInt(value)
}
}
switch probeType {
case readiness:
container.ReadinessProbe = &probeSpec
case liveness:
container.LivenessProbe = &probeSpec
}
pod := api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{container},
RestartPolicy: api.RestartPolicyNever,
},
}
pod.Name = "testPod"
pod.UID = testPodUID
return pod
}
示例4: convert_v1beta3_Container_To_api_Container
func convert_v1beta3_Container_To_api_Container(in *Container, out *api.Container, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*Container))(in)
}
out.Name = in.Name
out.Image = in.Image
if in.Command != nil {
out.Command = make([]string, len(in.Command))
for i := range in.Command {
out.Command[i] = in.Command[i]
}
}
if in.Args != nil {
out.Args = make([]string, len(in.Args))
for i := range in.Args {
out.Args[i] = in.Args[i]
}
}
out.WorkingDir = in.WorkingDir
if in.Ports != nil {
out.Ports = make([]api.ContainerPort, len(in.Ports))
for i := range in.Ports {
if err := convert_v1beta3_ContainerPort_To_api_ContainerPort(&in.Ports[i], &out.Ports[i], s); err != nil {
return err
}
}
}
if in.Env != nil {
out.Env = make([]api.EnvVar, len(in.Env))
for i := range in.Env {
if err := convert_v1beta3_EnvVar_To_api_EnvVar(&in.Env[i], &out.Env[i], s); err != nil {
return err
}
}
}
if err := s.Convert(&in.Resources, &out.Resources, 0); err != nil {
return err
}
if in.VolumeMounts != nil {
out.VolumeMounts = make([]api.VolumeMount, len(in.VolumeMounts))
for i := range in.VolumeMounts {
if err := convert_v1beta3_VolumeMount_To_api_VolumeMount(&in.VolumeMounts[i], &out.VolumeMounts[i], s); err != nil {
return err
}
}
}
if in.LivenessProbe != nil {
out.LivenessProbe = new(api.Probe)
if err := convert_v1beta3_Probe_To_api_Probe(in.LivenessProbe, out.LivenessProbe, s); err != nil {
return err
}
} else {
out.LivenessProbe = nil
}
if in.ReadinessProbe != nil {
out.ReadinessProbe = new(api.Probe)
if err := convert_v1beta3_Probe_To_api_Probe(in.ReadinessProbe, out.ReadinessProbe, s); err != nil {
return err
}
} else {
out.ReadinessProbe = nil
}
if in.Lifecycle != nil {
out.Lifecycle = new(api.Lifecycle)
if err := convert_v1beta3_Lifecycle_To_api_Lifecycle(in.Lifecycle, out.Lifecycle, s); err != nil {
return err
}
} else {
out.Lifecycle = nil
}
out.TerminationMessagePath = in.TerminationMessagePath
out.ImagePullPolicy = api.PullPolicy(in.ImagePullPolicy)
if in.SecurityContext != nil {
if in.SecurityContext.Capabilities != nil {
if !reflect.DeepEqual(in.SecurityContext.Capabilities.Add, in.Capabilities.Add) ||
!reflect.DeepEqual(in.SecurityContext.Capabilities.Drop, in.Capabilities.Drop) {
return fmt.Errorf("container capability settings do not match security context settings, cannot convert")
}
}
if in.SecurityContext.Privileged != nil {
if in.Privileged != *in.SecurityContext.Privileged {
return fmt.Errorf("container privileged settings do not match security context settings, cannot convert")
}
}
}
if in.SecurityContext != nil {
out.SecurityContext = new(api.SecurityContext)
if err := convert_v1beta3_SecurityContext_To_api_SecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil {
return err
}
} else {
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.TTY = in.TTY
return nil
}
示例5: deepCopy_api_Container
func deepCopy_api_Container(in api.Container, out *api.Container, c *conversion.Cloner) error {
out.Name = in.Name
out.Image = in.Image
if in.Command != nil {
out.Command = make([]string, len(in.Command))
for i := range in.Command {
out.Command[i] = in.Command[i]
}
} else {
out.Command = nil
}
if in.Args != nil {
out.Args = make([]string, len(in.Args))
for i := range in.Args {
out.Args[i] = in.Args[i]
}
} else {
out.Args = nil
}
out.WorkingDir = in.WorkingDir
if in.Ports != nil {
out.Ports = make([]api.ContainerPort, len(in.Ports))
for i := range in.Ports {
if err := deepCopy_api_ContainerPort(in.Ports[i], &out.Ports[i], c); err != nil {
return err
}
}
} else {
out.Ports = nil
}
if in.Env != nil {
out.Env = make([]api.EnvVar, len(in.Env))
for i := range in.Env {
if err := deepCopy_api_EnvVar(in.Env[i], &out.Env[i], c); err != nil {
return err
}
}
} else {
out.Env = nil
}
if err := deepCopy_api_ResourceRequirements(in.Resources, &out.Resources, c); err != nil {
return err
}
if in.VolumeMounts != nil {
out.VolumeMounts = make([]api.VolumeMount, len(in.VolumeMounts))
for i := range in.VolumeMounts {
if err := deepCopy_api_VolumeMount(in.VolumeMounts[i], &out.VolumeMounts[i], c); err != nil {
return err
}
}
} else {
out.VolumeMounts = nil
}
if in.LivenessProbe != nil {
out.LivenessProbe = new(api.Probe)
if err := deepCopy_api_Probe(*in.LivenessProbe, out.LivenessProbe, c); err != nil {
return err
}
} else {
out.LivenessProbe = nil
}
if in.ReadinessProbe != nil {
out.ReadinessProbe = new(api.Probe)
if err := deepCopy_api_Probe(*in.ReadinessProbe, out.ReadinessProbe, c); err != nil {
return err
}
} else {
out.ReadinessProbe = nil
}
if in.Lifecycle != nil {
out.Lifecycle = new(api.Lifecycle)
if err := deepCopy_api_Lifecycle(*in.Lifecycle, out.Lifecycle, c); err != nil {
return err
}
} else {
out.Lifecycle = nil
}
out.TerminationMessagePath = in.TerminationMessagePath
out.ImagePullPolicy = in.ImagePullPolicy
if in.SecurityContext != nil {
out.SecurityContext = new(api.SecurityContext)
if err := deepCopy_api_SecurityContext(*in.SecurityContext, out.SecurityContext, c); err != nil {
return err
}
} else {
out.SecurityContext = nil
}
out.Stdin = in.Stdin
out.TTY = in.TTY
return nil
}
示例6: TestProbe
func TestProbe(t *testing.T) {
prober := &prober{
refManager: kubecontainer.NewRefManager(),
recorder: &record.FakeRecorder{},
}
containerID := kubecontainer.ContainerID{Type: "test", ID: "foobar"}
execProbe := &api.Probe{
Handler: api.Handler{
Exec: &api.ExecAction{},
},
}
tests := []struct {
probe *api.Probe
execError bool
expectError bool
execResult probe.Result
expectedResult results.Result
}{
{ // No probe
probe: nil,
expectedResult: results.Success,
},
{ // No handler
probe: &api.Probe{},
expectError: true,
expectedResult: results.Failure,
},
{ // Probe fails
probe: execProbe,
execResult: probe.Failure,
expectedResult: results.Failure,
},
{ // Probe succeeds
probe: execProbe,
execResult: probe.Success,
expectedResult: results.Success,
},
{ // Probe result is unknown
probe: execProbe,
execResult: probe.Unknown,
expectedResult: results.Failure,
},
{ // Probe has an error
probe: execProbe,
execError: true,
expectError: true,
execResult: probe.Unknown,
expectedResult: results.Failure,
},
}
for i, test := range tests {
for _, probeType := range [...]probeType{liveness, readiness} {
testID := fmt.Sprintf("%d-%s", i, probeType)
testContainer := api.Container{}
switch probeType {
case liveness:
testContainer.LivenessProbe = test.probe
case readiness:
testContainer.ReadinessProbe = test.probe
}
if test.execError {
prober.exec = fakeExecProber{test.execResult, errors.New("exec error")}
} else {
prober.exec = fakeExecProber{test.execResult, nil}
}
result, err := prober.probe(probeType, &api.Pod{}, api.PodStatus{}, testContainer, containerID)
if test.expectError && err == nil {
t.Errorf("[%s] Expected probe error but no error was returned.", testID)
}
if !test.expectError && err != nil {
t.Errorf("[%s] Didn't expect probe error but got: %v", testID, err)
}
if test.expectedResult != result {
t.Errorf("[%s] Expected result to be %v but was %v", testID, test.expectedResult, result)
}
}
}
}
示例7: writePodContainer
func writePodContainer(m map[string]interface{}, item *api.Container) error {
if x, ok := m["name"].(string); ok {
item.Name = x
}
if x, ok := m["image"].(string); ok {
item.Image = x
}
if x, ok := m["image_pull_policy"].(string); ok {
item.ImagePullPolicy = api.PullPolicy(x)
}
if x, ok := m["termination_message_path"].(string); ok {
item.TerminationMessagePath = x
}
if x, ok := m["working_dir"].(string); ok {
item.WorkingDir = x
}
if x, ok := m["command"].([]interface{}); ok {
for _, y := range x {
item.Command = append(item.Command, y.(string))
}
}
if x, ok := m["args"].([]interface{}); ok {
for _, y := range x {
item.Args = append(item.Args, y.(string))
}
}
if x, ok := m["port"].([]interface{}); ok {
for _, y := range x {
ref := api.ContainerPort{}
writeContainerPort(y.(map[string]interface{}), &ref)
item.Ports = append(item.Ports, ref)
}
}
if x, ok := m["env"].([]interface{}); ok {
for _, y := range x {
ref := api.EnvVar{}
writeEnvVar(y.(map[string]interface{}), &ref)
item.Env = append(item.Env, ref)
}
}
if x, ok := m["volume_mount"].([]interface{}); ok {
for _, y := range x {
ref := api.VolumeMount{}
writeVolumeMount(y.(map[string]interface{}), &ref)
item.VolumeMounts = append(item.VolumeMounts, ref)
}
}
if n, ok := extractSingleMap(m["liveness_probe"]); ok {
item.LivenessProbe = &api.Probe{}
writeProbe(n, item.LivenessProbe)
}
if n, ok := extractSingleMap(m["readiness_probe"]); ok {
item.ReadinessProbe = &api.Probe{}
writeProbe(n, item.ReadinessProbe)
}
if n, ok := extractSingleMap(m["resources"]); ok {
if o, ok := extractSingleMap(n["limits"]); ok {
item.Resources.Limits = make(api.ResourceList)
if x, ok := o["cpu"].(string); ok && x != "" {
q, err := resource.ParseQuantity(x)
if err != nil {
return fmt.Errorf("%s for %q", err, x)
}
item.Resources.Limits[api.ResourceCPU] = *q
}
if x, ok := o["memory"].(string); ok && x != "" {
q, err := resource.ParseQuantity(x)
if err != nil {
return fmt.Errorf("%s for %q", err, x)
}
item.Resources.Limits[api.ResourceMemory] = *q
}
}
if o, ok := extractSingleMap(n["requests"]); ok {
item.Resources.Requests = make(api.ResourceList)
if x, ok := o["cpu"].(string); ok && x != "" {
q, err := resource.ParseQuantity(x)
if err != nil {
return fmt.Errorf("%s for %q", err, x)
}
item.Resources.Requests[api.ResourceCPU] = *q
}
if x, ok := o["memory"].(string); ok && x != "" {
q, err := resource.ParseQuantity(x)
if err != nil {
return fmt.Errorf("%s for %q", err, x)
}
//.........這裏部分代碼省略.........