Skip to content

Commit

Permalink
refactor: address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Fajerski <[email protected]>
  • Loading branch information
jan--f committed Jan 18, 2024
1 parent 51d028d commit eb4c6c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
29 changes: 25 additions & 4 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,43 @@ import (
"github.com/rhobs/observability-operator/pkg/operator"
"go.uber.org/zap/zapcore"

obopo "github.com/rhobs/obo-prometheus-operator/pkg/operator"

k8sflag "k8s.io/component-base/cli/flag"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

// The default values we use. Prometheus and Alertmanager are handled by
// prometheus-operator. For thanos we use the default version from
// prometheus-operator.
var defaultImages = map[string]string{
"prometheus": "",
"alertmanager": "",
"thanos": obopo.DefaultThanosImage,
}

func ImagesUsed() []string {
i := 0
imgs := make([]string, len(defaultImages))
for k := range defaultImages {
imgs[i] = k
i++
}
return imgs
}

// validateImages merges the passed images with the defaults and checks if any
// unknown image names are passed. If an unknown image is found, this raises an
// error.
func validateImages(images *k8sflag.MapStringString) (map[string]string, error) {
res := operator.DefaultImages
res := defaultImages
if !images.Empty() {
imgs := *images.Map
for k, v := range imgs {
if _, ok := res[k]; !ok {
return nil, fmt.Errorf(fmt.Sprintf("image %v is unknows", k))
return nil, fmt.Errorf(fmt.Sprintf("image %v is unknown", k))
}
res[k] = v
}
Expand All @@ -54,8 +76,7 @@ func main() {

setupLog = ctrl.Log.WithName("setup")
)
m := make(map[string]string)
images := k8sflag.NewMapStringString(&m)
images := k8sflag.NewMapStringString(ptr.To(make(map[string]string)))

flag.StringVar(&namespace, "namespace", "default", "The namespace in which the operator runs")
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
Expand Down
29 changes: 4 additions & 25 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
stackctrl "github.com/rhobs/observability-operator/pkg/controllers/monitoring/monitoring-stack"
tqctrl "github.com/rhobs/observability-operator/pkg/controllers/monitoring/thanos-querier"

obopo "github.com/rhobs/obo-prometheus-operator/pkg/operator"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"

Expand All @@ -23,25 +21,6 @@ const instanceSelector = "app.kubernetes.io/managed-by=observability-operator"

const ObservabilityOperatorName = "observability-operator"

// The default values we use. Prometheus and Alertmanager are handled by
// prometheus-operator. For thanos we use the default version from
// prometheus-operator.
var DefaultImages = map[string]string{
"prometheus": "",
"alertmanager": "",
"thanos": "quay.io/thanos/thanos:" + obopo.DefaultThanosVersion,
}

func ImagesUsed() []string {
i := 0
imgs := make([]string, len(DefaultImages))
for k := range DefaultImages {
imgs[i] = k
i++
}
return imgs
}

// Operator embedds manager and exposes only the minimal set of functions
type Operator struct {
manager manager.Manager
Expand All @@ -58,25 +37,25 @@ type OperatorConfiguration struct {

func WithPrometheusImage(image string) func(*OperatorConfiguration) {
return func(oc *OperatorConfiguration) {
oc.Prometheus = stackctrl.PrometheusConfiguration{Image: image}
oc.Prometheus.Image = image
}
}

func WithAlertmanagerImage(image string) func(*OperatorConfiguration) {
return func(oc *OperatorConfiguration) {
oc.Alertmanager = stackctrl.AlertmanagerConfiguration{Image: image}
oc.Alertmanager.Image = image
}
}

func WithThanosSidecarImage(image string) func(*OperatorConfiguration) {
return func(oc *OperatorConfiguration) {
oc.ThanosSidecar = stackctrl.ThanosConfiguration{Image: image}
oc.ThanosSidecar.Image = image
}
}

func WithThanosQuerierImage(image string) func(*OperatorConfiguration) {
return func(oc *OperatorConfiguration) {
oc.ThanosQuerier = tqctrl.ThanosConfiguration{Image: image}
oc.ThanosQuerier.Image = image
}
}

Expand Down

0 comments on commit eb4c6c8

Please sign in to comment.