Skip to content

Commit

Permalink
Add flag for providing credentials file
Browse files Browse the repository at this point in the history
  • Loading branch information
xmudrii committed Aug 26, 2019
1 parent 5f09061 commit ec54406
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 26 deletions.
6 changes: 4 additions & 2 deletions pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ It's possible to source information about hosts from Terraform output, using the
logger := initLogger(gopts.Verbose)
iopts.TerraformState = gopts.TerraformState
iopts.Verbose = gopts.Verbose
iopts.CredentialsFilePath = gopts.CredentialsFilePath

iopts.Manifest = args[0]
if iopts.Manifest == "" {
Expand Down Expand Up @@ -114,7 +115,8 @@ func createInstallerOptions(clusterFile string, cluster *kubeoneapi.KubeOneClust
defer f.Close()

return &installer.Options{
BackupFile: options.BackupFile,
Verbose: options.Verbose,
CredentialsFile: options.CredentialsFilePath,
BackupFile: options.BackupFile,
Verbose: options.Verbose,
}, nil
}
7 changes: 4 additions & 3 deletions pkg/cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ func runReset(logger *logrus.Logger, resetOptions *resetOptions) error {
}

options := &installer.Options{
Verbose: resetOptions.Verbose,
DestroyWorkers: resetOptions.DestroyWorkers,
RemoveBinaries: resetOptions.RemoveBinaries,
Verbose: resetOptions.Verbose,
CredentialsFile: resetOptions.CredentialsFilePath,
DestroyWorkers: resetOptions.DestroyWorkers,
RemoveBinaries: resetOptions.RemoveBinaries,
}

return installer.NewInstaller(cluster, logger).Reset(options)
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func newRoot() *cobra.Command {

fs.StringVarP(&opts.TerraformState, globalTerraformFlagName, "t", "",
"Source for terrafor output JSON. - to read from stdin. If path is file, contents will be used. If path is dictionary, `terraform output -json` is executed in this path")
fs.StringVarP(&opts.CredentialsFilePath, globalCredentialsFlagName, "c", "", "File to source credentials and secrets from")
fs.BoolVarP(&opts.Verbose, globalVerboseFlagName, "v", false, "verbose")
fs.BoolVarP(&opts.Debug, globalDebugFlagName, "d", false, "debug")

Expand Down
24 changes: 16 additions & 8 deletions pkg/cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ import (
)

const (
globalTerraformFlagName = "tfjson"
globalVerboseFlagName = "verbose"
globalDebugFlagName = "debug"
globalTerraformFlagName = "tfjson"
globalCredentialsFlagName = "credentials"
globalVerboseFlagName = "verbose"
globalDebugFlagName = "debug"
)

// globalOptions are global globalOptions same for all commands
type globalOptions struct {
TerraformState string
Verbose bool
Debug bool
TerraformState string
CredentialsFilePath string
Verbose bool
Debug bool
}

func persistentGlobalOptions(fs *pflag.FlagSet) (*globalOptions, error) {
Expand All @@ -49,9 +51,15 @@ func persistentGlobalOptions(fs *pflag.FlagSet) (*globalOptions, error) {
return nil, errors.WithStack(err)
}

creds, err := fs.GetString(globalCredentialsFlagName)
if err != nil {
return nil, errors.WithStack(err)
}

return &globalOptions{
Verbose: verbose,
TerraformState: tfjson,
Verbose: verbose,
TerraformState: tfjson,
CredentialsFilePath: creds,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func runUpgrade(logger *logrus.Logger, upgradeOptions *upgradeOptions) error {

func createUpgradeOptions(options *upgradeOptions) *upgrader.Options {
return &upgrader.Options{
CredentialsFile: options.CredentialsFilePath,
ForceUpgrade: options.ForceUpgrade,
Verbose: options.Verbose,
UpgradeMachineDeployments: options.UpgradeMachineDeployments,
Expand Down
28 changes: 15 additions & 13 deletions pkg/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import (
// Options groups the various possible options for running
// the Kubernetes installation.
type Options struct {
Verbose bool
BackupFile string
DestroyWorkers bool
RemoveBinaries bool
Verbose bool
CredentialsFile string
BackupFile string
DestroyWorkers bool
RemoveBinaries bool
}

// Installer is entrypoint for installation process
Expand Down Expand Up @@ -68,14 +69,15 @@ func (i *Installer) Reset(options *Options) error {
// structs for each task individually.
func (i *Installer) createState(options *Options) *state.State {
return &state.State{
Cluster: i.cluster,
Connector: ssh.NewConnector(),
Configuration: configupload.NewConfiguration(),
WorkDir: "kubeone",
Logger: i.logger,
Verbose: options.Verbose,
BackupFile: options.BackupFile,
DestroyWorkers: options.DestroyWorkers,
RemoveBinaries: options.RemoveBinaries,
Cluster: i.cluster,
Connector: ssh.NewConnector(),
Configuration: configupload.NewConfiguration(),
WorkDir: "kubeone",
Logger: i.logger,
Verbose: options.Verbose,
CredentialsFilePath: options.CredentialsFile,
BackupFile: options.BackupFile,
DestroyWorkers: options.DestroyWorkers,
RemoveBinaries: options.RemoveBinaries,
}
}
1 change: 1 addition & 0 deletions pkg/state/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type State struct {
ForceUpgrade bool
UpgradeMachineDeployments bool
PatchCNI bool
CredentialsFilePath string
}

// Clone returns a shallow copy of the State.
Expand Down
2 changes: 2 additions & 0 deletions pkg/upgrader/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

// Options groups the various possible options for running KubeOne upgrade
type Options struct {
CredentialsFile string
ForceUpgrade bool
UpgradeMachineDeployments bool
Verbose bool
Expand Down Expand Up @@ -64,5 +65,6 @@ func (u *Upgrader) createState(options *Options) *state.State {
Verbose: options.Verbose,
ForceUpgrade: options.ForceUpgrade,
UpgradeMachineDeployments: options.UpgradeMachineDeployments,
CredentialsFilePath: options.CredentialsFile,
}
}

0 comments on commit ec54406

Please sign in to comment.