Skip to content

Commit

Permalink
cmd/start: Add podman template
Browse files Browse the repository at this point in the history
This patch adds podman template to show users when run crc with podman
config. As of now podman template in used in case cluster configuration
doesn't have the cacert.
  • Loading branch information
praveenkumar committed Nov 15, 2021
1 parent 034eb37 commit 5e5edba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
31 changes: 26 additions & 5 deletions cmd/crc/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ func downloadLink(release *crcversion.CrcReleaseInfo) string {
return constants.CrcLandingPageURL
}

const startTemplate = `Started the OpenShift cluster.
const (
startTemplateForOpenshift = `Started the OpenShift cluster.
The server is accessible via web console at:
{{ .ClusterConfig.WebConsoleURL }}
Expand All @@ -243,6 +244,12 @@ Use the 'oc' command line interface:
{{ .CommandLinePrefix }} {{ .EvalCommandLine }}
{{ .CommandLinePrefix }} oc login -u {{ .ClusterConfig.DeveloperCredentials.Username }} {{ .ClusterConfig.URL }}
`
startTemplateForPodman = `Enabled the podman socket.
Use the 'podman' command line interface:
{{ .CommandLinePrefix }} {{ .EvalCommandLine }}
`
)

type templateVariables struct {
ClusterConfig *clusterConfig
Expand All @@ -251,18 +258,32 @@ type templateVariables struct {
}

func writeTemplatedMessage(writer io.Writer, s *startResult) error {
parsed, err := template.New("template").Parse(startTemplate)
parsed, err := template.New("template").Parse(startTemplateForPodman)
if err != nil {
return err
}

// This should be replaced with the config preset once
// we start using preset as part of config.
if s.ClusterConfig.ClusterCACert != "" {
parsed, err = template.New("template").Parse(startTemplateForOpenshift)
if err != nil {
return err
}
}
userShell, err := shell.GetShell("")
if err != nil {
userShell = ""
}

if s.ClusterConfig.ClusterCACert != "" {
return parsed.Execute(writer, &templateVariables{
ClusterConfig: s.ClusterConfig,
EvalCommandLine: shell.GenerateUsageHint(userShell, "crc oc-env"),
CommandLinePrefix: commandLinePrefix(userShell),
})
}
return parsed.Execute(writer, &templateVariables{
ClusterConfig: s.ClusterConfig,
EvalCommandLine: shell.GenerateUsageHint(userShell, "crc oc-env"),
EvalCommandLine: shell.GenerateUsageHint(userShell, "crc podman-env"),
CommandLinePrefix: commandLinePrefix(userShell),
})
}
Expand Down
1 change: 1 addition & 0 deletions cmd/crc/cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestRenderActionPlainSuccess(t *testing.T) {
assert.NoError(t, render(&startResult{
Success: true,
ClusterConfig: &clusterConfig{
ClusterCACert: "HKMLDJAJDV",
WebConsoleURL: defaultWebConsoleURL,
URL: defaultAPIURL,
AdminCredentials: credentials{
Expand Down
4 changes: 2 additions & 2 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
if crcBundleMetadata.IsOpenShift() {
logging.Infof("Creating CodeReady Containers VM for OpenShift %s...", crcBundleMetadata.GetOpenshiftVersion())
} else {
logging.Info("Creating CodeReady Containers VM for Podman")
logging.Infof("Creating CodeReady Containers VM for Podman %s...", crcBundleMetadata.GetPodmanVersion())
}

machineConfig := config.MachineConfig{
Expand Down Expand Up @@ -219,7 +219,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
}
if vmState == libmachinestate.Running {
if !crcBundleMetadata.IsOpenShift() {
logging.Info("A CodeReady Containers VM for Podman is already running")
logging.Infof("A CodeReady Containers VM for Podman %s is already running", crcBundleMetadata.GetPodmanVersion())
return &types.StartResult{
Status: state.FromMachine(vmState),
}, nil
Expand Down

0 comments on commit 5e5edba

Please sign in to comment.