-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13137d4
commit a931546
Showing
4 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package local | ||
|
||
import ( | ||
"fmt" | ||
"github.com/airbytehq/abctl/internal/cmd/local/docker" | ||
"github.com/airbytehq/abctl/internal/cmd/local/k8s" | ||
"github.com/airbytehq/abctl/internal/cmd/local/local" | ||
"github.com/airbytehq/abctl/internal/telemetry" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdStatus(provider k8s.Provider) *cobra.Command { | ||
spinner := &pterm.DefaultSpinner | ||
|
||
cmd := &cobra.Command{ | ||
Use: "status", | ||
Short: "Status of local Airbyte", | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
spinner, _ = spinner.Start("Starting status check") | ||
spinner.UpdateText("Checking for Docker installation") | ||
|
||
dockerVersion, err := dockerInstalled(cmd.Context()) | ||
if err != nil { | ||
pterm.Error.Println("Unable to determine if Docker is installed") | ||
return fmt.Errorf("could not determine docker installation status: %w", err) | ||
} | ||
|
||
telClient.Attr("docker_version", dockerVersion.Version) | ||
telClient.Attr("docker_arch", dockerVersion.Arch) | ||
telClient.Attr("docker_platform", dockerVersion.Platform) | ||
|
||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return telemetry.Wrapper(cmd.Context(), telemetry.Status, func() error { | ||
spinner.UpdateText(fmt.Sprintf("Checking for existing Kubernetes cluster '%s'", provider.ClusterName)) | ||
|
||
cluster, err := provider.Cluster() | ||
if err != nil { | ||
pterm.Error.Printfln("Could not determine status of any existing '%s' cluster", provider.ClusterName) | ||
return err | ||
} | ||
|
||
if !cluster.Exists() { | ||
pterm.Warning.Println("Airbyte does not appear to be installed locally") | ||
return nil | ||
} | ||
|
||
var port int | ||
|
||
if cluster.Exists() { | ||
// existing cluster, validate it | ||
pterm.Success.Printfln("Existing cluster '%s' found", provider.ClusterName) | ||
spinner.UpdateText(fmt.Sprintf("Validating existing cluster '%s'", provider.ClusterName)) | ||
|
||
// only for kind do we need to check the existing port | ||
if provider.Name == k8s.Kind { | ||
if dockerClient == nil { | ||
dockerClient, err = docker.New(cmd.Context()) | ||
if err != nil { | ||
pterm.Error.Printfln("Could not connect to Docker daemon") | ||
return fmt.Errorf("could not connect to docker: %w", err) | ||
} | ||
} | ||
|
||
port, err = dockerClient.Port(cmd.Context(), fmt.Sprintf("%s-control-plane", provider.ClusterName)) | ||
if err != nil { | ||
pterm.Warning.Printfln("TODO!!!") | ||
} | ||
|
||
pterm.Info.Printfln("port: %d", port) | ||
} | ||
} | ||
|
||
lc, err := local.New(provider, | ||
local.WithPortHTTP(port), | ||
local.WithTelemetryClient(telClient), | ||
local.WithSpinner(spinner), | ||
) | ||
if err != nil { | ||
pterm.Error.Printfln("Failed to initialize 'local' command") | ||
return fmt.Errorf("could not initialize local command: %w", err) | ||
} | ||
|
||
if err := lc.Status(cmd.Context()); err != nil { | ||
spinner.Fail("Unable to install Airbyte locally") | ||
return err | ||
} | ||
|
||
spinner.Success("Status check") | ||
return nil | ||
}) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters