Skip to content

Commit

Permalink
Add back deprecated flag logic
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Lamarre <[email protected]>
  • Loading branch information
alexandreLamarre committed Jan 15, 2025
1 parent f313157 commit ec2aadc
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions cmd/prometheus-federator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import (
"log"
"net/http"
_ "net/http/pprof"
"os"

"github.com/rancher/prometheus-federator/internal/hack"
command "github.com/rancher/prometheus-federator/internal/helm-project-operator/pkg/cli"
"github.com/rancher/prometheus-federator/internal/helm-project-operator/pkg/controllers/common"
"github.com/rancher/prometheus-federator/internal/helm-project-operator/pkg/operator"
"github.com/rancher/prometheus-federator/pkg/chart"
"github.com/rancher/prometheus-federator/pkg/debug"
"github.com/rancher/prometheus-federator/pkg/version"
"github.com/rancher/wrangler/v3/pkg/crd"
_ "github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io"
_ "github.com/rancher/wrangler/v3/pkg/generated/controllers/networking.k8s.io"
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -32,7 +36,6 @@ var (
SystemNamespaces = []string{"kube-system", "cattle-monitoring-system", "cattle-dashboards"}

debugConfig command.DebugConfig
updateCRDs = false
)

type PrometheusFederator struct {
Expand All @@ -57,7 +60,42 @@ func (f *PrometheusFederator) Run(cmd *cobra.Command, _ []string) error {

ctx := cmd.Context()

managedCRDs := common.ManagedCRDsFromRuntime(f.RuntimeOptions)
// Note : for SURE-8872 we introduced some new flags, we keep the logic to handle them here,
// but end-users experiencing the same issues will be unaffected without using these values

// FIXME: the detect block logic is deprecated and will be removed in a later version, since the fix is available
// without changing values

// start:detect
update := os.Getenv("MANAGE_CRD_UPDATES") == "true"
autoDetect := os.Getenv("DETECT_K3S_RKE2") == "true"
clientConfig, err := cfg.ClientConfig()
if err != nil {
logrus.Fatalf("Failed to get client config from runtime : %s", err)
}
var managedCrds []crd.CRD
if autoDetect {
k8sRuntimeType, err := hack.IdentifyKubernetesRuntimeType(clientConfig)
if err != nil {
logrus.Fatalf("Failed to dynamically identify kuberntes runtime : %s", err)
}
onK3sRke2 := k8sRuntimeType == "k3s" || k8sRuntimeType == "rke2"
if onK3sRke2 {
logrus.Debug("the cluster is running on k3s (or rke2), `helm-controller` CRDs will not be managed by `prometheus-federator`")
managedCrds = common.ManagedCRDsFromRuntime(common.RuntimeOptions{
DisableEmbeddedHelmController: true,
})
} else {
managedCrds = common.ManagedCRDsFromRuntime(f.RuntimeOptions)
}
} else if !update {
managedCrds = common.ManagedCRDsFromRuntime(common.RuntimeOptions{
DisableEmbeddedHelmController: true,
})
// end: detect
} else {
managedCrds = common.ManagedCRDsFromRuntime(f.RuntimeOptions)
}

if err := operator.Init(ctx, f.Namespace, cfg, common.Options{
OperatorOptions: common.OperatorOptions{
Expand All @@ -69,7 +107,7 @@ func (f *PrometheusFederator) Run(cmd *cobra.Command, _ []string) error {
},
RuntimeOptions: f.RuntimeOptions,
},
managedCRDs,
managedCrds,
); err != nil {
return err
}
Expand Down

0 comments on commit ec2aadc

Please sign in to comment.