Updated the --metrics flag of the oc cluster up command to create a job
so that it will automatically retry if it fails due to the service account
token not being created yet.
Fixes issue #11946
... | ... |
@@ -3,11 +3,12 @@ package openshift |
3 | 3 |
import ( |
4 | 4 |
"fmt" |
5 | 5 |
|
6 |
- "github.com/openshift/origin/pkg/cmd/util/clientcmd" |
|
7 | 6 |
kapi "k8s.io/kubernetes/pkg/api" |
8 | 7 |
apierrors "k8s.io/kubernetes/pkg/api/errors" |
8 |
+ kbatch "k8s.io/kubernetes/pkg/apis/batch" |
|
9 | 9 |
|
10 | 10 |
"github.com/openshift/origin/pkg/bootstrap/docker/errors" |
11 |
+ "github.com/openshift/origin/pkg/cmd/util/clientcmd" |
|
11 | 12 |
) |
12 | 13 |
|
13 | 14 |
const ( |
... | ... |
@@ -15,7 +16,7 @@ const ( |
15 | 15 |
svcMetrics = "hawkular-metrics" |
16 | 16 |
metricsDeployerSA = "metrics-deployer" |
17 | 17 |
metricsDeployerSecret = "metrics-deployer" |
18 |
- metricsDeployerPodName = "metrics-deployer-pod" |
|
18 |
+ metricsDeployerJobName = "metrics-deployer-pod" |
|
19 | 19 |
) |
20 | 20 |
|
21 | 21 |
// InstallMetrics checks whether metrics is installed and installs it if not already installed |
... | ... |
@@ -65,15 +66,17 @@ func (h *Helper) InstallMetrics(f *clientcmd.Factory, hostName, imagePrefix, ima |
65 | 65 |
return errors.NewError("cannot create metrics deployer secret").WithCause(err).WithDetails(h.OriginLog()) |
66 | 66 |
} |
67 | 67 |
|
68 |
- // Create deployer Pod |
|
69 |
- deployerPod := metricsDeployerPod(hostName, imagePrefix, imageVersion) |
|
70 |
- if _, err = kubeClient.Pods(infraNamespace).Create(deployerPod); err != nil { |
|
71 |
- return errors.NewError("cannot create metrics deployer pod").WithCause(err).WithDetails(h.OriginLog()) |
|
72 |
- } |
|
68 |
+ // Create the job client |
|
69 |
+ jobClient := kubeClient.Batch().Jobs(infraNamespace) |
|
70 |
+ |
|
71 |
+ // Submit the job |
|
72 |
+ jobClient.Create(metricsDeployerJob(hostName, imagePrefix, imageVersion)) |
|
73 |
+ |
|
73 | 74 |
return nil |
74 | 75 |
} |
75 | 76 |
|
76 |
-func metricsDeployerPod(hostName, imagePrefix, imageVersion string) *kapi.Pod { |
|
77 |
+// Returns a job to create the metrics deployer pod |
|
78 |
+func metricsDeployerJob(hostName, imagePrefix, imageVersion string) *kbatch.Job { |
|
77 | 79 |
env := []kapi.EnvVar{ |
78 | 80 |
{ |
79 | 81 |
Name: "PROJECT", |
... | ... |
@@ -144,49 +147,65 @@ func metricsDeployerPod(hostName, imagePrefix, imageVersion string) *kapi.Pod { |
144 | 144 |
Value: "10s", |
145 | 145 |
}, |
146 | 146 |
} |
147 |
- pod := &kapi.Pod{ |
|
148 |
- Spec: kapi.PodSpec{ |
|
149 |
- DNSPolicy: kapi.DNSClusterFirst, |
|
150 |
- RestartPolicy: kapi.RestartPolicyNever, |
|
151 |
- ServiceAccountName: metricsDeployerSA, |
|
152 |
- Volumes: []kapi.Volume{ |
|
153 |
- { |
|
154 |
- Name: "empty", |
|
155 |
- VolumeSource: kapi.VolumeSource{ |
|
156 |
- EmptyDir: &kapi.EmptyDirVolumeSource{}, |
|
147 |
+ podSpec := kapi.PodSpec{ |
|
148 |
+ DNSPolicy: kapi.DNSClusterFirst, |
|
149 |
+ RestartPolicy: kapi.RestartPolicyNever, |
|
150 |
+ ServiceAccountName: metricsDeployerSA, |
|
151 |
+ Volumes: []kapi.Volume{ |
|
152 |
+ { |
|
153 |
+ Name: "empty", |
|
154 |
+ VolumeSource: kapi.VolumeSource{ |
|
155 |
+ EmptyDir: &kapi.EmptyDirVolumeSource{}, |
|
156 |
+ }, |
|
157 |
+ }, |
|
158 |
+ { |
|
159 |
+ Name: "secret", |
|
160 |
+ VolumeSource: kapi.VolumeSource{ |
|
161 |
+ Secret: &kapi.SecretVolumeSource{ |
|
162 |
+ SecretName: metricsDeployerSecret, |
|
157 | 163 |
}, |
158 | 164 |
}, |
159 |
- { |
|
160 |
- Name: "secret", |
|
161 |
- VolumeSource: kapi.VolumeSource{ |
|
162 |
- Secret: &kapi.SecretVolumeSource{ |
|
163 |
- SecretName: metricsDeployerSecret, |
|
164 |
- }, |
|
165 |
+ }, |
|
166 |
+ }, |
|
167 |
+ Containers: []kapi.Container{ |
|
168 |
+ { |
|
169 |
+ Image: fmt.Sprintf("%s-metrics-deployer:%s", imagePrefix, imageVersion), |
|
170 |
+ Name: "deployer", |
|
171 |
+ VolumeMounts: []kapi.VolumeMount{ |
|
172 |
+ { |
|
173 |
+ Name: "secret", |
|
174 |
+ MountPath: "/secret", |
|
175 |
+ ReadOnly: true, |
|
176 |
+ }, |
|
177 |
+ { |
|
178 |
+ Name: "empty", |
|
179 |
+ MountPath: "/etc/deploy", |
|
165 | 180 |
}, |
166 | 181 |
}, |
182 |
+ Env: env, |
|
167 | 183 |
}, |
168 | 184 |
}, |
169 | 185 |
} |
170 |
- pod.Name = metricsDeployerPodName |
|
171 |
- pod.Spec.Containers = []kapi.Container{ |
|
172 |
- { |
|
173 |
- Image: fmt.Sprintf("%s-metrics-deployer:%s", imagePrefix, imageVersion), |
|
174 |
- Name: "deployer", |
|
175 |
- VolumeMounts: []kapi.VolumeMount{ |
|
176 |
- { |
|
177 |
- Name: "secret", |
|
178 |
- MountPath: "/secret", |
|
179 |
- ReadOnly: true, |
|
180 |
- }, |
|
181 |
- { |
|
182 |
- Name: "empty", |
|
183 |
- MountPath: "/etc/deploy", |
|
184 |
- }, |
|
186 |
+ |
|
187 |
+ completions := int32(1) |
|
188 |
+ |
|
189 |
+ deadline := int64(60 * 5) |
|
190 |
+ |
|
191 |
+ meta := kapi.ObjectMeta{ |
|
192 |
+ Name: metricsDeployerJobName, |
|
193 |
+ } |
|
194 |
+ |
|
195 |
+ job := &kbatch.Job{ |
|
196 |
+ ObjectMeta: meta, |
|
197 |
+ Spec: kbatch.JobSpec{ |
|
198 |
+ Completions: &completions, |
|
199 |
+ ActiveDeadlineSeconds: &deadline, |
|
200 |
+ Template: kapi.PodTemplateSpec{ |
|
201 |
+ Spec: podSpec, |
|
185 | 202 |
}, |
186 |
- Env: env, |
|
187 | 203 |
}, |
188 | 204 |
} |
189 |
- return pod |
|
205 |
+ return job |
|
190 | 206 |
} |
191 | 207 |
|
192 | 208 |
func MetricsHost(routingSuffix, serverIP string) string { |