Skip to content

Commit

Permalink
Merge pull request #82 from hyperspike/fix-ver-detect
Browse files Browse the repository at this point in the history
fix version detection
  • Loading branch information
dmolik authored Oct 3, 2024
2 parents 81566ec + 3172b2e commit 812ce61
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ linters:
enable:
- dupl
- errcheck
- exportloopref
- copyloopvar
- ginkgolinter
- goconst
- gocyclo
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test-e2e:

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT) run
$Q$(GOLANGCI_LINT) run

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
Expand Down
4 changes: 2 additions & 2 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type Config struct {

func Defaults() *Config {
return &Config{
ExporterImage: "docker.io/bitnami/redis-exporter:1.62.0-debian-12-r2",
ValkeyImage: "docker.io/bitnami/valkey-cluster:7.2.6-debian-12-r0",
ExporterImage: "docker.io/bitnami/redis-exporter:1.63.0-debian-12-r0",
ValkeyImage: "docker.io/bitnami/valkey-cluster:8.0.0-debian-12-r0",
Nodes: 3,
}
}
33 changes: 29 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import (
"flag"
"os"
"strconv"
"strings"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -63,6 +65,15 @@ func init() {
// +kubebuilder:scaffold:scheme
}

func getOperatorNamespace() (string, error) {
nsBytes, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
if err != nil {
return "", err
}
ns := strings.TrimSpace(string(nsBytes))
return ns, nil
}

func main() {
var metricsAddr string
var enableLeaderElection bool
Expand Down Expand Up @@ -138,7 +149,7 @@ func main() {
}

ctx := ctrl.SetupSignalHandler()
k8sClient := mgr.GetClient()
// k8sClient :=
instanceName := os.Getenv("INSTANCE_NAME")
if instanceName == "" {
instanceName = os.Getenv("APP_NAME")
Expand All @@ -152,8 +163,22 @@ func main() {
Name: cmName,
},
}
if err := k8sClient.Get(ctx, types.NamespacedName{Name: cmName}, cfgMap); err != nil {
setupLog.Error(err, "failed to get", "configmap", cmName)
k8sCfg, err := rest.InClusterConfig()
if err != nil {
setupLog.Error(err, "failed to get in-cluster config")
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(k8sCfg)
if err != nil {
setupLog.Error(err, "failed to get in-cluster config")
}
ns, err := getOperatorNamespace()
if err != nil {
setupLog.Error(err, "failed to get namespace")
}
cfgMap, err = clientset.CoreV1().ConfigMaps(ns).Get(ctx, cmName, metav1.GetOptions{})
if err != nil {
setupLog.Error(err, "failed to get global config")
}
config := cfg.Defaults()
for k, v := range cfgMap.Data {
Expand Down

0 comments on commit 812ce61

Please sign in to comment.