// PrepareForUpdate clears fields that are not allowed to be set by end users on update. func (strategy) PrepareForUpdate(obj, old runtime.Object) { newDc := obj.(*api.DeploymentConfig) oldDc := old.(*api.DeploymentConfig) newVersion := newDc.Status.LatestVersion oldVersion := oldDc.Status.LatestVersion // Persist status newDc.Status = oldDc.Status // oc deploy --latest from new clients and image change controller updates on deployment // configs without config change triggers. if newVersion == oldVersion && deployutil.IsInstantiated(newDc) { // TODO: Have an endpoint for this and avoid hacking it here. newDc.Status.LatestVersion = oldVersion + 1 delete(newDc.Annotations, api.DeploymentInstantiatedAnnotation) } // oc deploy --latest from old clients // TODO: Remove once we drop support for older clients if newVersion == oldVersion+1 { newDc.Status.LatestVersion = newVersion } // Any changes to the spec or labels, increment the generation number, any changes // to the status should reflect the generation number of the corresponding object // (should be handled by the controller). if !reflect.DeepEqual(oldDc.Spec, newDc.Spec) || newDc.Status.LatestVersion != oldDc.Status.LatestVersion { newDc.Generation = oldDc.Generation + 1 } }
// TestCmdDeploy_latestOk ensures that attempts to start a new deployment // succeeds given an existing deployment in a terminal state. func TestCmdDeploy_latestOk(t *testing.T) { validStatusList := []deployapi.DeploymentStatus{ deployapi.DeploymentStatusComplete, deployapi.DeploymentStatusFailed, } for _, status := range validStatusList { config := deploytest.OkDeploymentConfig(1) var updatedConfig *deployapi.DeploymentConfig osClient := &tc.Fake{} osClient.AddReactor("get", "deploymentconfigs", func(action ktc.Action) (handled bool, ret runtime.Object, err error) { return true, config, nil }) osClient.AddReactor("update", "deploymentconfigs", func(action ktc.Action) (handled bool, ret runtime.Object, err error) { updatedConfig = action.(ktc.UpdateAction).GetObject().(*deployapi.DeploymentConfig) return true, updatedConfig, nil }) kubeClient := &ktc.Fake{} kubeClient.AddReactor("get", "replicationcontrollers", func(action ktc.Action) (handled bool, ret runtime.Object, err error) { return true, deploymentFor(config, status), nil }) o := &DeployOptions{osClient: osClient, kubeClient: kubeClient} err := o.deploy(config, ioutil.Discard) if err != nil { t.Fatalf("unexpected error: %v", err) } if updatedConfig == nil { t.Fatalf("expected updated config") } if !deployutil.IsInstantiated(updatedConfig) { t.Fatalf("expected deployment config instantiation") } } }