本文整理汇总了Golang中github.com/openshift/origin/pkg/deploy/util.DecodeDeploymentConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeDeploymentConfig函数的具体用法?Golang DecodeDeploymentConfig怎么用?Golang DecodeDeploymentConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodeDeploymentConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: emitEvent
func (e *HookExecutor) emitEvent(deployment *kapi.ReplicationController, eventType, reason, msg string) {
t := unversioned.Time{Time: time.Now()}
var ref *kapi.ObjectReference
if config, err := deployutil.DecodeDeploymentConfig(deployment, e.decoder); err != nil {
glog.Errorf("Unable to decode deployment %s/%s to replication contoller: %v", deployment.Namespace, deployment.Name, err)
if ref, err = kapi.GetReference(deployment); err != nil {
glog.Errorf("Unable to get reference for %#v: %v", deployment, err)
return
}
} else {
if ref, err = kapi.GetReference(config); err != nil {
glog.Errorf("Unable to get reference for %#v: %v", config, err)
return
}
}
event := &kapi.Event{
ObjectMeta: kapi.ObjectMeta{
Name: fmt.Sprintf("%v.%x", ref.Name, t.UnixNano()),
Namespace: ref.Namespace,
},
InvolvedObject: *ref,
Reason: reason,
Message: msg,
FirstTimestamp: t,
LastTimestamp: t,
Count: 1,
Type: eventType,
}
if _, err := e.events.Create(event); err != nil {
glog.Errorf("Could not send event '%#v': %v", event, err)
}
}
示例2: TestHandle_waitForImageController
// TestHandle_waitForImageController tests an initial deployment with unresolved image. The config
// change controller should never increment latestVersion, thus trigger a deployment for this config.
func TestHandle_waitForImageController(t *testing.T) {
fake := &testclient.Fake{}
kFake := &ktestclient.Fake{}
fake.PrependReactor("update", "deploymentconfigs/status", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
t.Fatalf("an update should never run before the template image is resolved")
return true, nil, nil
})
controller := &DeploymentConfigChangeController{
client: fake,
kClient: kFake,
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion))
},
}
config := testapi.OkDeploymentConfig(0)
config.Namespace = kapi.NamespaceDefault
config.Spec.Triggers = []deployapi.DeploymentTriggerPolicy{testapi.OkConfigChangeTrigger(), testapi.OkImageChangeTrigger()}
if err := controller.Handle(config); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
示例3: emitDeploymentEvent
func (c *DeploymentController) emitDeploymentEvent(deployment *kapi.ReplicationController, eventType, title, message string) {
if config, _ := deployutil.DecodeDeploymentConfig(deployment, c.codec); config != nil {
c.recorder.Eventf(config, eventType, title, fmt.Sprintf("%s: %s", deployment.Name, message))
} else {
c.recorder.Eventf(deployment, eventType, title, message)
}
}
示例4: TestHandle_newConfigNoTriggers
// TestHandle_newConfigNoTriggers ensures that a change to a config with no
// triggers doesn't result in a new config version bump.
func TestHandle_newConfigNoTriggers(t *testing.T) {
controller := &DeploymentConfigChangeController{
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, api.Codec)
},
changeStrategy: &changeStrategyImpl{
generateDeploymentConfigFunc: func(namespace, name string) (*deployapi.DeploymentConfig, error) {
t.Fatalf("unexpected generation of deploymentConfig")
return nil, nil
},
updateDeploymentConfigFunc: func(namespace string, config *deployapi.DeploymentConfig) (*deployapi.DeploymentConfig, error) {
t.Fatalf("unexpected update of deploymentConfig")
return config, nil
},
},
}
config := deployapitest.OkDeploymentConfig(1)
config.Spec.Triggers = []deployapi.DeploymentTriggerPolicy{}
err := controller.Handle(config)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
示例5: RecordConfigEvent
// RecordConfigEvent records an event for the deployment config referenced by the
// deployment.
func RecordConfigEvent(client kclient.EventNamespacer, deployment *kapi.ReplicationController, decoder runtime.Decoder, eventType, reason, msg string) {
t := unversioned.Time{Time: time.Now()}
var obj runtime.Object = deployment
if config, err := deployutil.DecodeDeploymentConfig(deployment, decoder); err == nil {
obj = config
} else {
glog.Errorf("Unable to decode deployment config from %s/%s: %v", deployment.Namespace, deployment.Name, err)
}
ref, err := kapi.GetReference(obj)
if err != nil {
glog.Errorf("Unable to get reference for %#v: %v", obj, err)
return
}
event := &kapi.Event{
ObjectMeta: kapi.ObjectMeta{
Name: fmt.Sprintf("%v.%x", ref.Name, t.UnixNano()),
Namespace: ref.Namespace,
},
InvolvedObject: *ref,
Reason: reason,
Message: msg,
Source: kapi.EventSource{
Component: deployutil.DeployerPodNameFor(deployment),
},
FirstTimestamp: t,
LastTimestamp: t,
Count: 1,
Type: eventType,
}
if _, err := client.Events(ref.Namespace).Create(event); err != nil {
glog.Errorf("Could not create event '%#v': %v", event, err)
}
}
示例6: 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 := deployutil.DecodeDeploymentConfig(deployment, c.codec)
if err != nil {
return nil, err
}
container := c.makeDeployerContainer(&deploymentConfig.Spec.Strategy)
// 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,
DNSPolicy: deployment.Spec.Template.Spec.DNSPolicy,
ImagePullSecrets: deployment.Spec.Template.Spec.ImagePullSecrets,
// 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
}
示例7: TestHandle_cleanupDesiredReplicasAnnotation
// TestHandle_cleanupDesiredReplicasAnnotation ensures that the desired replicas annotation
// will be cleaned up in a complete deployment and stay around in a failed deployment
func TestHandle_cleanupDesiredReplicasAnnotation(t *testing.T) {
// shared fixtures shouldn't be used in unit tests
shared, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(1), kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion))
tests := []struct {
name string
pod *kapi.Pod
expected bool
}{
{
name: "complete deployment - cleaned up annotation",
pod: succeededPod(shared),
expected: false,
},
{
name: "failed deployment - annotation stays",
pod: terminatedPod(shared),
expected: true,
},
}
for _, test := range tests {
deployment, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(1), kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion))
var updatedDeployment *kapi.ReplicationController
deployment.Annotations[deployapi.DesiredReplicasAnnotation] = "1"
kFake := &ktestclient.Fake{}
kFake.PrependReactor("get", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
return true, deployment, nil
})
kFake.PrependReactor("update", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
updatedDeployment = deployment
return true, deployment, nil
})
controller := &DeployerPodController{
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, kapi.Codecs.UniversalDecoder())
},
store: cache.NewStore(cache.MetaNamespaceKeyFunc),
kClient: kFake,
}
if err := controller.Handle(test.pod); err != nil {
t.Errorf("%s: unexpected error: %v", test.name, err)
continue
}
if updatedDeployment == nil {
t.Errorf("%s: expected deployment update", test.name)
continue
}
if _, got := updatedDeployment.Annotations[deployapi.DesiredReplicasAnnotation]; got != test.expected {
t.Errorf("%s: expected annotation: %t, got %t", test.name, test.expected, got)
}
}
}
示例8: TestHandle_cleanupPodOk
// TestHandle_cleanupPodOk ensures that deployer pods are cleaned up for
// deployments in a completed state.
func TestHandle_cleanupPodOk(t *testing.T) {
deployerPodNames := []string{"pod1", "pod2", "pod3"}
deletedPodNames := []string{}
controller := &DeploymentController{
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, api.Codec)
},
deploymentClient: &deploymentClientImpl{
updateDeploymentFunc: func(namespace string, deployment *kapi.ReplicationController) (*kapi.ReplicationController, error) {
t.Fatalf("unexpected deployment update")
return nil, nil
},
},
podClient: &podClientImpl{
createPodFunc: func(namespace string, pod *kapi.Pod) (*kapi.Pod, error) {
t.Fatalf("unexpected call to create pod")
return nil, nil
},
deletePodFunc: func(namespace, name string) error {
deletedPodNames = append(deletedPodNames, name)
return nil
},
getDeployerPodsForFunc: func(namespace, name string) ([]kapi.Pod, error) {
pods := []kapi.Pod{}
for _, podName := range deployerPodNames {
pod := *ttlNonZeroPod()
pod.Name = podName
pods = append(pods, pod)
}
return pods, nil
},
},
makeContainer: func(strategy *deployapi.DeploymentStrategy) (*kapi.Container, error) {
t.Fatalf("unexpected call to make container")
return nil, nil
},
recorder: &record.FakeRecorder{},
}
// Verify successful cleanup
config := deploytest.OkDeploymentConfig(1)
deployment, _ := deployutil.MakeDeployment(config, kapi.Codec)
deployment.Annotations[deployapi.DeploymentStatusAnnotation] = string(deployapi.DeploymentStatusComplete)
err := controller.Handle(deployment)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
sort.Strings(deployerPodNames)
sort.Strings(deletedPodNames)
if !reflect.DeepEqual(deletedPodNames, deletedPodNames) {
t.Fatalf("pod deletions - expected: %v, actual: %v", deployerPodNames, deletedPodNames)
}
}
示例9: TestHandle_cleanupDesiredReplicasAnnotation
// TestHandle_cleanupDesiredReplicasAnnotation ensures that the desired replicas annotation
// will be cleaned up in a complete deployment and stay around in a failed deployment
func TestHandle_cleanupDesiredReplicasAnnotation(t *testing.T) {
deployment, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(1), kapi.Codec)
tests := []struct {
name string
pod *kapi.Pod
expected bool
}{
{
name: "complete deployment - cleaned up annotation",
pod: succeededPod(deployment),
expected: false,
},
{
name: "failed deployment - annotation stays",
pod: terminatedPod(deployment),
expected: true,
},
}
for _, test := range tests {
var updatedDeployment *kapi.ReplicationController
deployment.Annotations[deployapi.DesiredReplicasAnnotation] = "1"
controller := &DeployerPodController{
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, kapi.Codec)
},
deploymentClient: &deploymentClientImpl{
getDeploymentFunc: func(namespace, name string) (*kapi.ReplicationController, error) {
return deployment, nil
},
updateDeploymentFunc: func(namespace string, deployment *kapi.ReplicationController) (*kapi.ReplicationController, error) {
updatedDeployment = deployment
return deployment, nil
},
listDeploymentsForConfigFunc: func(namespace, configName string) (*kapi.ReplicationControllerList, error) {
return &kapi.ReplicationControllerList{Items: []kapi.ReplicationController{*deployment}}, nil
},
},
}
if err := controller.Handle(test.pod); err != nil {
t.Errorf("%s: unexpected error: %v", test.name, err)
continue
}
if updatedDeployment == nil {
t.Errorf("%s: expected deployment update", test.name)
continue
}
if _, got := updatedDeployment.Annotations[deployapi.DesiredReplicasAnnotation]; got != test.expected {
t.Errorf("%s: expected annotation: %t, got %t", test.name, test.expected, got)
}
}
}
示例10: TestHandle_cleanupPendingRunning
// TestHandle_cleanupPendingRunning ensures that deployer pods are deleted
// for deployments in post-New phases.
func TestHandle_cleanupPendingRunning(t *testing.T) {
deployerPodCount := 3
deletedPods := 0
controller := &DeploymentController{
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion))
},
deploymentClient: &deploymentClientImpl{
updateDeploymentFunc: func(namespace string, deployment *kapi.ReplicationController) (*kapi.ReplicationController, error) {
// None of these tests should transition the phase.
t.Errorf("unexpected call to updateDeployment")
return nil, nil
},
},
podClient: &podClientImpl{
getPodFunc: func(namespace, name string) (*kapi.Pod, error) {
return ttlNonZeroPod(), nil
},
deletePodFunc: func(namespace, name string) error {
deletedPods++
return nil
},
getDeployerPodsForFunc: func(namespace, name string) ([]kapi.Pod, error) {
pods := []kapi.Pod{}
for i := 0; i < deployerPodCount; i++ {
pods = append(pods, *ttlNonZeroPod())
}
return pods, nil
},
},
makeContainer: func(strategy *deployapi.DeploymentStrategy) *kapi.Container {
return okContainer()
},
recorder: &record.FakeRecorder{},
}
cases := []deployapi.DeploymentStatus{
deployapi.DeploymentStatusPending,
deployapi.DeploymentStatusRunning,
}
for _, status := range cases {
deletedPods = 0
deployment, _ := deployutil.MakeDeployment(deploytest.OkDeploymentConfig(1), kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion))
deployment.Annotations[deployapi.DeploymentStatusAnnotation] = string(status)
deployment.Annotations[deployapi.DeploymentCancelledAnnotation] = deployapi.DeploymentCancelledAnnotationValue
err := controller.Handle(deployment)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if e, a := deletedPods, deployerPodCount; e != a {
t.Fatalf("expected %d deleted pods, got %d", e, a)
}
}
}
示例11: Create
// Create creates a DeploymentConfigChangeController.
func (factory *DeploymentConfigChangeControllerFactory) Create() controller.RunnableController {
deploymentConfigLW := &deployutil.ListWatcherImpl{
ListFunc: func() (runtime.Object, error) {
return factory.Client.DeploymentConfigs(kapi.NamespaceAll).List(labels.Everything(), fields.Everything())
},
WatchFunc: func(resourceVersion string) (watch.Interface, error) {
return factory.Client.DeploymentConfigs(kapi.NamespaceAll).Watch(labels.Everything(), fields.Everything(), resourceVersion)
},
}
queue := cache.NewFIFO(cache.MetaNamespaceKeyFunc)
cache.NewReflector(deploymentConfigLW, &deployapi.DeploymentConfig{}, queue, 2*time.Minute).Run()
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartRecordingToSink(factory.KubeClient.Events(""))
changeController := &DeploymentConfigChangeController{
changeStrategy: &changeStrategyImpl{
getDeploymentFunc: func(namespace, name string) (*kapi.ReplicationController, error) {
return factory.KubeClient.ReplicationControllers(namespace).Get(name)
},
generateDeploymentConfigFunc: func(namespace, name string) (*deployapi.DeploymentConfig, error) {
return factory.Client.DeploymentConfigs(namespace).Generate(name)
},
updateDeploymentConfigFunc: func(namespace string, config *deployapi.DeploymentConfig) (*deployapi.DeploymentConfig, error) {
return factory.Client.DeploymentConfigs(namespace).Update(config)
},
},
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, factory.Codec)
},
recorder: eventBroadcaster.NewRecorder(kapi.EventSource{Component: "deployer"}),
}
return &controller.RetryController{
Queue: queue,
RetryManager: controller.NewQueueRetryManager(
queue,
cache.MetaNamespaceKeyFunc,
func(obj interface{}, err error, retries controller.Retry) bool {
kutil.HandleError(err)
if _, isFatal := err.(fatalError); isFatal {
return false
}
if retries.Count > 0 {
return false
}
return true
},
kutil.NewTokenBucketRateLimiter(1, 10),
),
Handle: func(obj interface{}) error {
config := obj.(*deployapi.DeploymentConfig)
return changeController.Handle(config)
},
}
}
示例12: TestHandle_canceledDeploymentTriggerTest
// TestHandle_canceledDeploymentTrigger ensures that a canceled deployment
// will trigger a reconcilation of its deploymentconfig (via an annotation
// update) so that rolling back can happen on the spot and not rely on the
// deploymentconfig cache resync interval.
func TestHandle_canceledDeploymentTriggerTest(t *testing.T) {
var (
updatedDeployment *kapi.ReplicationController
updatedConfig *deployapi.DeploymentConfig
)
initial := deploytest.OkDeploymentConfig(1)
// Canceled deployment
deployment, _ := deployutil.MakeDeployment(deploytest.TestDeploymentConfig(initial), kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion))
deployment.Annotations[deployapi.DeploymentCancelledAnnotation] = deployapi.DeploymentCancelledAnnotationValue
kFake := &ktestclient.Fake{}
kFake.PrependReactor("get", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
return true, deployment, nil
})
kFake.PrependReactor("update", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
updatedDeployment = deployment
return true, deployment, nil
})
fake := &testclient.Fake{}
fake.PrependReactor("get", "deploymentconfigs", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
config := initial
return true, config, nil
})
fake.PrependReactor("update", "deploymentconfigs", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
updated := action.(ktestclient.UpdateAction).GetObject().(*deployapi.DeploymentConfig)
updatedConfig = updated
return true, updated, nil
})
controller := &DeployerPodController{
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, kapi.Codecs.UniversalDecoder())
},
store: cache.NewStore(cache.MetaNamespaceKeyFunc),
client: fake,
kClient: kFake,
}
err := controller.Handle(terminatedPod(deployment))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if updatedDeployment == nil {
t.Fatalf("expected deployment update")
}
if e, a := deployapi.DeploymentStatusFailed, deployutil.DeploymentStatusFor(updatedDeployment); e != a {
t.Fatalf("expected updated deployment status %s, got %s", e, a)
}
if updatedConfig == nil {
t.Fatalf("expected config update")
}
}
示例13: TestDeployerCustomLabelsAndAnnotations
func TestDeployerCustomLabelsAndAnnotations(t *testing.T) {
controller := &DeploymentController{
decodeConfig: func(deployment *kapi.ReplicationController) (*deployapi.DeploymentConfig, error) {
return deployutil.DecodeDeploymentConfig(deployment, api.Codec)
},
podClient: &podClientImpl{
createPodFunc: func(namespace string, pod *kapi.Pod) (*kapi.Pod, error) {
return pod, nil
},
},
makeContainer: func(strategy *deployapi.DeploymentStrategy) (*kapi.Container, error) {
return okContainer(), nil
},
}
testCases := []struct {
name string
strategy deployapi.DeploymentStrategy
labels map[string]string
annotations map[string]string
verifyLabels bool
}{
{name: "labels and annotations", strategy: deploytest.OkStrategy(), labels: map[string]string{"label1": "value1"}, annotations: map[string]string{"annotation1": "value1"}, verifyLabels: true},
{name: "custom strategy, no annotations", strategy: deploytest.OkCustomStrategy(), labels: map[string]string{"label2": "value2", "label3": "value3"}, verifyLabels: true},
{name: "custom strategy, no labels", strategy: deploytest.OkCustomStrategy(), annotations: map[string]string{"annotation3": "value3"}, verifyLabels: true},
{name: "no overrride", strategy: deploytest.OkStrategy(), labels: map[string]string{deployapi.DeployerPodForDeploymentLabel: "ignored"}, verifyLabels: false},
}
for _, test := range testCases {
t.Logf("evaluating test case %s", test.name)
config := deploytest.OkDeploymentConfig(1)
config.Spec.Strategy = test.strategy
config.Spec.Strategy.Labels = test.labels
config.Spec.Strategy.Annotations = test.annotations
deployment, _ := deployutil.MakeDeployment(config, kapi.Codec)
podTemplate, err := controller.makeDeployerPod(deployment)
if err != nil {
t.Fatal(err)
}
nameLabel, ok := podTemplate.Labels[deployapi.DeployerPodForDeploymentLabel]
if ok && nameLabel != deployment.Name {
t.Errorf("label %s expected %s, got %s", deployapi.DeployerPodForDeploymentLabel, deployment.Name, nameLabel)
} else if !ok {
t.Errorf("label %s not present", deployapi.DeployerPodForDeploymentLabel)
}
if test.verifyLabels {
expectMapContains(t, podTemplate.Labels, test.labels, "labels")
}
expectMapContains(t, podTemplate.Annotations, test.annotations, "annotations")
}
}
示例14: Create
// Create generates a new DeploymentConfig representing a rollback.
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
namespace, ok := kapi.NamespaceFrom(ctx)
if !ok {
return nil, kerrors.NewBadRequest("namespace parameter required.")
}
rollback, ok := obj.(*deployapi.DeploymentConfigRollback)
if !ok {
return nil, kerrors.NewBadRequest(fmt.Sprintf("not a rollback spec: %#v", obj))
}
if errs := validation.ValidateDeploymentConfigRollback(rollback); len(errs) > 0 {
return nil, kerrors.NewInvalid(deployapi.Kind("DeploymentConfigRollback"), rollback.Name, errs)
}
from, err := r.dn.DeploymentConfigs(namespace).Get(rollback.Name)
if err != nil {
return nil, newInvalidError(rollback, fmt.Sprintf("cannot get deployment config %q: %v", rollback.Name, err))
}
switch from.Status.LatestVersion {
case 0:
return nil, newInvalidError(rollback, "cannot rollback an undeployed config")
case 1:
return nil, newInvalidError(rollback, fmt.Sprintf("no previous deployment exists for %q", deployutil.LabelForDeploymentConfig(from)))
}
revision := from.Status.LatestVersion - 1
if rollback.Spec.Revision > 0 {
revision = rollback.Spec.Revision
}
// Find the target deployment and decode its config.
name := deployutil.DeploymentNameForConfigVersion(from.Name, revision)
targetDeployment, err := r.rn.ReplicationControllers(namespace).Get(name)
if err != nil {
return nil, newInvalidError(rollback, err.Error())
}
to, err := deployutil.DecodeDeploymentConfig(targetDeployment, r.codec)
if err != nil {
return nil, newInvalidError(rollback, fmt.Sprintf("couldn't decode deployment config from deployment: %v", err))
}
if from.Annotations == nil && len(rollback.UpdatedAnnotations) > 0 {
from.Annotations = make(map[string]string)
}
for key, value := range rollback.UpdatedAnnotations {
from.Annotations[key] = value
}
return r.generator.GenerateRollback(from, to, &rollback.Spec)
}
示例15: executeExecNewPod
// executeExecNewPod executes a ExecNewPod hook by creating a new pod based on
// the hook parameters and deployment. The pod is then synchronously watched
// until the pod completes, and if the pod failed, an error is returned.
//
// The hook pod inherits the following from the container the hook refers to:
//
// * Environment (hook keys take precedence)
// * Working directory
// * Resources
func (e *HookExecutor) executeExecNewPod(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, label string) error {
config, err := deployutil.DecodeDeploymentConfig(deployment, e.codec)
if err != nil {
return err
}
// Build a pod spec from the hook config and deployment
podSpec, err := makeHookPod(hook, deployment, &config.Template.Strategy, label)
if err != nil {
return err
}
// Try to create the pod.
pod, err := e.podClient.CreatePod(deployment.Namespace, podSpec)
if err != nil {
if !kerrors.IsAlreadyExists(err) {
return fmt.Errorf("couldn't create lifecycle pod for %s: %v", deployutil.LabelForDeployment(deployment), err)
}
} else {
glog.V(0).Infof("Created lifecycle pod %s/%s for deployment %s", pod.Namespace, pod.Name, deployutil.LabelForDeployment(deployment))
}
stopChannel := make(chan struct{})
defer close(stopChannel)
nextPod := e.podClient.PodWatch(pod.Namespace, pod.Name, pod.ResourceVersion, stopChannel)
// Wait for the hook pod to reach a terminal phase. Start reading logs as
// soon as the pod enters a usable phase.
var updatedPod *kapi.Pod
var once sync.Once
wg := &sync.WaitGroup{}
wg.Add(1)
glog.V(0).Infof("Watching logs for hook pod %s/%s while awaiting completion", pod.Namespace, pod.Name)
waitLoop:
for {
updatedPod = nextPod()
switch updatedPod.Status.Phase {
case kapi.PodRunning:
go once.Do(func() { e.readPodLogs(pod, wg) })
case kapi.PodSucceeded, kapi.PodFailed:
go once.Do(func() { e.readPodLogs(pod, wg) })
break waitLoop
}
}
// The pod is finished, wait for all logs to be consumed before returning.
wg.Wait()
if updatedPod.Status.Phase == kapi.PodFailed {
return fmt.Errorf(updatedPod.Status.Message)
}
return nil
}