Skip to content

Commit

Permalink
feat(vault): Install a system vault when using --vault or --gitops
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Arch committed Nov 19, 2018
1 parent c0b5dc9 commit a9e64dc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pkg/gits/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ func TestCreateGitProviderFromURL(t *testing.T) {
ApiToken: tc.apiToken,
}
server = createAuthServer(tc.hostURL, tc.Name, tc.providerKind, currUser, users...)
*authSvc, err = auth.NewFileBasedAuthConfigService(configFile.Name())
s, err := auth.NewFileBasedAuthConfigService(configFile.Name())
authSvc = &s
assert.NoError(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/jx/cmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (f *factory) CreateComplianceClient() (*client.SonobuoyClient, error) {
return client.NewSonobuoyClient(config, skc)
}

// CreateVaultOpeatorClient creates a new vault operator client
// CreateVaultOperatorClient creates a new vault operator client
func (f *factory) CreateVaultOperatorClient() (vaultoperatorclient.Interface, error) {
config, err := f.CreateKubeConfig()
if err != nil {
Expand Down
31 changes: 29 additions & 2 deletions pkg/jx/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/Pallinder/go-randomdata"
"github.com/jenkins-x/jx/pkg/apis/jenkins.io"
"github.com/jenkins-x/jx/pkg/vault"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -679,14 +680,40 @@ func (options *InstallOptions) Run() error {
}

// Create a new System vault
// TODO
cvo := &CreateVaultOptions{
CreateOptions: CreateOptions{
CommonOptions: options.CommonOptions,
},
UpgradeIngressOptions: UpgradeIngressOptions{
CreateOptions: CreateOptions{
CommonOptions: options.CommonOptions,
},
},
Namespace: ns,
}
vaultOperatorClient, err := cvo.Factory.CreateVaultOperatorClient()
if err != nil {
return err
}

if vault.FindVault(vaultOperatorClient, vault.SystemVaultName, ns) {
log.Infof("System vault named %s in namespace %s already exists\n",
util.ColorInfo(vault.SystemVaultName), util.ColorInfo(ns))
} else {
log.Info("Creating new system vault\n")
err = cvo.DoCreateVault(vaultOperatorClient, vault.SystemVaultName)
if err != nil {
return err
}
log.Infof("System vault created named %s in namespace %s.\n",
util.ColorInfo(vault.SystemVaultName), util.ColorInfo(ns))
}
options.Factory.UseVault(true)
}

// get secrets to use in helm install
secrets, err := options.getGitSecrets()
if err != nil {

return errors.Wrap(err, "failed to read the git secrets from configuration")
}

Expand Down
18 changes: 11 additions & 7 deletions pkg/util/structs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package util

import (
"gopkg.in/yaml.v2"
"encoding/json"
"strconv"

"github.com/fatih/structs"
Expand Down Expand Up @@ -46,22 +46,26 @@ func ToStringMapStringFromStruct(obj interface{}) map[string]string {
return config
}

// ToMapStringInterfaceFromStruct marshals a struct to a generic map[string]interface{} by marshalling it to yaml and back
// ToMapStringInterfaceFromStruct marshals a struct to a generic map[string]interface{} by marshalling it to json and back
// Use JSON for the marshalling instead of YAML because sub-structs will get marshalled into map[interface{}]interface{}
// when using YAML, but map[string]interface{} when using JSON and vault libraries can't handle map[interface{}]interface{}
func ToMapStringInterfaceFromStruct(obj interface{}) (map[string]interface{}, error) {
y, err := yaml.Marshal(&obj)
y, err := json.Marshal(&obj)
if err != nil {
return nil, err
}
out := make(map[string]interface{})
err = yaml.Unmarshal(y, &out)
err = json.Unmarshal(y, &out)
return out, err
}

// ToStructFromMapStringInterface marshals a generic map[string]interface{} to a struct by marshalling to yaml and back
// ToStructFromMapStringInterface marshals a generic map[string]interface{} to a struct by marshalling to json and back
// Use JSON for the marshalling instead of YAML because sub-structs will get marshalled into map[interface{}]interface{}
// when using YAML, but map[string]interface{} when using JSON and vault libraries can't handle map[interface{}]interface{}
func ToStructFromMapStringInterface(m map[string]interface{}, str interface{}) error {
j, err := yaml.Marshal(m)
j, err := json.Marshal(m)
if err != nil {
return err
}
return yaml.Unmarshal(j, str)
return json.Unmarshal(j, str)
}

0 comments on commit a9e64dc

Please sign in to comment.