|
1 | 1 | package controller |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "crypto/md5" |
| 5 | + "encoding/hex" |
4 | 6 | "errors" |
5 | 7 | "fmt" |
6 | 8 | "time" |
@@ -250,12 +252,13 @@ func createManagedResources(r GenericTunnelReconciler) (ctrl.Result, error) { |
250 | 252 | } |
251 | 253 |
|
252 | 254 | // Check if ConfigMap already exists, else create it |
253 | | - if err := k8s.MergeOrApply(r, configMapForTunnel(r)); err != nil { |
| 255 | + cm := configMapForTunnel(r) |
| 256 | + if err := k8s.MergeOrApply(r, cm); err != nil { |
254 | 257 | return ctrl.Result{}, err |
255 | 258 | } |
256 | 259 |
|
257 | 260 | // Apply patch to deployment |
258 | | - dep := deploymentForTunnel(r) |
| 261 | + dep := deploymentForTunnel(r, cm.Data[configmapKey]) |
259 | 262 | if err := k8s.StrategicPatch(dep, r.GetTunnel().GetSpec().DeployPatch, dep); err != nil { |
260 | 263 | r.GetLog().Error(err, "unable to patch deployment, check patch") |
261 | 264 | r.GetRecorder().Event(r.GetTunnel().GetObject(), corev1.EventTypeWarning, "FailedPatch", "Failed to patch deployment, check patch") |
@@ -329,9 +332,10 @@ func secretForTunnel(r GenericTunnelReconciler) *corev1.Secret { |
329 | 332 | } |
330 | 333 |
|
331 | 334 | // deploymentForTunnel returns a tunnel Deployment object |
332 | | -func deploymentForTunnel(r GenericTunnelReconciler) *appsv1.Deployment { |
| 335 | +func deploymentForTunnel(r GenericTunnelReconciler, configStr string) *appsv1.Deployment { |
333 | 336 | ls := labelsForTunnel(r.GetTunnel()) |
334 | 337 | protocol := r.GetTunnel().GetSpec().Protocol |
| 338 | + hash := md5.Sum([]byte(configStr)) |
335 | 339 |
|
336 | 340 | args := []string{"tunnel", "--protocol", protocol, "--config", "/etc/cloudflared/config/config.yaml", "--metrics", "0.0.0.0:2000", "run"} |
337 | 341 | volumes := []corev1.Volume{{ |
@@ -398,6 +402,9 @@ func deploymentForTunnel(r GenericTunnelReconciler) *appsv1.Deployment { |
398 | 402 | Template: corev1.PodTemplateSpec{ |
399 | 403 | ObjectMeta: metav1.ObjectMeta{ |
400 | 404 | Labels: ls, |
| 405 | + Annotations: map[string]string{ |
| 406 | + tunnelConfigChecksum: hex.EncodeToString(hash[:]), |
| 407 | + }, |
401 | 408 | }, |
402 | 409 | Spec: corev1.PodSpec{ |
403 | 410 | SecurityContext: &corev1.PodSecurityContext{ |
|
0 commit comments