@@ -17,6 +17,7 @@ import (
17
17
kapi "k8s.io/kubernetes/pkg/api"
18
18
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
19
19
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
20
+ "k8s.io/kubernetes/pkg/client/retry"
20
21
21
22
"github.com/openshift/origin/pkg/client"
22
23
deployapi "github.com/openshift/origin/pkg/deploy/apis/apps"
@@ -51,59 +52,64 @@ func (r *REST) Create(ctx apirequest.Context, obj runtime.Object) (runtime.Objec
51
52
if ! ok {
52
53
return nil , errors .NewInternalError (fmt .Errorf ("wrong object passed for requesting a new rollout: %#v" , obj ))
53
54
}
55
+ var ret runtime.Object
56
+ err := retry .RetryOnConflict (retry .DefaultRetry , func () error {
57
+ configObj , err := r .store .Get (ctx , req .Name , & metav1.GetOptions {})
58
+ if err != nil {
59
+ return err
60
+ }
61
+ config := configObj .(* deployapi.DeploymentConfig )
62
+ old := config
54
63
55
- configObj , err := r .store .Get (ctx , req .Name , & metav1.GetOptions {})
56
- if err != nil {
57
- return nil , err
58
- }
59
- config := configObj .(* deployapi.DeploymentConfig )
60
- old := config
64
+ if errs := validation .ValidateRequestForDeploymentConfig (req , config ); len (errs ) > 0 {
65
+ return errors .NewInvalid (deployapi .Kind ("DeploymentRequest" ), req .Name , errs )
66
+ }
61
67
62
- if errs := validation .ValidateRequestForDeploymentConfig (req , config ); len (errs ) > 0 {
63
- return nil , errors .NewInvalid (deployapi .Kind ("DeploymentRequest" ), req .Name , errs )
64
- }
68
+ // We need to process the deployment config before we can determine if it is possible to trigger
69
+ // a deployment.
70
+ if req .Latest {
71
+ if err := processTriggers (config , r .isn , req .Force , req .ExcludeTriggers ); err != nil {
72
+ return err
73
+ }
74
+ }
65
75
66
- // We need to process the deployment config before we can determine if it is possible to trigger
67
- // a deployment.
68
- if req .Latest {
69
- if err := processTriggers (config , r .isn , req .Force , req .ExcludeTriggers ); err != nil {
70
- return nil , err
76
+ canTrigger , causes , err := canTrigger (config , r .rn , r .decoder , req .Force )
77
+ if err != nil {
78
+ return err
71
79
}
72
- }
80
+ // If we cannot trigger then there is nothing to do here.
81
+ if ! canTrigger {
82
+ ret = & metav1.Status {
83
+ Message : fmt .Sprintf ("deployment config %q cannot be instantiated" , config .Name ),
84
+ Code : int32 (204 ),
85
+ }
86
+ return nil
87
+ }
88
+ glog .V (4 ).Infof ("New deployment for %q caused by %#v" , config .Name , causes )
89
+
90
+ config .Status .Details = new (deployapi.DeploymentDetails )
91
+ config .Status .Details .Causes = causes
92
+ switch causes [0 ].Type {
93
+ case deployapi .DeploymentTriggerOnConfigChange :
94
+ config .Status .Details .Message = "config change"
95
+ case deployapi .DeploymentTriggerOnImageChange :
96
+ config .Status .Details .Message = "image change"
97
+ case deployapi .DeploymentTriggerManual :
98
+ config .Status .Details .Message = "manual change"
99
+ }
100
+ config .Status .LatestVersion ++
73
101
74
- canTrigger , causes , err := canTrigger (config , r .rn , r .decoder , req .Force )
75
- if err != nil {
76
- return nil , err
77
- }
78
- // If we cannot trigger then there is nothing to do here.
79
- if ! canTrigger {
80
- return & metav1.Status {
81
- Message : fmt .Sprintf ("deployment config %q cannot be instantiated" , config .Name ),
82
- Code : int32 (204 ),
83
- }, nil
84
- }
85
- glog .V (4 ).Infof ("New deployment for %q caused by %#v" , config .Name , causes )
86
-
87
- config .Status .Details = new (deployapi.DeploymentDetails )
88
- config .Status .Details .Causes = causes
89
- switch causes [0 ].Type {
90
- case deployapi .DeploymentTriggerOnConfigChange :
91
- config .Status .Details .Message = "config change"
92
- case deployapi .DeploymentTriggerOnImageChange :
93
- config .Status .Details .Message = "image change"
94
- case deployapi .DeploymentTriggerManual :
95
- config .Status .Details .Message = "manual change"
96
- }
97
- config .Status .LatestVersion ++
102
+ userInfo , _ := apirequest .UserFrom (ctx )
103
+ attrs := admission .NewAttributesRecord (config , old , deployapi .Kind ("DeploymentConfig" ).WithVersion ("" ), config .Namespace , config .Name , deployapi .Resource ("DeploymentConfig" ).WithVersion ("" ), "" , admission .Update , userInfo )
104
+ if err := r .admit .Admit (attrs ); err != nil {
105
+ return err
106
+ }
98
107
99
- userInfo , _ := apirequest .UserFrom (ctx )
100
- attrs := admission .NewAttributesRecord (config , old , deployapi .Kind ("DeploymentConfig" ).WithVersion ("" ), config .Namespace , config .Name , deployapi .Resource ("DeploymentConfig" ).WithVersion ("" ), "" , admission .Update , userInfo )
101
- if err := r .admit .Admit (attrs ); err != nil {
102
- return nil , err
103
- }
108
+ ret , _ , err = r .store .Update (ctx , config .Name , rest .DefaultUpdatedObjectInfo (config , kapi .Scheme ))
109
+ return err
110
+ })
104
111
105
- updated , _ , err := r .store .Update (ctx , config .Name , rest .DefaultUpdatedObjectInfo (config , kapi .Scheme ))
106
- return updated , err
112
+ return ret , err
107
113
}
108
114
109
115
// processTriggers will go over all deployment triggers that require processing and update
0 commit comments