本文整理汇总了Golang中github.com/openshift/origin/pkg/util.MergeInto函数的典型用法代码示例。如果您正苦于以下问题:Golang MergeInto函数的具体用法?Golang MergeInto怎么用?Golang MergeInto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MergeInto函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: makeDeployerPod
// makeDeployerPod creates a pod which implements deployment behavior. The pod is correlated to
// the deployment with an annotation.
func (c *DeploymentController) makeDeployerPod(deployment *kapi.ReplicationController) (*kapi.Pod, error) {
deploymentConfig, err := c.decodeConfig(deployment)
if err != nil {
return nil, err
}
container, err := c.makeContainer(&deploymentConfig.Spec.Strategy)
if err != nil {
return nil, err
}
// Add deployment environment variables to the container.
envVars := []kapi.EnvVar{}
for _, env := range container.Env {
envVars = append(envVars, env)
}
envVars = append(envVars, kapi.EnvVar{Name: "OPENSHIFT_DEPLOYMENT_NAME", Value: deployment.Name})
envVars = append(envVars, kapi.EnvVar{Name: "OPENSHIFT_DEPLOYMENT_NAMESPACE", Value: deployment.Namespace})
// Assigning to a variable since its address is required
maxDeploymentDurationSeconds := deployapi.MaxDeploymentDurationSeconds
pod := &kapi.Pod{
ObjectMeta: kapi.ObjectMeta{
Name: deployutil.DeployerPodNameForDeployment(deployment.Name),
Annotations: map[string]string{
deployapi.DeploymentAnnotation: deployment.Name,
},
Labels: map[string]string{
deployapi.DeployerPodForDeploymentLabel: deployment.Name,
},
},
Spec: kapi.PodSpec{
Containers: []kapi.Container{
{
Name: "deployment",
Command: container.Command,
Args: container.Args,
Image: container.Image,
Env: envVars,
Resources: deploymentConfig.Spec.Strategy.Resources,
},
},
ActiveDeadlineSeconds: &maxDeploymentDurationSeconds,
// Setting the node selector on the deployer pod so that it is created
// on the same set of nodes as the pods.
NodeSelector: deployment.Spec.Template.Spec.NodeSelector,
RestartPolicy: kapi.RestartPolicyNever,
ServiceAccountName: c.serviceAccount,
},
}
// MergeInfo will not overwrite values unless the flag OverwriteExistingDstKey is set.
util.MergeInto(pod.Labels, deploymentConfig.Spec.Strategy.Labels, 0)
util.MergeInto(pod.Annotations, deploymentConfig.Spec.Strategy.Annotations, 0)
pod.Spec.Containers[0].ImagePullPolicy = kapi.PullIfNotPresent
return pod, nil
}
开发者ID:richm,项目名称:origin,代码行数:62,代码来源:controller.go
示例2: makeHookPod
//.........这里部分代码省略.........
// container environment
envMap := map[string]kapi.EnvVar{}
mergedEnv := []kapi.EnvVar{}
for _, env := range baseContainer.Env {
envMap[env.Name] = env
}
for _, env := range exec.Env {
envMap[env.Name] = env
}
for k, v := range envMap {
mergedEnv = append(mergedEnv, kapi.EnvVar{Name: k, Value: v.Value, ValueFrom: v.ValueFrom})
}
mergedEnv = append(mergedEnv, kapi.EnvVar{Name: "OPENSHIFT_DEPLOYMENT_NAME", Value: deployment.Name})
mergedEnv = append(mergedEnv, kapi.EnvVar{Name: "OPENSHIFT_DEPLOYMENT_NAMESPACE", Value: deployment.Namespace})
// Inherit resources from the base container
resources := kapi.ResourceRequirements{}
if err := kapi.Scheme.Convert(&baseContainer.Resources, &resources, nil); err != nil {
return nil, fmt.Errorf("couldn't clone ResourceRequirements: %v", err)
}
// Assigning to a variable since its address is required
maxDeploymentDurationSeconds := deployapi.MaxDeploymentDurationSeconds - int64(time.Since(deployerPod.Status.StartTime.Time).Seconds())
// Let the kubelet manage retries if requested
restartPolicy := kapi.RestartPolicyNever
if hook.FailurePolicy == deployapi.LifecycleHookFailurePolicyRetry {
restartPolicy = kapi.RestartPolicyOnFailure
}
// Transfer any requested volumes to the hook pod.
volumes := []kapi.Volume{}
volumeNames := sets.NewString()
for _, volume := range deployment.Spec.Template.Spec.Volumes {
for _, name := range exec.Volumes {
if volume.Name == name {
volumes = append(volumes, volume)
volumeNames.Insert(volume.Name)
}
}
}
// Transfer any volume mounts associated with transferred volumes.
volumeMounts := []kapi.VolumeMount{}
for _, mount := range baseContainer.VolumeMounts {
if volumeNames.Has(mount.Name) {
volumeMounts = append(volumeMounts, kapi.VolumeMount{
Name: mount.Name,
ReadOnly: mount.ReadOnly,
MountPath: mount.MountPath,
})
}
}
// Transfer image pull secrets from the pod spec.
imagePullSecrets := []kapi.LocalObjectReference{}
for _, pullSecret := range deployment.Spec.Template.Spec.ImagePullSecrets {
imagePullSecrets = append(imagePullSecrets, kapi.LocalObjectReference{Name: pullSecret.Name})
}
gracePeriod := int64(10)
pod := &kapi.Pod{
ObjectMeta: kapi.ObjectMeta{
Name: namer.GetPodName(deployment.Name, suffix),
Annotations: map[string]string{
deployapi.DeploymentAnnotation: deployment.Name,
},
Labels: map[string]string{
deployapi.DeploymentPodTypeLabel: suffix,
deployapi.DeployerPodForDeploymentLabel: deployment.Name,
},
},
Spec: kapi.PodSpec{
Containers: []kapi.Container{
{
Name: HookContainerName,
Image: baseContainer.Image,
Command: exec.Command,
WorkingDir: baseContainer.WorkingDir,
Env: mergedEnv,
Resources: resources,
VolumeMounts: volumeMounts,
},
},
Volumes: volumes,
ActiveDeadlineSeconds: &maxDeploymentDurationSeconds,
// Setting the node selector on the hook pod so that it is created
// on the same set of nodes as the deployment pods.
NodeSelector: deployment.Spec.Template.Spec.NodeSelector,
RestartPolicy: restartPolicy,
ImagePullSecrets: imagePullSecrets,
TerminationGracePeriodSeconds: &gracePeriod,
},
}
util.MergeInto(pod.Labels, strategy.Labels, 0)
util.MergeInto(pod.Annotations, strategy.Annotations, 0)
return pod, nil
}
开发者ID:LalatenduMohanty,项目名称:origin,代码行数:101,代码来源:lifecycle.go
示例3: DeploymentConfig
// DeploymentConfig creates a deploymentConfig resource from the deployment configuration reference
//
// TODO: take a pod template spec as argument
func (r *DeploymentConfigRef) DeploymentConfig() (*deployapi.DeploymentConfig, error) {
if len(r.Name) == 0 {
suggestions := NameSuggestions{}
for i := range r.Images {
suggestions = append(suggestions, r.Images[i])
}
name, ok := suggestions.SuggestName()
if !ok {
return nil, fmt.Errorf("unable to suggest a name for this DeploymentConfig")
}
r.Name = name
}
selector := map[string]string{
"deploymentconfig": r.Name,
}
if len(r.Labels) > 0 {
if err := util.MergeInto(selector, r.Labels, 0); err != nil {
return nil, err
}
}
triggers := []deployapi.DeploymentTriggerPolicy{
// By default, always deploy on change
{
Type: deployapi.DeploymentTriggerOnConfigChange,
},
}
template := kapi.PodSpec{}
for i := range r.Images {
c, containerTriggers, err := r.Images[i].DeployableContainer()
if err != nil {
return nil, err
}
triggers = append(triggers, containerTriggers...)
template.Containers = append(template.Containers, *c)
}
// Create EmptyDir volumes for all container volume mounts
for _, c := range template.Containers {
for _, v := range c.VolumeMounts {
template.Volumes = append(template.Volumes, kapi.Volume{
Name: v.Name,
VolumeSource: kapi.VolumeSource{
EmptyDir: &kapi.EmptyDirVolumeSource{Medium: kapi.StorageMediumDefault},
},
})
}
}
for i := range template.Containers {
template.Containers[i].Env = append(template.Containers[i].Env, r.Env.List()...)
}
return &deployapi.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{
Name: r.Name,
},
Template: deployapi.DeploymentTemplate{
ControllerTemplate: kapi.ReplicationControllerSpec{
Replicas: 1,
Selector: selector,
Template: &kapi.PodTemplateSpec{
ObjectMeta: kapi.ObjectMeta{
Labels: selector,
},
Spec: template,
},
},
},
Triggers: triggers,
}, nil
}
开发者ID:kcbabo,项目名称:origin,代码行数:77,代码来源:app.go
示例4: DeploymentConfig
// DeploymentConfig creates a deploymentConfig resource from the deployment configuration reference
//
// TODO: take a pod template spec as argument
func (r *DeploymentConfigRef) DeploymentConfig() (*deployapi.DeploymentConfig, error) {
if len(r.Name) == 0 {
suggestions := NameSuggestions{}
for i := range r.Images {
suggestions = append(suggestions, r.Images[i])
}
name, ok := suggestions.SuggestName()
if !ok {
return nil, fmt.Errorf("unable to suggest a name for this DeploymentConfig")
}
r.Name = name
}
selector := map[string]string{
"deploymentconfig": r.Name,
}
if len(r.Labels) > 0 {
if err := util.MergeInto(selector, r.Labels, 0); err != nil {
return nil, err
}
}
triggers := []deployapi.DeploymentTriggerPolicy{
// By default, always deploy on change
{
Type: deployapi.DeploymentTriggerOnConfigChange,
},
}
annotations := make(map[string]string)
template := kapi.PodSpec{}
for i := range r.Images {
c, containerTriggers, err := r.Images[i].DeployableContainer()
if err != nil {
return nil, err
}
triggers = append(triggers, containerTriggers...)
template.Containers = append(template.Containers, *c)
if cmd, ok := r.Images[i].Command(); ok {
imageapi.SetContainerImageEntrypointAnnotation(annotations, c.Name, cmd)
}
}
// Create EmptyDir volumes for all container volume mounts
for _, c := range template.Containers {
for _, v := range c.VolumeMounts {
template.Volumes = append(template.Volumes, kapi.Volume{
Name: v.Name,
VolumeSource: kapi.VolumeSource{
EmptyDir: &kapi.EmptyDirVolumeSource{Medium: kapi.StorageMediumDefault},
},
})
}
}
for i := range template.Containers {
template.Containers[i].Env = append(template.Containers[i].Env, r.Env.List()...)
}
dc := &deployapi.DeploymentConfig{
ObjectMeta: kapi.ObjectMeta{
Name: r.Name,
},
Spec: deployapi.DeploymentConfigSpec{
Replicas: 1,
Test: r.AsTest,
Selector: selector,
Template: &kapi.PodTemplateSpec{
ObjectMeta: kapi.ObjectMeta{
Labels: selector,
Annotations: annotations,
},
Spec: template,
},
Triggers: triggers,
},
}
if r.PostHook != nil {
//dc.Spec.Strategy.Type = "Rolling"
if len(r.PostHook.Shell) > 0 {
dc.Spec.Strategy.RecreateParams = &deployapi.RecreateDeploymentStrategyParams{
Post: &deployapi.LifecycleHook{
ExecNewPod: &deployapi.ExecNewPodHook{
Command: []string{"/bin/sh", "-c", r.PostHook.Shell},
},
},
}
}
}
return dc, nil
}
开发者ID:Xmagicer,项目名称:origin,代码行数:96,代码来源:app.go
注:本文中的github.com/openshift/origin/pkg/util.MergeInto函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论