mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-07-13 07:05:42 +00:00
feat: envs to initialise server
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
parent
51b1b352ac
commit
0071e25992
@ -1,10 +1,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/k8sgpt-ai/k8sgpt/cmd/serve"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/k8sgpt-ai/k8sgpt/cmd/serve"
|
||||||
|
|
||||||
"github.com/k8sgpt-ai/k8sgpt/cmd/analyze"
|
"github.com/k8sgpt-ai/k8sgpt/cmd/analyze"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/cmd/auth"
|
"github.com/k8sgpt-ai/k8sgpt/cmd/auth"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/cmd/filters"
|
"github.com/k8sgpt-ai/k8sgpt/cmd/filters"
|
||||||
@ -81,6 +82,7 @@ func initConfig() {
|
|||||||
viper.Set("kubecontext", kubecontext)
|
viper.Set("kubecontext", kubecontext)
|
||||||
viper.Set("kubeconfig", kubeconfig)
|
viper.Set("kubeconfig", kubeconfig)
|
||||||
|
|
||||||
|
viper.SetEnvPrefix("K8SGPT")
|
||||||
viper.AutomaticEnv() // read in environment variables that match
|
viper.AutomaticEnv() // read in environment variables that match
|
||||||
|
|
||||||
// If a config file is found, read it in.
|
// If a config file is found, read it in.
|
||||||
|
@ -28,19 +28,33 @@ var ServeCmd = &cobra.Command{
|
|||||||
color.Red("Error: %v", err)
|
color.Red("Error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
var aiProvider *ai.AIProvider
|
||||||
if len(configAI.Providers) == 0 {
|
if len(configAI.Providers) == 0 {
|
||||||
|
// Check for env injection
|
||||||
|
backend = os.Getenv("K8SGPT_BACKEND")
|
||||||
|
password := os.Getenv("K8SGPT_PASSWORD")
|
||||||
|
model := os.Getenv("K8SGPT_MODEL")
|
||||||
|
// If the envs are set, alocate in place to the aiProvider
|
||||||
|
// else exit with error
|
||||||
|
if backend != "" || password != "" || model != "" {
|
||||||
|
aiProvider = &ai.AIProvider{
|
||||||
|
Name: backend,
|
||||||
|
Password: password,
|
||||||
|
Model: model,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
color.Red("Error: AI provider not specified in configuration. Please run k8sgpt auth")
|
color.Red("Error: AI provider not specified in configuration. Please run k8sgpt auth")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var aiProvider ai.AIProvider
|
if aiProvider == nil {
|
||||||
for _, provider := range configAI.Providers {
|
for _, provider := range configAI.Providers {
|
||||||
if backend == provider.Name {
|
if backend == provider.Name {
|
||||||
aiProvider = provider
|
aiProvider = &provider
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if aiProvider.Name == "" {
|
if aiProvider.Name == "" {
|
||||||
color.Red("Error: AI provider %s not specified in configuration. Please run k8sgpt auth", backend)
|
color.Red("Error: AI provider %s not specified in configuration. Please run k8sgpt auth", backend)
|
||||||
|
Loading…
Reference in New Issue
Block a user