Skip to content

Commit

Permalink
CR-22383-block-cli (#737)
Browse files Browse the repository at this point in the history
## What
block `cf runtime install` command early

## Why
cli runtimes are no longer supported

## Notes
this is the minimal change required to block the command. a more
thorough cleanup is needed in the near future.
  • Loading branch information
ATGardner authored Feb 5, 2024
1 parent 625e806 commit 67fda7a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 171 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.1.60
VERSION=v0.1.61

OUT_DIR=dist
YEAR?=$(shell date +"%Y")
Expand Down
164 changes: 76 additions & 88 deletions cmd/commands/runtime_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,94 +168,13 @@ func NewRuntimeInstallCommand() *cobra.Command {
)

cmd := &cobra.Command{
Use: "install [runtime_name]",
Short: "Install a new Codefresh runtime",
Example: util.Doc(`
# To run this command you need to create a personal access token for your git provider
# and provide it using:
export GIT_TOKEN=<token>
# or with the flag:
--git-token <token>
# Adds a new runtime
<BIN> runtime install runtime-name --repo gitops_repo
`),
PreRunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

if len(args) > 0 {
installationOpts.RuntimeName = args[0]
}

if installationOpts.GatewayName != "" {
installationOpts.useGatewayAPI = true
}

installationOpts.RuntimeNamespace = installationOpts.RuntimeName
namespace := cmd.Flag("namespace").Value.String()
if namespace != "" {
installationOpts.RuntimeNamespace = namespace
}

createAnalyticsReporter(ctx, reporter.InstallFlow, installationOpts.DisableTelemetry)

if accessMode != "" {
installationOpts.AccessMode = platmodel.AccessMode(strings.ToUpper(accessMode))
if !installationOpts.AccessMode.IsValid() {
return fmt.Errorf("invalid access-mode %s, must be one of: ingress|tunnel", accessMode)
}

if installationOpts.AccessMode == platmodel.AccessModeTunnel && installationOpts.IngressHost != "" {
return fmt.Errorf("ingress host can't be set when access mode is Tunnel")
}
}

err := runtimeInstallCommandPreRunHandler(cmd, installationOpts)
handleCliStep(reporter.InstallPhasePreCheckFinish, "Finished pre installation checks", err, true, false)
if err != nil {
if errors.Is(err, promptui.ErrInterrupt) {
return fmt.Errorf("installation canceled by user")
}

util.CheckNetworkErr(err)

return util.DecorateErrorWithDocsLink(fmt.Errorf("pre installation error: %w", err), store.Get().RequirementsLink)
}

finalParameters := map[string]string{
"Codefresh context": cfConfig.GetCurrentContext().Name,
"Kube context": installationOpts.kubeContext,
"Runtime name": installationOpts.RuntimeName,
"Runtime namespace": installationOpts.RuntimeNamespace,
"Repository URL": installationOpts.InsCloneOpts.Repo,
"Ingress class": installationOpts.IngressClass,
"Installing demo resources": strconv.FormatBool(installationOpts.InstallDemoResources),
"Git provider": string(installationOpts.gitProvider.Type()),
}

if installationOpts.AccessMode == platmodel.AccessModeTunnel {
finalParameters["Tunnel URL"] = installationOpts.IngressHost
finalParameters["Access mode"] = "Codefresh tunnel-based"
} else {
finalParameters["Ingress host"] = installationOpts.IngressHost
finalParameters["Internal ingress host"] = installationOpts.InternalIngressHost
finalParameters["Access mode"] = "Ingress-based"
}

if err := getApprovalFromUser(ctx, finalParameters, "runtime install"); err != nil {
return err
}

return nil
},
Use: "install [runtime_name]",
Deprecated: "We have transitioned our GitOps Runtimes from CLI-based to Helm-based installation.",
RunE: func(cmd *cobra.Command, _ []string) error {
err := runRuntimeInstall(cmd, installationOpts)
handleCliStep(reporter.InstallPhaseFinish, "Runtime installation phase finished", err, false, false)
return err
return errors.New(`We have transitioned our GitOps Runtimes from CLI-based to Helm-based installation.
As of January 30, 2024, CLI-based Runtimes are no longer supported.
If you're currently using CLI-based Hybrid GitOps Runtimes, we encourage you to migrate to Helm by following our migration guidelines (https://codefresh.io/docs/docs/installation/gitops/migrate-cli-runtimes-helm).
For Helm installation, review our documentation on installing Hybrid GitOps Runtimes (https://codefresh.io/docs/docs/installation/gitops/hybrid-gitops-helm-installation).`)
},
}

Expand Down Expand Up @@ -313,6 +232,75 @@ func NewRuntimeInstallCommand() *cobra.Command {
return cmd
}

func PreRunE(cmd *cobra.Command, args []string, installationOpts *RuntimeInstallOptions, accessMode string) error {
ctx := cmd.Context()

if len(args) > 0 {
installationOpts.RuntimeName = args[0]
}

if installationOpts.GatewayName != "" {
installationOpts.useGatewayAPI = true
}

installationOpts.RuntimeNamespace = installationOpts.RuntimeName
namespace := cmd.Flag("namespace").Value.String()
if namespace != "" {
installationOpts.RuntimeNamespace = namespace
}

createAnalyticsReporter(ctx, reporter.InstallFlow, installationOpts.DisableTelemetry)

if accessMode != "" {
installationOpts.AccessMode = platmodel.AccessMode(strings.ToUpper(accessMode))
if !installationOpts.AccessMode.IsValid() {
return fmt.Errorf("invalid access-mode %s, must be one of: ingress|tunnel", accessMode)
}

if installationOpts.AccessMode == platmodel.AccessModeTunnel && installationOpts.IngressHost != "" {
return fmt.Errorf("ingress host can't be set when access mode is Tunnel")
}
}

err := runtimeInstallCommandPreRunHandler(cmd, installationOpts)
handleCliStep(reporter.InstallPhasePreCheckFinish, "Finished pre installation checks", err, true, false)
if err != nil {
if errors.Is(err, promptui.ErrInterrupt) {
return fmt.Errorf("installation canceled by user")
}

util.CheckNetworkErr(err)

return util.DecorateErrorWithDocsLink(fmt.Errorf("pre installation error: %w", err), store.Get().RequirementsLink)
}

finalParameters := map[string]string{
"Codefresh context": cfConfig.GetCurrentContext().Name,
"Kube context": installationOpts.kubeContext,
"Runtime name": installationOpts.RuntimeName,
"Runtime namespace": installationOpts.RuntimeNamespace,
"Repository URL": installationOpts.InsCloneOpts.Repo,
"Ingress class": installationOpts.IngressClass,
"Installing demo resources": strconv.FormatBool(installationOpts.InstallDemoResources),
"Git provider": string(installationOpts.gitProvider.Type()),
}

if installationOpts.AccessMode == platmodel.AccessModeTunnel {
finalParameters["Tunnel URL"] = installationOpts.IngressHost
finalParameters["Access mode"] = "Codefresh tunnel-based"
} else {
finalParameters["Ingress host"] = installationOpts.IngressHost
finalParameters["Internal ingress host"] = installationOpts.InternalIngressHost
finalParameters["Access mode"] = "Ingress-based"
}

if err := getApprovalFromUser(ctx, finalParameters, "runtime install"); err != nil {
return err
}

return nil
}

func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
var err error
ctx := cmd.Context()
Expand Down Expand Up @@ -643,7 +631,7 @@ func createRuntimeOnPlatform(ctx context.Context, opts *RuntimeInstallOptions, r
return runtimeCreationResponse.NewAccessToken, hex.EncodeToString(iv), nil
}

func runRuntimeInstall(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
func RunRuntimeInstall(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
ctx := cmd.Context()
rt, err := preInstallationChecks(cmd, opts)
handleCliStep(reporter.InstallPhaseRunPreCheckFinish, "Pre run installation checks", err, true, true)
Expand Down
1 change: 0 additions & 1 deletion docs/commands/cli-v2_runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ cli-v2 runtime [flags]
### SEE ALSO

* [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops
* [cli-v2 runtime install](cli-v2_runtime_install.md) - Install a new Codefresh runtime
* [cli-v2 runtime list](cli-v2_runtime_list.md) - List all Codefresh runtimes
* [cli-v2 runtime logs](cli-v2_runtime_logs.md) - Work with current runtime logs
* [cli-v2 runtime uninstall](cli-v2_runtime_uninstall.md) - Uninstall a Codefresh runtime
Expand Down
79 changes: 0 additions & 79 deletions docs/commands/cli-v2_runtime_install.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cf version

```bash
# download and extract the binary
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.60/cf-linux-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.61/cf-linux-amd64.tar.gz | tar zx

# move the binary to your $PATH
mv ./cf-linux-amd64 /usr/local/bin/cf
Expand All @@ -36,7 +36,7 @@ cf version

```bash
# download and extract the binary
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.60/cf-darwin-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.61/cf-darwin-amd64.tar.gz | tar zx

# move the binary to your $PATH
mv ./cf-darwin-amd64 /usr/local/bin/cf
Expand Down

0 comments on commit 67fda7a

Please sign in to comment.