Skip to content

Commit

Permalink
Refactore kubeconfig handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dschniepp committed May 13, 2020
1 parent 10fc505 commit 8f04987
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
12 changes: 2 additions & 10 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import (
"time"

"gopkg.in/yaml.v3"

// Register Auth providers
_ "k8s.io/client-go/plugin/pkg/client/auth"
)

var kubeConfig string

type Config struct {
SealingRuleSets []SealingRuleSet `yaml:"sealingRules"`
}
Expand Down Expand Up @@ -43,9 +38,6 @@ func ExampleConfig() Config {
}
}

func LoadConfig(file []byte, kubeConfig string) (Config, error) {
kubeConfig = kubeConfig
var config Config
err := yaml.Unmarshal(file, &config)
return config, err
func LoadConfig(file []byte) (config Config, err error) {
return config, yaml.Unmarshal(file, &config)
}
2 changes: 1 addition & 1 deletion internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sealingRules:
`)

func TestLoadConfig(t *testing.T) {
config, _ := LoadConfig(basicConfig, "~/.kube/config")
config, _ := LoadConfig(basicConfig)

maxAge := config.SealingRuleSets[0].Cert.MaxAge
duration, _ := time.ParseDuration("720h")
Expand Down
2 changes: 2 additions & 0 deletions internal/sealing_rule_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
)

var kubeConfig string

type certSource interface {
fetch() (io.ReadCloser, error)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/sealit.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ func Template(sealedSecretPath string) (err error) {
}

func New(sealitconfig string, kubeconfig string, fetchCert bool) (*Sealit, error) {
kubeConfig = kubeconfig
log.Printf("[DEBUG] Load config file %s", sealitconfig)
configFile, err := ioutil.ReadFile(sealitconfig)

if err != nil {
return nil, err
}

config, err := LoadConfig(configFile, kubeconfig)
config, err := LoadConfig(configFile)

if err != nil {
return nil, err
Expand Down

0 comments on commit 8f04987

Please sign in to comment.