Skip to content

Commit

Permalink
Issue #359 Add context as minishift
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumar authored and hferentschik committed Mar 21, 2017
1 parent de3139f commit 74f5c6c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cmd/minishift/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func runStart(cmd *cobra.Command, args []string) {
glog.Errorln("Error adding developer user to sudoers", err)
atexit.Exit(1)
}
if err := openshift.AddContextForProfile(constants.MachineName, ip, "developer", "myproject"); err != nil {
glog.Errorln("Error adding OpenShift Context", err)
atexit.Exit(1)
}
}

// Set Docker Proxy
Expand Down
11 changes: 11 additions & 0 deletions docs/source/using/interacting-with-openshift.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ In future versions we will provide a command to assist in setting up the
See GitHub issue
https://github.com/minishift/minishift/issues/142[#142].

As part of the `minishift start` command there is also a `minishift`
https://docs.openshift.org/latest/cli_reference/manage_cli_profiles.html[oc context] created.
This context contains the configuration to communicate with your OpenShift cluster.

Minishift activates this context automatcally, but if you need to switch back to it after,
for example logging into another OpenShift instance, you can run:

----
$ oc config use-context minishift
----

For an introduction to `oc` usage, refer to the
https://docs.openshift.com/enterprise/3.2/cli_reference/get_started_cli.html[Get
Started with the CLI]
Expand Down
3 changes: 2 additions & 1 deletion gen_help_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package main

import (
"os"

"github.com/minishift/minishift/cmd/minishift/cmd"
"github.com/spf13/cobra/doc"
"os"
)

func main() {
Expand Down
26 changes: 26 additions & 0 deletions pkg/minishift/openshift/oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ limitations under the License.
package openshift

import (
"fmt"
"strings"

"github.com/minishift/minishift/pkg/minikube/constants"
instanceState "github.com/minishift/minishift/pkg/minishift/config"
"github.com/minishift/minishift/pkg/util"
)
Expand All @@ -42,3 +46,25 @@ func AddSudoersRoleForUser(user string) error {
}
return nil
}

// Add Current Profile Context
func AddContextForProfile(profile string, ip string, username string, namespace string) error {
cmdName := instanceState.Config.OcPath
ip = strings.Replace(ip, ".", "-", -1)
cmdArgs := []string{"config", "set-context", profile,
fmt.Sprintf("--cluster=%s:%d", ip, constants.APIServerPort),
fmt.Sprintf("--user=%s/%s:%d", username, ip, constants.APIServerPort),
fmt.Sprintf("--namespace=%s", namespace),
}

if _, err := runner.Output(cmdName, cmdArgs...); err != nil {
return err
}

cmdArgs = []string{"config", "use-context", profile}

if _, err := runner.Output(cmdName, cmdArgs...); err != nil {
return err
}
return nil
}
43 changes: 41 additions & 2 deletions test/integration/features/basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,51 @@ Feature: Basic
sudoer /sudoer developer
When executing "oc --as system:admin get clusterrolebindings"
Then stderr should be empty
And exitcode should equal 0
And stdout should contain
And exitcode should equal 0
And stdout should contain
"""
sudoer
"""

Scenario: Current Context should be minishift
Check the context is set as per profile
In our case profile is minishift
When executing "oc config current-context"
Then stderr should be empty
And exitcode should equal 0
And stdout should contain
"""
minishift
"""

Scenario: Create a dummy context
When executing "oc config set-context dummy"
Then stderr should be empty
And exitcode should equal 0

Scenario: Switch to dummy context
When executing "oc config use-context dummy"
Then stderr should be empty
And exitcode should equal 0

Scenario: Check project info for dummy context
When executing "oc project -q"
Then exitcode should equal 1

Scenario: Switch context to minishift
When executing "oc config use-context minishift"
Then stderr should be empty
And exitcode should equal 0

Scenario: Check project info for minishift context
When executing "oc project -q"
Then stderr should be empty
And exitcode should equal 0
And stdout should contain
"""
myproject
"""

Scenario: User is able to do ssh into machine via Minishift
Given Minishift has state "Running"
When executing "minishift ssh echo hello"
Expand Down

0 comments on commit 74f5c6c

Please sign in to comment.