Skip to content

Commit

Permalink
Provide a way to run podman service only
Browse files Browse the repository at this point in the history
Without the Openshift cluster.

Fixes crc-org#1097.
  • Loading branch information
zeenix committed Apr 15, 2020
1 parent 87f1453 commit 1ca434d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 32 deletions.
1 change: 1 addition & 0 deletions cmd/crc/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
Memory = cfg.AddSetting("memory", constants.DefaultMemory, []cfg.ValidationFnType{cfg.ValidateMemory}, []cfg.SetFn{cfg.RequiresRestartMsg})
NameServer = cfg.AddSetting("nameserver", nil, []cfg.ValidationFnType{cfg.ValidateIpAddress}, []cfg.SetFn{cfg.SuccessfullyApplied})
PullSecretFile = cfg.AddSetting("pull-secret-file", nil, []cfg.ValidationFnType{cfg.ValidatePath}, []cfg.SetFn{cfg.SuccessfullyApplied})
DisableCluster = cfg.AddSetting("disable-cluster", nil, []cfg.ValidationFnType{cfg.ValidateBool}, []cfg.SetFn{cfg.SuccessfullyApplied})

DisableUpdateCheck = cfg.AddSetting("disable-update-check", nil, []cfg.ValidationFnType{cfg.ValidateBool}, []cfg.SetFn{cfg.SuccessfullyApplied})
ExperimentalFeatures = cfg.AddSetting("enable-experimental-features", nil, []cfg.ValidationFnType{cfg.ValidateBool}, []cfg.SetFn{cfg.SuccessfullyApplied})
Expand Down
24 changes: 15 additions & 9 deletions cmd/crc/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,28 @@ func runStart(arguments []string) {
preflight.StartPreflightChecks()

startConfig := machine.StartConfig{
Name: constants.DefaultName,
BundlePath: crcConfig.GetString(config.Bundle.Name),
Memory: crcConfig.GetInt(config.Memory.Name),
CPUs: crcConfig.GetInt(config.CPUs.Name),
NameServer: crcConfig.GetString(config.NameServer.Name),
GetPullSecret: getPullSecretFileContent,
Debug: isDebugLog(),
Name: constants.DefaultName,
BundlePath: crcConfig.GetString(config.Bundle.Name),
Memory: crcConfig.GetInt(config.Memory.Name),
CPUs: crcConfig.GetInt(config.CPUs.Name),
NameServer: crcConfig.GetString(config.NameServer.Name),
GetPullSecret: getPullSecretFileContent,
Debug: isDebugLog(),
DisableCluster: crcConfig.GetBool(config.DisableCluster.Name),
}

commandResult, err := machine.Start(startConfig)
if err != nil {
errors.Exit(1)
}
if commandResult.Status == "Running" {
output.Outln("Started the OpenShift cluster")
if startConfig.DisableCluster {
output.Outln("Podman service now available")
} else {
output.Outln("Started the OpenShift cluster")

logging.Warn("The cluster might report a degraded or error state. This is expected since several operators have been disabled to lower the resource usage. For more information, please consult the documentation")
logging.Warn("The cluster might report a degraded or error state. This is expected since several operators have been disabled to lower the resource usage. For more information, please consult the documentation")
}
} else {
logging.Warnf("Unexpected status of the OpenShift cluster: %s", commandResult.Status)
}
Expand All @@ -80,6 +85,7 @@ func initStartCmdFlagSet() *pflag.FlagSet {
flagSet.IntP(config.Memory.Name, "m", constants.DefaultMemory, "MiB of memory to allocate to the OpenShift cluster")
flagSet.StringP(config.NameServer.Name, "n", "", "IPv4 address of nameserver to use for the OpenShift cluster")
flagSet.Bool(config.DisableUpdateCheck.Name, false, "Don't check for update")
flagSet.BoolP(config.DisableCluster.Name, "d", false, "Don't start the OpenShift cluster")

return flagSet
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/crc/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var statusCmd = &cobra.Command{

var statusFormat = `CRC VM: {{.CrcStatus}}
OpenShift: {{.OpenShiftStatus}}
Podman: {{.PodmanStatus}}
Disk Usage: {{.DiskUsage}}
Cache Usage: {{.CacheUsage}}
Cache Directory: {{.CacheDir}}
Expand All @@ -36,6 +37,7 @@ Cache Directory: {{.CacheDir}}
type Status struct {
CrcStatus string
OpenShiftStatus string
PodmanStatus string
DiskUsage string
CacheUsage string
CacheDir string
Expand Down Expand Up @@ -65,7 +67,7 @@ func runStatus() {
diskUse := units.HumanSize(float64(clusterStatus.DiskUse))
diskSize := units.HumanSize(float64(clusterStatus.DiskSize))
diskUsage := fmt.Sprintf("%s of %s (Inside the CRC VM)", diskUse, diskSize)
status := Status{clusterStatus.CrcStatus, clusterStatus.OpenshiftStatus, diskUsage, cacheUsage, cacheDir}
status := Status{clusterStatus.CrcStatus, clusterStatus.OpenshiftStatus, clusterStatus.PodmanStatus, diskUsage, cacheUsage, cacheDir}
printStatus(status, statusFormat)
}

Expand Down
66 changes: 44 additions & 22 deletions pkg/crc/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/code-ready/crc/pkg/crc/network"
crcssh "github.com/code-ready/crc/pkg/crc/ssh"
"github.com/code-ready/crc/pkg/crc/systemd"
"github.com/code-ready/crc/pkg/crc/systemd/states"
crcos "github.com/code-ready/crc/pkg/os"

// cluster services
Expand Down Expand Up @@ -355,6 +356,12 @@ func Start(startConfig StartConfig) (StartResult, error) {
}
}

if startConfig.DisableCluster {
logging.Infof("To access the podman service, first set up your environment by following 'crc podman-env' instructions")

return *result, nil
}

if needsCertsRenewal {
logging.Infof("Cluster TLS certificates have expired, renewing them... [will take up to 5 minutes]")
err = RegenerateCertificates(sshRunner, startConfig.Name)
Expand Down Expand Up @@ -553,6 +560,7 @@ func Status(statusConfig ClusterStatusConfig) (ClusterStatusResult, error) {
defer libMachineAPIClient.Close()

openshiftStatus := "Stopped"
podmanStatus := "Running"
var diskUse int64
var diskSize int64

Expand Down Expand Up @@ -582,37 +590,51 @@ func Status(statusConfig ClusterStatusConfig) (ClusterStatusResult, error) {
}
proxyConfig.ApplyToEnvironment()

// check if all the clusteroperators are running
ocConfig := oc.UseOCWithConfig(statusConfig.Name)
operatorsStatus, err := oc.GetClusterOperatorStatus(ocConfig)
sshRunner := crcssh.CreateRunner(host.Driver)
if err = cluster.WaitForSsh(sshRunner); err != nil {
return *result, errors.Newf("Error waiting for SSH serivce: %v", err)
}

sd := systemd.NewInstanceSystemdCommander(sshRunner)
status, err := sd.Status("kubelet")
if err != nil {
result.Success = false
result.Error = err.Error()
return *result, errors.New(err.Error())
return *result, errors.Newf("Error fetching status of kubelet service: %v", err.Error())
}
if operatorsStatus.Available {
openshiftVersion := "4.x"
_, crcBundleMetadata, err := getBundleMetadataFromDriver(host.Driver)
if states.Compare(status) == states.Running {
// check if all the clusteroperators are running
ocConfig := oc.UseOCWithConfig(statusConfig.Name)
operatorsStatus, err := oc.GetClusterOperatorStatus(ocConfig)
if err != nil {
logging.Debugf("Failed to load bundle metadata: %s", err.Error())
} else if crcBundleMetadata.GetOpenshiftVersion() != "" {
openshiftVersion = crcBundleMetadata.GetOpenshiftVersion()
result.Success = false
result.Error = err.Error()
return *result, errors.New(err.Error())
}
if operatorsStatus.Available {
openshiftVersion := "4.x"
_, crcBundleMetadata, err := getBundleMetadataFromDriver(host.Driver)
if err != nil {
logging.Debugf("Failed to load bundle metadata: %s", err.Error())
} else if crcBundleMetadata.GetOpenshiftVersion() != "" {
openshiftVersion = crcBundleMetadata.GetOpenshiftVersion()
}
openshiftStatus = fmt.Sprintf("Running (v%s)", openshiftVersion)
} else if operatorsStatus.Degraded {
openshiftStatus = fmt.Sprintf("Degraded")
} else if operatorsStatus.Progressing {
openshiftStatus = fmt.Sprintf("Starting")
}
diskSize, diskUse, err = cluster.GetRootPartitionUsage(sshRunner)
if err != nil {
result.Success = false
result.Error = err.Error()
return *result, errors.New(err.Error())
}
openshiftStatus = fmt.Sprintf("Running (v%s)", openshiftVersion)
} else if operatorsStatus.Degraded {
openshiftStatus = fmt.Sprintf("Degraded")
} else if operatorsStatus.Progressing {
openshiftStatus = fmt.Sprintf("Starting")
}
sshRunner := crcssh.CreateRunner(host.Driver)
diskSize, diskUse, err = cluster.GetRootPartitionUsage(sshRunner)
if err != nil {
result.Success = false
result.Error = err.Error()
return *result, errors.New(err.Error())
}
}
result.OpenshiftStatus = openshiftStatus
result.PodmanStatus = podmanStatus
result.DiskUse = diskUse
result.DiskSize = diskSize
result.CrcStatus = vmStatus.String()
Expand Down
4 changes: 4 additions & 0 deletions pkg/crc/machine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type StartConfig struct {

// User Pull secret
GetPullSecret GetPullSecretFunc

// To disable launching of the cluster, or not
DisableCluster bool
}

type ClusterConfig struct {
Expand Down Expand Up @@ -94,6 +97,7 @@ type ClusterStatusConfig struct {
type ClusterStatusResult struct {
Name string
CrcStatus string
PodmanStatus string
OpenshiftStatus string
DiskUse int64
DiskSize int64
Expand Down

0 comments on commit 1ca434d

Please sign in to comment.