本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api.DNSPolicy函数的典型用法代码示例。如果您正苦于以下问题:Golang DNSPolicy函数的具体用法?Golang DNSPolicy怎么用?Golang DNSPolicy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DNSPolicy函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestValidateDNSPolicy
func TestValidateDNSPolicy(t *testing.T) {
successCases := []api.DNSPolicy{api.DNSClusterFirst, api.DNSDefault, api.DNSPolicy("")}
for _, policy := range successCases {
if errs := validateDNSPolicy(&policy); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
}
errorCases := []api.DNSPolicy{api.DNSPolicy("invalid")}
for _, policy := range errorCases {
if errs := validateDNSPolicy(&policy); len(errs) == 0 {
t.Errorf("expected failure for %v", policy)
}
}
}
示例2: TestValidatePodSpec
func TestValidatePodSpec(t *testing.T) {
successCases := []api.PodSpec{
{}, // empty is valid, if not very useful */
{ // Populate basic fields, leave defaults for most.
Volumes: []api.Volume{{Name: "vol"}},
Containers: []api.Container{{Name: "ctr", Image: "image"}},
},
{ // Populate all fields.
Volumes: []api.Volume{
{Name: "vol"},
},
Containers: []api.Container{{Name: "ctr", Image: "image"}},
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}},
DNSPolicy: api.DNSClusterFirst,
NodeSelector: map[string]string{
"key": "value",
},
Host: "foobar",
},
}
for i := range successCases {
if errs := ValidatePodSpec(&successCases[i]); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
}
failureCases := map[string]api.PodSpec{
"bad volume": {
Volumes: []api.Volume{{}},
},
"bad container": {
Containers: []api.Container{{}},
},
"bad DNS policy": {
DNSPolicy: api.DNSPolicy("invalid"),
},
}
for k, v := range failureCases {
if errs := ValidatePodSpec(&v); len(errs) == 0 {
t.Errorf("expected failure for %q", k)
}
}
defaultPod := api.PodSpec{} // all empty fields
if errs := ValidatePodSpec(&defaultPod); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
if util.AllPtrFieldsNil(defaultPod.RestartPolicy) {
t.Errorf("expected a default RestartPolicy")
}
if defaultPod.DNSPolicy == "" {
t.Errorf("expected a default DNSPolicy")
}
}
示例3: init
//.........这里部分代码省略.........
if err := s.Convert(&in.DesiredState.Manifest, &out.Spec, 0); err != nil {
return err
}
out.Spec.Host = in.DesiredState.Host
if err := s.Convert(&in.Labels, &out.ObjectMeta.Labels, 0); err != nil {
return err
}
return nil
},
func(in *newer.PodSpec, out *BoundPod, s conversion.Scope) error {
if err := s.Convert(&in, &out.Spec, 0); err != nil {
return err
}
return nil
},
func(in *BoundPod, out *newer.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Spec, &out, 0); err != nil {
return err
}
return nil
},
func(in *newer.PodSpec, out *ContainerManifest, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
}
if err := s.Convert(&in.Containers, &out.Containers, 0); err != nil {
return err
}
if err := s.Convert(&in.RestartPolicy, &out.RestartPolicy, 0); err != nil {
return err
}
out.DNSPolicy = DNSPolicy(in.DNSPolicy)
out.Version = "v1beta2"
return nil
},
func(in *ContainerManifest, out *newer.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
}
if err := s.Convert(&in.Containers, &out.Containers, 0); err != nil {
return err
}
if err := s.Convert(&in.RestartPolicy, &out.RestartPolicy, 0); err != nil {
return err
}
out.DNSPolicy = newer.DNSPolicy(in.DNSPolicy)
return nil
},
func(in *newer.Service, out *Service, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}
out.Port = in.Spec.Port
out.Protocol = Protocol(in.Spec.Protocol)
if err := s.Convert(&in.Spec.Selector, &out.Selector, 0); err != nil {
return err
示例4: addConversionFuncs
//.........这里部分代码省略.........
}
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 err := s.Convert(&in.SecurityContext, &out.SecurityContext, 0); err != nil {
return err
}
return nil
},
func(in *api.PodSpec, out *ContainerManifest, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
}
if err := s.Convert(&in.Containers, &out.Containers, 0); err != nil {
return err
}
if err := s.Convert(&in.RestartPolicy, &out.RestartPolicy, 0); err != nil {
return err
}
if err := s.Convert(&in.ImagePullSecrets, &out.ImagePullSecrets, 0); err != nil {
return err
}
if in.TerminationGracePeriodSeconds != nil {
out.TerminationGracePeriodSeconds = new(int64)
*out.TerminationGracePeriodSeconds = *in.TerminationGracePeriodSeconds
}
if in.ActiveDeadlineSeconds != nil {
out.ActiveDeadlineSeconds = new(int64)
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
}
out.DNSPolicy = DNSPolicy(in.DNSPolicy)
out.Version = "v1beta2"
out.HostNetwork = in.HostNetwork
return nil
},
func(in *ContainerManifest, out *api.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
}
if err := s.Convert(&in.Containers, &out.Containers, 0); err != nil {
return err
}
if err := s.Convert(&in.RestartPolicy, &out.RestartPolicy, 0); err != nil {
return err
}
if err := s.Convert(&in.ImagePullSecrets, &out.ImagePullSecrets, 0); err != nil {
return err
}
if in.TerminationGracePeriodSeconds != nil {
out.TerminationGracePeriodSeconds = new(int64)
*out.TerminationGracePeriodSeconds = *in.TerminationGracePeriodSeconds
}
if in.ActiveDeadlineSeconds != nil {
out.ActiveDeadlineSeconds = new(int64)
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
}
out.DNSPolicy = api.DNSPolicy(in.DNSPolicy)
out.HostNetwork = in.HostNetwork
return nil
},
func(in *api.PodStatus, out *PodState, s conversion.Scope) error {
if err := s.Convert(&in.Phase, &out.Status, 0); err != nil {
示例5: convert_v1_PodSpec_To_api_PodSpec
func convert_v1_PodSpec_To_api_PodSpec(in *PodSpec, out *api.PodSpec, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*PodSpec))(in)
}
if in.Volumes != nil {
out.Volumes = make([]api.Volume, len(in.Volumes))
for i := range in.Volumes {
if err := convert_v1_Volume_To_api_Volume(&in.Volumes[i], &out.Volumes[i], s); err != nil {
return err
}
}
} else {
out.Volumes = nil
}
if in.Containers != nil {
out.Containers = make([]api.Container, len(in.Containers))
for i := range in.Containers {
if err := convert_v1_Container_To_api_Container(&in.Containers[i], &out.Containers[i], s); err != nil {
return err
}
}
} else {
out.Containers = nil
}
out.RestartPolicy = api.RestartPolicy(in.RestartPolicy)
if in.TerminationGracePeriodSeconds != nil {
out.TerminationGracePeriodSeconds = new(int64)
*out.TerminationGracePeriodSeconds = *in.TerminationGracePeriodSeconds
} else {
out.TerminationGracePeriodSeconds = nil
}
if in.ActiveDeadlineSeconds != nil {
out.ActiveDeadlineSeconds = new(int64)
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
} else {
out.ActiveDeadlineSeconds = nil
}
out.DNSPolicy = api.DNSPolicy(in.DNSPolicy)
if in.NodeSelector != nil {
out.NodeSelector = make(map[string]string)
for key, val := range in.NodeSelector {
out.NodeSelector[key] = val
}
} else {
out.NodeSelector = nil
}
// We support DeprecatedServiceAccount as an alias for ServiceAccountName.
// If both are specified, ServiceAccountName (the new field) wins.
out.ServiceAccountName = in.ServiceAccountName
if in.ServiceAccountName == "" {
out.ServiceAccountName = in.DeprecatedServiceAccount
}
out.NodeName = in.NodeName
// carry conversion
if in.NodeName == "" {
out.NodeName = in.DeprecatedHost
}
out.HostNetwork = in.HostNetwork
if in.ImagePullSecrets != nil {
out.ImagePullSecrets = make([]api.LocalObjectReference, len(in.ImagePullSecrets))
for i := range in.ImagePullSecrets {
if err := convert_v1_LocalObjectReference_To_api_LocalObjectReference(&in.ImagePullSecrets[i], &out.ImagePullSecrets[i], s); err != nil {
return err
}
}
} else {
out.ImagePullSecrets = nil
}
return nil
}
示例6: init
//.........这里部分代码省略.........
if err := s.Convert(&in.LivenessProbe, &out.LivenessProbe, 0); err != nil {
return err
}
if err := s.Convert(&in.ReadinessProbe, &out.ReadinessProbe, 0); err != nil {
return err
}
if err := s.Convert(&in.Lifecycle, &out.Lifecycle, 0); err != nil {
return err
}
if err := s.Convert(&in.TerminationMessagePath, &out.TerminationMessagePath, 0); err != nil {
return err
}
if err := s.Convert(&in.Privileged, &out.Privileged, 0); err != nil {
return err
}
if err := s.Convert(&in.ImagePullPolicy, &out.ImagePullPolicy, 0); err != nil {
return err
}
if err := s.Convert(&in.Capabilities, &out.Capabilities, 0); err != nil {
return err
}
return nil
},
func(in *newer.PodSpec, out *ContainerManifest, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
}
if err := s.Convert(&in.Containers, &out.Containers, 0); err != nil {
return err
}
if err := s.Convert(&in.RestartPolicy, &out.RestartPolicy, 0); err != nil {
return err
}
out.DNSPolicy = DNSPolicy(in.DNSPolicy)
out.Version = "v1beta2"
return nil
},
func(in *ContainerManifest, out *newer.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
}
if err := s.Convert(&in.Containers, &out.Containers, 0); err != nil {
return err
}
if err := s.Convert(&in.RestartPolicy, &out.RestartPolicy, 0); err != nil {
return err
}
out.DNSPolicy = newer.DNSPolicy(in.DNSPolicy)
return nil
},
func(in *newer.Service, out *Service, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}
out.Port = in.Spec.Port
out.Protocol = Protocol(in.Spec.Protocol)
if err := s.Convert(&in.Spec.Selector, &out.Selector, 0); err != nil {
return err
示例7: init
//.........这里部分代码省略.........
if err := s.Convert(&in.LivenessProbe, &out.LivenessProbe, 0); err != nil {
return err
}
if err := s.Convert(&in.ReadinessProbe, &out.ReadinessProbe, 0); err != nil {
return err
}
if err := s.Convert(&in.Lifecycle, &out.Lifecycle, 0); err != nil {
return err
}
if err := s.Convert(&in.TerminationMessagePath, &out.TerminationMessagePath, 0); err != nil {
return err
}
if err := s.Convert(&in.Privileged, &out.Privileged, 0); err != nil {
return err
}
if err := s.Convert(&in.ImagePullPolicy, &out.ImagePullPolicy, 0); err != nil {
return err
}
if err := s.Convert(&in.Capabilities, &out.Capabilities, 0); err != nil {
return err
}
return nil
},
func(in *newer.PodSpec, out *ContainerManifest, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
}
if err := s.Convert(&in.Containers, &out.Containers, 0); err != nil {
return err
}
if err := s.Convert(&in.RestartPolicy, &out.RestartPolicy, 0); err != nil {
return err
}
out.DNSPolicy = DNSPolicy(in.DNSPolicy)
out.Version = "v1beta2"
return nil
},
func(in *ContainerManifest, out *newer.PodSpec, s conversion.Scope) error {
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
return err
}
if err := s.Convert(&in.Containers, &out.Containers, 0); err != nil {
return err
}
if err := s.Convert(&in.RestartPolicy, &out.RestartPolicy, 0); err != nil {
return err
}
out.DNSPolicy = newer.DNSPolicy(in.DNSPolicy)
return nil
},
func(in *newer.PodStatus, out *PodState, s conversion.Scope) error {
if err := s.Convert(&in.Phase, &out.Status, 0); err != nil {
return err
}
if err := s.Convert(&in.Info, &out.Info, 0); err != nil {
return err
}
if err := s.Convert(&in.Conditions, &out.Conditions, 0); err != nil {
return err
}
out.Message = in.Message
out.Host = in.Host
out.HostIP = in.HostIP
out.PodIP = in.PodIP
return nil