Skip to content

Architecture Guide

Anand Gaitonde edited this page Oct 16, 2018 · 28 revisions

Page under construction.

CF CLI Architecture Diagram

The CF CLI master branch contains both the V6 and V7 CLIs:

CLI Architecture

Glossary:

  • main.go (Orange): Entry point into the CF CLI.
  • Command Lists (Grey): List of CLI commands contained in that version of the CF CLI. This is dependent on the build tags provided to GoLang at compile time.
  • Command Packages (Yellow): These packages manage the UX/UI logic for each individual command.
  • Actor Packages (Teal): These packages manage the business logic for the entire CLI. The V6 CLI actors are divided by Cloud Controller API version; the push and V2/V3 actors are required to mitigate the complexity of integrating the V2 and V3 API versions. The V7 CLI utilizes the V7 Actor package for V7 specific commands.
  • API Packages (Green): These packages manage the API requests made to the Cloud Controller/UAA/Networking/etc. These API requests do not contain any business logic; they are simple abstractions of individual API requests.
  • Plugin Packages/Legacy Code (Red): These packages manage the CLI Plugin interface as well as the Legacy CLI code. The plugin interface exclusively talks to the Legacy Code, and the Legacy Code only interacts with the Cloud Controller V2 API, UAA API, and the Routing API.

General Command Flow

When a CLI command runs, the following process occurs to execute the requested action:

  1. All the command line arguments (aka os.Args) are provided to the go-flags package with the appropriate command list.
  2. Based on the command tag from the command list and the command line arguments, go-flags will instantiate the correct command struct, populating the struct's fields based off of the provided short/long flags listed in the command struct's tags.
  3. The command's Setup function is called with a preloaded UI and an in memory copy of the CLI config. This Setup function creates all the necessary API clients and Actors required for the command.
  4. The command's Execute function is called; the Execute function [generally] runs through the following:
    1. Validates/sanitizes the user provided input.
    2. API version checking based on provided input.
    3. Verifies API targets based on command requirements.
    4. Outputs "flavor" text to indicate to the user that desired action is about to be processed.
    5. Calls appropriate Actor function(s) to perform command's action. (See step #5 for more information)
    6. Displays output of Actor function(s) depending on command's intent.
  5. When an Actor function is called, one or more API calls are made to the Cloud Controller, UAA, Networking API, etc. in order to perform the desired action. Any complex logic regarding the return of these APIs are handled within the Actor function, returning the final result of said API calls or an error indicating why the Actor function could not proceed.
  6. When a command has returned from it's Execute, any changes to the CLI config are written to disk.

V6 CLI Packages/Files

When the CLI's main package is compiled without the V7 tag (or with the !V7 tag), the V6 CLI's command list is used in the generated binary. This command list points exclusively to the commands under command/v6, command/common, and command/plugin. Depending on the command, they use some combination of the v2action.Actor, v3action.Actor, v2v3action.Actor, and the Push.Actor to perform the desired action.

The following is a list of files exclusive to the V6 CLI:

└── command
    └── common
        ├── command_list_v6.go # Different Command list
        └── internal
            ├── help_all_display_v6.go # Different help list
            └── help_common_display_v6.go # Different help list

V7 Packages/Files

When the CLI's main package is compiled with the V7 tag, the V7 CLI's command list is used in the generated binary. The V7 CLI command list contains everything from the V6 CLI's command list; except it overrides specific command/v6 commands with command/v7 commands. These command/v7 commands should exclusively use the actor/v7action package to perform its business operations. (Note: while the API is transitioning, there may be a need to temporarily use the v2action package to fill in missing functionality)

The following is a list of files exclusive to the V7 CLI:

├── actor
│   └── v7actor # V7 specific business logic
└── command
    ├── common
    │   ├── command_list_v7.go # Different Command list
    │   └── internal
    │       ├── help_all_display_v7.go # Different help list
    │       └── help_common_display_v7.go # Different help list
    └── v7 # Over written V7 versions of V6 commands

Need to fill in the following

  • V6 vs V7
  • Legacy vs Rewrite