Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ishandhanani committed Sep 26, 2024
2 parents 847f8b3 + d3c7752 commit a171463
Show file tree
Hide file tree
Showing 26 changed files with 127 additions and 93 deletions.
7 changes: 6 additions & 1 deletion cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func generateDocs(cmd *cobra.Command, genMarkdown, genReST bool) error {
}
// Generate reStructuredText documentation
if genReST {
if err := doc.GenReSTTree(root, outputDir); err != nil {
emptyStr := func(s string) string { return "" }
linkHandler := func(name, ref string) string {
//sphinx-style refs.
return fmt.Sprintf(":ref:`%s <%s>`", name, ref)
}
if err := doc.GenReSTTreeCustom(root, outputDir, emptyStr, linkHandler); err != nil {
return fmt.Errorf("failed to generate reStructuredText documentation: %w", err)
}
fmt.Println("reStructuredText documentation generated")
Expand Down
8 changes: 5 additions & 3 deletions cmd/preflight/brev/brev.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (c *BrevClient) RunDebuggingScript(instanceName string, image string, image
debuggingScript := generateDebuggingScript(image, imageArgs)

cmd := exec.Command("brev", "refresh")
cmd.Run()
if err := cmd.Run(); err != nil {
return fmt.Errorf("issue running `brev refresh`: %w", err)
}

sshAlias := instanceName
sshCmd := []string{
Expand Down Expand Up @@ -126,7 +128,7 @@ func runSSHExec(sshAlias string, args []string) error {
return fmt.Errorf("error getting stdin pipe: %w", err)
}
for _, arg := range args {
si.Write([]byte(arg + "\n"))
_, _ = si.Write([]byte(arg + "\n"))
}
si.Close()

Expand Down Expand Up @@ -173,7 +175,7 @@ func saveDebugInstance(functionId, instanceName string) error {
instances := make(map[string]string)
data, err := os.ReadFile(configPath)
if err == nil {
json.Unmarshal(data, &instances)
_ = json.Unmarshal(data, &instances)
}

// Add or update the new instance
Expand Down
97 changes: 42 additions & 55 deletions cmd/preflight/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ func CheckCmd() *cobra.Command {
Use: "check <image-name>",
Short: "Run local deployment test for NVCF compatibility",
Long: `Run a local deployment test to verify container compatibility with NVCF.
This command deploys the specified Docker image locally, checks its health,
and performs basic connectivity tests to ensure it meets NVCF requirements.`,
and performs basic connectivity tests to ensure it meets NVCF requirements.
Key features:
- Supports both HTTP and gRPC protocols
- Customizable health check and inference endpoints
- Configurable wait times for container readiness
- Option to force cleanup of existing containers
Use this command to validate your NVCF function before deployment.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
imageName = args[0]
runLocalDeploymentTest()
return runLocalDeploymentTest()
},
}
cmd.Flags().StringVar(&containerPort, "container-port", "8000", "Port that the server is listening on")
Expand All @@ -53,85 +62,63 @@ and performs basic connectivity tests to ensure it meets NVCF requirements.`,
return cmd
}

func runLocalDeploymentTest() {
func runLocalDeploymentTest() error {
if protocol == "grpc" && (grpcServiceName == "" || grpcMethodName == "") {
fmt.Println("Error: gRPC service name and method name are required for gRPC protocol")
os.Exit(1)
return fmt.Errorf("gRPC service name and method name are required for gRPC protocol")
}

cst, err := containerutil.NewContainerSmokeTest()
if err != nil {
fmt.Printf("Error creating ContainerSmokeTest: %v\n", err)
os.Exit(1)
return fmt.Errorf("error creating ContainerSmokeTest: %w", err)
}

// Set up signal handling for graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigChan
fmt.Println("\nReceived interrupt signal. Cleaning up...")
cst.Cleanup()
os.Exit(1)
_ = cst.Cleanup()
}()

// Force cleanup if requested
if forceCleanup {
fmt.Println("Forcing cleanup of existing containers...")
if err := cst.ForceCleanup(imageName); err != nil {
fmt.Printf("Error during force cleanup: %v\n", err)
os.Exit(1)
return fmt.Errorf("error during force cleanup: %w", err)
}
}

defer cst.Cleanup()

err = cst.LaunchContainer(imageName, containerPort)
if err != nil {
fmt.Printf("Error launching container: %v\n", err)
os.Exit(1)
defer func() {
_ = cst.Cleanup()
}()
if err := cst.LaunchContainer(imageName, containerPort); err != nil {
return fmt.Errorf("error launching container: %w", err)
}

var healthErr error
if protocol == "http" {
err = cst.CheckHTTPHealthEndpoint(healthEndpoint, secondsToWaitForHealthy)
healthErr = cst.CheckHTTPHealthEndpoint(healthEndpoint, secondsToWaitForHealthy)
} else {
err = cst.CheckGRPCHealthEndpoint(secondsToWaitForHealthy)
healthErr = cst.CheckGRPCHealthEndpoint(secondsToWaitForHealthy)
}

if err != nil {
fmt.Printf("Error checking health endpoint: %v\n", err)
os.Exit(1)
if healthErr != nil {
return fmt.Errorf("error checking health endpoint: %w", healthErr)
}

fmt.Println("Health Check succeeded!")

if protocol == "http" {
var payload interface{}
err := json.Unmarshal([]byte(httpPayload), &payload)
if err != nil {
fmt.Printf("Error parsing HTTP payload: %v\n", err)
os.Exit(1)
if err := json.Unmarshal([]byte(httpPayload), &payload); err != nil {
return fmt.Errorf("error parsing HTTP payload: %w", err)
}

err = cst.TestHTTPInference(httpInferenceEndpoint, payload)
if err != nil {
fmt.Printf("Error testing HTTP inference: %v\n", err)
fmt.Println("HTTP inference test failed. Please check your application's endpoints and try again.")
os.Exit(1)
fmt.Println("HTTP inference test succeeded!")
} else if protocol == "grpc" {
var inputData map[string]interface{}
err := json.Unmarshal([]byte(grpcInputData), &inputData)
if err != nil {
fmt.Printf("Error parsing gRPC input data: %v\n", err)
os.Exit(1)
}

err = cst.TestGRPCInference(grpcServiceName, grpcMethodName, inputData, false)
if err != nil {
fmt.Printf("Error testing gRPC inference: %v\n", err)
os.Exit(1)
}
if err := cst.TestHTTPInference(httpInferenceEndpoint, payload); err != nil {
return fmt.Errorf("error testing HTTP inference: %w", err)
}
fmt.Println("HTTP inference test succeeded!")
} else if protocol == "grpc" {
var inputData map[string]interface{}
if err := json.Unmarshal([]byte(grpcInputData), &inputData); err != nil {
return fmt.Errorf("error parsing gRPC input data: %w", err)
}
if err := cst.TestGRPCInference(grpcServiceName, grpcMethodName, inputData, false); err != nil {
return fmt.Errorf("error testing gRPC inference: %w", err)
}
fmt.Println("gRPC inference test succeeded!")
}
return nil
}
19 changes: 13 additions & 6 deletions cmd/preflight/debug/debug_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ func debugStartCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "start <function-id>",
Short: "Start a debug environment",
Long: `Create and start a debug environment for an NVCF function`,
Args: cobra.ExactArgs(1),
RunE: runDebugStart,
Long: `Create and start a debug environment for an NVCF function.
This command sets up a GPU-powered VM using Brev CLI, pulls the function's
container image, and runs it in a debugging session. It allows you to:
- Debug functions with ERROR status
- Specify a particular version for debugging
- Access the debug environment via SSH for hands-on troubleshooting
Use this command when you need to investigate issues with your NVCF function in a live environment.`,
Args: cobra.ExactArgs(1),
RunE: runDebugStart,
}

cmd.Flags().String("version-id", "", "The ID of the version")
Expand Down Expand Up @@ -109,9 +117,8 @@ func runDebugStart(cmd *cobra.Command, args []string) error {
instanceName := fmt.Sprintf("nvcf-%s-debug-%s", functionId, randomString)

// hit the brev api to create an instance using
err = brevClient.CreateInstance(functionId, instanceName)
if err != nil {
return output.Error(cmd, "Error creating instance", err)
if err := brevClient.CreateInstance(functionId, instanceName); err != nil {
return output.Error(cmd, "Error creating Brev instance", err)
}

// run the debugging script on the instance
Expand Down
7 changes: 6 additions & 1 deletion docs/nvcf.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ NVIDIA Cloud Functions CLI

A command-line interface for managing and interacting with NVIDIA Cloud Functions.

Environment variables:
NVCF_BETA - Set to true to enable beta features
NVCF_SHOW_DOCS_CMD - Set to true to show the docs command


```
nvcf [flags]
```
Expand All @@ -17,7 +22,7 @@ nvcf [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Authenticate with NVIDIA Cloud and configure the CLI to use your API key.
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_auth_configure-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nvcf auth configure-docker [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_auth_login.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nvcf auth login [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_auth_logout.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nvcf auth logout [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_auth_org-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nvcf auth org-id [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_auth_orgs.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ nvcf auth orgs [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_auth_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nvcf auth status [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_auth_whoami.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nvcf auth whoami [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on your serverless functions.
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
16 changes: 15 additions & 1 deletion docs/nvcf_function_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ Create a new NVCF Function with the specified parameters. If you specify --from-
nvcf function create [flags]
```

### Examples

```
Create a new function:
nvcf function create --name myfunction --inference-url /v1/chat/completions --inference-port 80 --health-uri /health --container-image nvcr.io/nvidia/example-image:latest
Create and deploy a new function from a file:
nvcf function create --file deploy.yaml --deploy
Create a new version of an existing function:
nvcf function create --from-version existing-function-id --name newversion --inference-url /v2/chat/completions --inference-port 8080 --health-uri /healthcheck --container-image nvcr.io/nvidia/updated-image:v2
```

### Options

```
Expand Down Expand Up @@ -49,7 +63,7 @@ nvcf function create [flags]
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_function_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ nvcf function delete fid --version-id vid
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/nvcf_function_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ nvcf function deploy fid --version-id vid --gpu A100 --instance-type g5.4xlarge
--json Output results in JSON format
--no-color Disable color output
-q, --quiet Suppress non-error output
-v, --verbose Enable verbose output
-v, --verbose Enable verbose output and show underlying API calls
```

### SEE ALSO
Expand Down
Loading

0 comments on commit a171463

Please sign in to comment.