@@ -58,6 +58,13 @@ const (
58
58
59
59
// CPUPanel is the ID of the CPU panel on OSM's MeshDetails dashboard
60
60
CPUPanel int = 14
61
+
62
+ // maxPodCreationRetries determines the max number of retries for creating
63
+ // a Pod (including via a Deployment) upon failure
64
+ maxPodCreationRetries = 2
65
+
66
+ // delayIntervalForPodCreationRetries
67
+ delayIntervalForPodCreationRetries = 5 * time .Second
61
68
)
62
69
63
70
var (
@@ -105,24 +112,49 @@ func (td *OsmTestData) createRoleBinding(ns string, roleBinding *rbacv1.RoleBind
105
112
return rb , nil
106
113
}
107
114
115
+ func (td * OsmTestData ) getMaxPodCreationRetries () int {
116
+ if td .RetryAppPodCreation {
117
+ return maxPodCreationRetries
118
+ }
119
+ return 1
120
+ }
121
+
108
122
// CreatePod is a wrapper to create a pod
109
123
func (td * OsmTestData ) CreatePod (ns string , pod corev1.Pod ) (* corev1.Pod , error ) {
110
- podRet , err := td .Client .CoreV1 ().Pods (ns ).Create (context .Background (), & pod , metav1.CreateOptions {})
111
- if err != nil {
112
- err := fmt .Errorf ("Could not create Pod: %v" , err )
113
- return nil , err
124
+ maxRetries := td .getMaxPodCreationRetries ()
125
+
126
+ for i := 1 ; i <= maxRetries ; i ++ {
127
+ if i > 1 {
128
+ // Sleep before next retry
129
+ time .Sleep (delayIntervalForPodCreationRetries )
130
+ }
131
+ podRet , err := td .Client .CoreV1 ().Pods (ns ).Create (context .Background (), & pod , metav1.CreateOptions {})
132
+ if err != nil {
133
+ td .T .Logf ("Could not create Pod in attempt %d due to error: %v" , i , err )
134
+ continue
135
+ }
136
+ return podRet , nil
114
137
}
115
- return podRet , nil
138
+ return nil , errors . Errorf ( "Error creating pod in namespace %s after %d attempts" , ns , maxRetries )
116
139
}
117
140
118
141
// CreateDeployment is a wrapper to create a deployment
119
142
func (td * OsmTestData ) CreateDeployment (ns string , deployment appsv1.Deployment ) (* appsv1.Deployment , error ) {
120
- deploymentRet , err := td .Client .AppsV1 ().Deployments (ns ).Create (context .Background (), & deployment , metav1.CreateOptions {})
121
- if err != nil {
122
- err := fmt .Errorf ("Could not create Deployment: %v" , err )
123
- return nil , err
143
+ maxRetries := td .getMaxPodCreationRetries ()
144
+
145
+ for i := 1 ; i <= maxRetries ; i ++ {
146
+ if i > 1 {
147
+ // Sleep before next retry
148
+ time .Sleep (delayIntervalForPodCreationRetries )
149
+ }
150
+ deploymentRet , err := td .Client .AppsV1 ().Deployments (ns ).Create (context .Background (), & deployment , metav1.CreateOptions {})
151
+ if err != nil {
152
+ td .T .Logf ("Could not create Deployment in attempt %d due to error: %v" , i , err )
153
+ continue
154
+ }
155
+ return deploymentRet , nil
124
156
}
125
- return deploymentRet , nil
157
+ return nil , errors . Errorf ( "Error creating Deployment in namespace %s after %d attempts" , ns , maxRetries )
126
158
}
127
159
128
160
// CreateService is a wrapper to create a service
0 commit comments