diff --git a/internal/controller/automq_controller.go b/internal/controller/automq_controller.go index 784cae3..5469cc9 100644 --- a/internal/controller/automq_controller.go +++ b/internal/controller/automq_controller.go @@ -20,10 +20,13 @@ import ( "context" "errors" "fmt" + "time" + infrav1beta1 "github.com/cuisongliu/automq-operator/api/v1beta1" "github.com/cuisongliu/automq-operator/defaults" "github.com/cuisongliu/automq-operator/internal/pkg/storage" "github.com/labring/operator-sdk/controller" + "github.com/labring/operator-sdk/hash" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -37,7 +40,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "time" ) // AutoMQReconciler reconciles a AutoMQ object @@ -49,6 +51,8 @@ type AutoMQReconciler struct { MountTZ bool } +type ctxKey string + // finalizeSetting will perform the required operations before delete the CR. func (r *AutoMQReconciler) doFinalizerOperationsForSetting(ctx context.Context, automq *infrav1beta1.AutoMQ) error { return r.cleanup(ctx, automq) @@ -229,6 +233,7 @@ func (r *AutoMQReconciler) scriptConfigmap(ctx context.Context, obj *infrav1beta }) return ctx } + ctx = context.WithValue(ctx, ctxKey("hash-configmap"), hash.Hash(data)) if err = retry.RetryOnConflict(retry.DefaultRetry, func() error { var change controllerutil.OperationResult var e error diff --git a/internal/controller/automq_controller_c.go b/internal/controller/automq_controller_c.go index 0454372..ada602c 100644 --- a/internal/controller/automq_controller_c.go +++ b/internal/controller/automq_controller_c.go @@ -19,6 +19,9 @@ package controller import ( "context" "fmt" + "strconv" + "strings" + "github.com/aws/aws-sdk-go-v2/aws" infrav1beta1 "github.com/cuisongliu/automq-operator/api/v1beta1" "github.com/cuisongliu/automq-operator/defaults" @@ -30,8 +33,6 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/util/retry" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "strconv" - "strings" ) const ( @@ -298,16 +299,22 @@ func (r *AutoMQReconciler) syncControllerSTS(ctx context.Context, obj *infrav1be ImagePullPolicy: v1.PullIfNotPresent, }, } + hash, ok := ctx.Value(ctxKey("hash-configmap")).(string) + if !ok { + hash = "" + } + sts.Spec.Template.Annotations = map[string]string{ + "configmap/script-hash": hash, + } + if obj.Spec.Metrics.Enable { sts.Spec.Template.Spec.Containers[0].Env = append(sts.Spec.Template.Spec.Containers[0].Env, v1.EnvVar{ Name: "KAFKA_S3_TELEMETRY_METRICS_EXPORTER_URI", Value: "prometheus://?host=127.0.0.1&port=9090", }) - sts.Spec.Template.Annotations = map[string]string{ - "prometheus.io/path": "/metrics", - "prometheus.io/port": "9090", - "prometheus.io/scrape": "true", - } + sts.Spec.Template.Annotations["prometheus.io/scrape"] = "true" + sts.Spec.Template.Annotations["prometheus.io/port"] = "9090" + sts.Spec.Template.Annotations["prometheus.io/path"] = "/metrics" } if r.MountTZ { sts.Spec.Template.Spec.Volumes = append(sts.Spec.Template.Spec.Volumes, v1.Volume{ diff --git a/internal/controller/automq_status_controller.go b/internal/controller/automq_status_controller.go index 839ca78..5073b6b 100644 --- a/internal/controller/automq_status_controller.go +++ b/internal/controller/automq_status_controller.go @@ -18,6 +18,7 @@ package controller import ( "context" + infrav1beta1 "github.com/cuisongliu/automq-operator/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" diff --git a/internal/controller/init_contrainer.go b/internal/controller/init_contrainer.go index 09c1400..bea5847 100644 --- a/internal/controller/init_contrainer.go +++ b/internal/controller/init_contrainer.go @@ -17,10 +17,11 @@ limitations under the License. package controller import ( + "strings" + "github.com/cuisongliu/automq-operator/defaults" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - "strings" ) func sysctlContainer() v1.Container {