Skip to content

Commit d746325

Browse files
committed
fix
1 parent cd06933 commit d746325

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

internal/controller/generic_tunnel_reconciler.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controller
22

33
import (
4+
"crypto/md5"
5+
"encoding/hex"
46
"errors"
57
"fmt"
68
"time"
@@ -250,12 +252,13 @@ func createManagedResources(r GenericTunnelReconciler) (ctrl.Result, error) {
250252
}
251253

252254
// 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 {
254257
return ctrl.Result{}, err
255258
}
256259

257260
// Apply patch to deployment
258-
dep := deploymentForTunnel(r)
261+
dep := deploymentForTunnel(r, cm.Data[configmapKey])
259262
if err := k8s.StrategicPatch(dep, r.GetTunnel().GetSpec().DeployPatch, dep); err != nil {
260263
r.GetLog().Error(err, "unable to patch deployment, check patch")
261264
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 {
329332
}
330333

331334
// deploymentForTunnel returns a tunnel Deployment object
332-
func deploymentForTunnel(r GenericTunnelReconciler) *appsv1.Deployment {
335+
func deploymentForTunnel(r GenericTunnelReconciler, configStr string) *appsv1.Deployment {
333336
ls := labelsForTunnel(r.GetTunnel())
334337
protocol := r.GetTunnel().GetSpec().Protocol
338+
hash := md5.Sum([]byte(configStr))
335339

336340
args := []string{"tunnel", "--protocol", protocol, "--config", "/etc/cloudflared/config/config.yaml", "--metrics", "0.0.0.0:2000", "run"}
337341
volumes := []corev1.Volume{{
@@ -398,6 +402,9 @@ func deploymentForTunnel(r GenericTunnelReconciler) *appsv1.Deployment {
398402
Template: corev1.PodTemplateSpec{
399403
ObjectMeta: metav1.ObjectMeta{
400404
Labels: ls,
405+
Annotations: map[string]string{
406+
tunnelConfigChecksum: hex.EncodeToString(hash[:]),
407+
},
401408
},
402409
Spec: corev1.PodSpec{
403410
SecurityContext: &corev1.PodSecurityContext{

internal/controller/tunnelbinding_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,10 @@ func (r *TunnelBindingReconciler) setConfigMapConfiguration(config *cf.Configura
535535
// Restart pods
536536
r.Recorder.Event(r.binding, corev1.EventTypeNormal, "ApplyingConfig", "Applying ConfigMap to Deployment")
537537
r.Recorder.Event(cfDeployment, corev1.EventTypeNormal, "ApplyingConfig", "Applying ConfigMap to Deployment")
538-
if cfDeployment.Annotations == nil {
539-
cfDeployment.Annotations = map[string]string{}
538+
if cfDeployment.Spec.Template.Annotations == nil {
539+
cfDeployment.Spec.Template.Annotations = map[string]string{}
540540
}
541-
cfDeployment.Annotations[tunnelConfigChecksum] = hex.EncodeToString(hash[:])
541+
cfDeployment.Spec.Template.Annotations[tunnelConfigChecksum] = hex.EncodeToString(hash[:])
542542
if err := r.Update(r.ctx, cfDeployment); err != nil {
543543
r.log.Error(err, "Failed to update Deployment for restart")
544544
r.Recorder.Event(r.binding, corev1.EventTypeWarning, "FailedApplyingConfig", "Failed to apply ConfigMap to Deployment")

0 commit comments

Comments
 (0)