forked from k8sgpt-ai/k8sgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into docs/issue-232
- Loading branch information
Showing
22 changed files
with
831 additions
and
70 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
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
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,60 @@ | ||
package serve | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fatih/color" | ||
k8sgptserver "github.com/k8sgpt-ai/k8sgpt/pkg/server" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"os" | ||
) | ||
|
||
var ( | ||
port string | ||
backend string | ||
token string | ||
) | ||
|
||
var ServeCmd = &cobra.Command{ | ||
Use: "serve", | ||
Short: "Runs k8sgpt as a server", | ||
Long: `Runs k8sgpt as a server to allow for easy integration with other applications.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
backendType := viper.GetString("backend_type") | ||
if backendType == "" { | ||
color.Red("No backend set. Please run k8sgpt auth") | ||
os.Exit(1) | ||
} | ||
|
||
if backend != "" { | ||
backendType = backend | ||
} | ||
|
||
token := viper.GetString(fmt.Sprintf("%s_key", backendType)) | ||
// check if nil | ||
if token == "" { | ||
color.Red("No %s key set. Please run k8sgpt auth", backendType) | ||
os.Exit(1) | ||
} | ||
|
||
server := k8sgptserver.Config{ | ||
Backend: backend, | ||
Port: port, | ||
Token: token, | ||
} | ||
|
||
err := server.Serve() | ||
if err != nil { | ||
color.Red("Error: %v", err) | ||
os.Exit(1) | ||
} | ||
// override the default backend if a flag is provided | ||
}, | ||
} | ||
|
||
func init() { | ||
// add flag for backend | ||
ServeCmd.Flags().StringVarP(&port, "port", "p", "8080", "Port to run the server on") | ||
ServeCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider") | ||
} |
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
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
Oops, something went wrong.