Skip to content

Commit

Permalink
address observations, merge files, add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed Dec 3, 2024
1 parent fe1cfc7 commit 02466ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
30 changes: 0 additions & 30 deletions cmd/root/config.go

This file was deleted.

21 changes: 21 additions & 0 deletions cmd/root/options.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
package root

import (
"errors"
"fmt"
"net/http"
"net/http/pprof"
"os"
"path/filepath"
"reflect"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"

configv1alpha1 "github.com/grafana/tempo-operator/api/config/v1alpha1"
)

var errConfigFileLoading = errors.New("could not read file at path")

func loadConfigFile(scheme *runtime.Scheme, outConfig *configv1alpha1.ProjectConfig, configFile string) error {
content, err := os.ReadFile(filepath.Clean(configFile))
if err != nil {
return fmt.Errorf("%w %s", errConfigFileLoading, configFile)
}

codecs := serializer.NewCodecFactory(scheme)

if err = runtime.DecodeInto(codecs.UniversalDecoder(), content, outConfig); err != nil {
return fmt.Errorf("could not decode file into runtime.Object: %w", err)
}

return nil
}

// LoadConfig initializes the controller configuration, optionally overriding the defaults
// from a provided configuration file.
func LoadConfig(scheme *runtime.Scheme, configFile string) (*configv1alpha1.ProjectConfig, ctrl.Options, error) {
Expand Down
3 changes: 0 additions & 3 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package root

import (
"context"

grafanav1 "github.com/grafana/grafana-operator/v5/api/v1beta1"
configv1 "github.com/openshift/api/config/v1"
openshiftoperatorv1 "github.com/openshift/api/operator/v1"
Expand Down Expand Up @@ -44,8 +43,6 @@ func init() {
//+kubebuilder:scaffold:scheme
}

//var errConfigFileLoading = errors.New("could not read file at path")

func readConfig(cmd *cobra.Command, configFile string) error {
// default controller configuration
ctrlCfg, options, err := LoadConfig(scheme, configFile)
Expand Down

0 comments on commit 02466ad

Please sign in to comment.