Skip to content

Commit

Permalink
Issue minishift#2482 Add minishift ssh user to addon default context
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumar committed Jun 21, 2018
1 parent 42ade6d commit 8ff2afa
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion addons/registry-route/registry-route.addon
Expand Up @@ -5,7 +5,7 @@ openshift adm ca create-server-cert --signer-cert=/var/lib/origin/openshift.loca
openshift create route edge docker-registry --service=docker-registry --ca-cert=/var/lib/origin/openshift.local.config/master/ca.crt --cert=/etc/secrets/registry.crt --key=/etc/secrets/registry.key --hostname='docker-registry-default.#{routing-suffix}' --config=/var/lib/origin/openshift.local.config/master/admin.kubeconfig

ssh sudo mkdir -p /etc/docker/certs.d/docker-registry-default.#{routing-suffix}
ssh sudo chown docker /etc/docker/certs.d/docker-registry-default.#{routing-suffix}
ssh sudo chown #{user} /etc/docker/certs.d/docker-registry-default.#{routing-suffix}

docker cp origin:/var/lib/origin/openshift.local.config/master/ca.crt /etc/docker/certs.d/docker-registry-default.#{routing-suffix}/ca.crt

Expand Down
3 changes: 2 additions & 1 deletion cmd/minishift/cmd/addon/addon_apply.go
Expand Up @@ -78,6 +78,7 @@ func runApplyAddon(cmd *cobra.Command, args []string) {

routingSuffix := determineRoutingSuffix(host.Driver)
sshCommander := provision.GenericSSHCommander{Driver: host.Driver}
sshUser := sshCommander.Driver.GetSSHUsername()
ocRunner, err := oc.NewOcRunner(minishiftConfig.InstanceConfig.OcPath, constants.KubeConfigPath)
if err != nil {
atexit.ExitWithMessage(1, fmt.Sprintf("Error applying the add-on: %s", err.Error()))
Expand All @@ -86,7 +87,7 @@ func runApplyAddon(cmd *cobra.Command, args []string) {
for i := range args {
addonName := args[i]
addon := addOnManager.Get(addonName)
addonContext, err := clusterup.GetExecutionContext(ip, routingSuffix, viper.GetStringSlice(util.AddOnEnv), ocRunner, sshCommander)
addonContext, err := clusterup.GetExecutionContext(ip, routingSuffix, sshUser, viper.GetStringSlice(util.AddOnEnv), ocRunner, sshCommander)
if err != nil {
atexit.ExitWithMessage(1, fmt.Sprint("Error applying the add-on: ", err))
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/minishift/cmd/addon/addon_remove.go
Expand Up @@ -81,6 +81,7 @@ func runRemoveAddon(cmd *cobra.Command, args []string) {

routingSuffix := determineRoutingSuffix(host.Driver)
sshCommander := provision.GenericSSHCommander{Driver: host.Driver}
sshUser := sshCommander.Driver.GetSSHUsername()
ocRunner, err := oc.NewOcRunner(minishiftConfig.InstanceConfig.OcPath, constants.KubeConfigPath)
if err != nil {
atexit.ExitWithMessage(1, fmt.Sprintf("Error removing the add-on: %s", err.Error()))
Expand All @@ -89,7 +90,7 @@ func runRemoveAddon(cmd *cobra.Command, args []string) {
for i := range args {
addonName := args[i]
addon := addOnManager.Get(addonName)
addonContext, err := clusterup.GetExecutionContext(ip, routingSuffix, viper.GetStringSlice(util.AddOnEnv), ocRunner, sshCommander)
addonContext, err := clusterup.GetExecutionContext(ip, routingSuffix, sshUser, viper.GetStringSlice(util.AddOnEnv), ocRunner, sshCommander)
if err != nil {
atexit.ExitWithMessage(1, fmt.Sprint("Error removing the add-on: ", err))
}
Expand Down
1 change: 1 addition & 0 deletions cmd/minishift/cmd/start.go
Expand Up @@ -237,6 +237,7 @@ func runStart(cmd *cobra.Command, args []string) {
PublicHostname: configCmd.GetDefaultPublicHostName(ip),
SSHCommander: sshCommander,
OcBinaryPathInsideVM: fmt.Sprintf("%s/oc", minishiftConstants.OcPathInsideVM),
SshUser: sshCommander.Driver.GetSSHUsername(),
}

clusterUpParams := determineClusterUpParameters(clusterUpConfig)
Expand Down
3 changes: 3 additions & 0 deletions docs/source/using/addons.adoc
Expand Up @@ -160,6 +160,9 @@ The following table shows these variables.

|addon-name
|Name of the current add-on.

|user
|Name of {project} ssh user
|===

[[addon-dynamic-variables]]
Expand Down
11 changes: 7 additions & 4 deletions pkg/minishift/clusterup/clusterup.go
Expand Up @@ -47,6 +47,7 @@ import (
const (
ipKey = "ip"
routingSuffixKey = "routing-suffix"
user = "user"
envPrefix = "env."
)

Expand All @@ -64,6 +65,7 @@ type ClusterUpConfig struct {
PublicHostname string
SSHCommander provision.SSHCommander
OcBinaryPathInsideVM string
SshUser string
}

// ClusterUp execute oc binary in order to run 'cluster up'
Expand Down Expand Up @@ -130,7 +132,7 @@ func PostClusterUp(clusterUpConfig *ClusterUpConfig, sshCommander provision.SSHC
return err
}

err = applyAddOns(addOnManager, clusterUpConfig.Ip, clusterUpConfig.RoutingSuffix, clusterUpConfig.AddonEnv, ocRunner, sshCommander)
err = applyAddOns(addOnManager, clusterUpConfig.Ip, clusterUpConfig.RoutingSuffix, clusterUpConfig.SshUser, clusterUpConfig.AddonEnv, ocRunner, sshCommander)
if err != nil {
return err
}
Expand All @@ -150,14 +152,15 @@ func EnsureHostDirectoriesExist(host *host.Host, dirs []string) error {

// GetExecutionContext creates an ExecutionContext used for variable interpolation during add-on application.
// The context contains variables to interpolate during add-on execution, as well as the means to communicate with the VM (SSHCommander) and OpenShift (OcRunner).
func GetExecutionContext(ip string, routingSuffix string, addOnEnv []string, ocRunner *oc.OcRunner, sshCommander provision.SSHCommander) (*command.ExecutionContext, error) {
func GetExecutionContext(ip string, routingSuffix string, sshUser string, addOnEnv []string, ocRunner *oc.OcRunner, sshCommander provision.SSHCommander) (*command.ExecutionContext, error) {
context, err := command.NewExecutionContext(ocRunner, sshCommander)
if err != nil {
return nil, errors.New(fmt.Sprintf("Unable to initialise execution context: %s", err.Error()))
}

context.AddToContext(ipKey, ip)
context.AddToContext(routingSuffixKey, routingSuffix)
context.AddToContext(user, sshUser)

for _, env := range addOnEnv {
match, _ := regexp.Match(".*=.*", []byte(env))
Expand Down Expand Up @@ -201,8 +204,8 @@ func CopyOcBinaryFromImageToVM(dockerCommander docker.DockerCommander, image str
return nil
}

func applyAddOns(addOnManager *manager.AddOnManager, ip string, routingSuffix string, addonEnv []string, ocRunner *oc.OcRunner, sshCommander provision.SSHCommander) error {
context, err := GetExecutionContext(ip, routingSuffix, addonEnv, ocRunner, sshCommander)
func applyAddOns(addOnManager *manager.AddOnManager, ip string, routingSuffix string, sshUser string, addonEnv []string, ocRunner *oc.OcRunner, sshCommander provision.SSHCommander) error {
context, err := GetExecutionContext(ip, routingSuffix, sshUser, addonEnv, ocRunner, sshCommander)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/minishift/clusterup/clusterup_test.go
Expand Up @@ -25,7 +25,7 @@ import (
)

func Test_invalid_addon_variable_leads_to_error_in_context_creation(t *testing.T) {
context, err := GetExecutionContext("127.0.0.1", "foo.bar", []string{"FOOBAR"}, nil, nil)
context, err := GetExecutionContext("127.0.0.1", "foo.bar", "foo", []string{"FOOBAR"}, nil, nil)
assert.Error(t, err, "There should have been an error due to incorrect addon env variable.")
assert.Nil(t, context, "There should be no InterpolationContext returned.")
}
Expand All @@ -35,7 +35,7 @@ func Test_addon_variable_can_be_interpolated(t *testing.T) {
}

func Test_nil_can_be_passed_to_create_context(t *testing.T) {
_, err := GetExecutionContext("127.0.0.1", "foo.bar", nil, nil, nil)
_, err := GetExecutionContext("127.0.0.1", "foo.bar", "foo", nil, nil, nil)

assert.NoError(t, err, "Error in getting execution context")
}
Expand All @@ -55,7 +55,7 @@ func Test_addon_variable_can_be_interpolated_from_environment(t *testing.T) {
}

func assertInterpolation(variables []string, testString string, expectedResult string, t *testing.T) {
context, err := GetExecutionContext("127.0.0.1", "foo.bar", variables, nil, nil)
context, err := GetExecutionContext("127.0.0.1", "foo.bar", "foo", variables, nil, nil)
assert.NoError(t, err)

result := context.Interpolate(testString)
Expand Down

0 comments on commit 8ff2afa

Please sign in to comment.