Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(main): add hash from configmap #32

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/controller/automq_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions internal/controller/automq_controller_c.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions internal/controller/automq_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/init_contrainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down