Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/env/kube_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func NewKubeEnvPrinter(injector di.Injector) *KubeEnvPrinter {
// It checks for a project-specific volume directory and returns current variables
// if it doesn't exist. If it does, it ensures each PVC directory has a corresponding
// "PV_" environment variable, returning the map if all are accounted for.
// If not all volumes are accounted for, it attempts to query the Kubernetes API
// to create environment variables for matching PVCs. If the API is unavailable,
// it gracefully degrades by returning the basic environment variables without failing.
func (e *KubeEnvPrinter) GetEnvVars() (map[string]string, error) {
envVars := make(map[string]string)
configRoot, err := e.configHandler.GetConfigRoot()
Expand Down Expand Up @@ -111,7 +114,7 @@ func (e *KubeEnvPrinter) GetEnvVars() (map[string]string, error) {

pvcs, err := queryPersistentVolumeClaims(kubeConfigPath)
if err != nil {
return nil, fmt.Errorf("error querying persistent volume claims: %w", err)
return envVars, nil
}

if pvcs != nil && pvcs.Items != nil {
Expand Down
21 changes: 12 additions & 9 deletions pkg/env/kube_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,22 @@ func TestKubeEnvPrinter_GetEnvVars(t *testing.T) {
// When getting environment variables
envVars, err := printer.GetEnvVars()

// Then an error should be returned
if err == nil {
t.Error("Expected error, got nil")
// Then no error should be returned (graceful degradation)
if err != nil {
t.Errorf("Expected no error due to graceful degradation, got %v", err)
}

// And the error should mention querying PVCs
if !strings.Contains(err.Error(), "error querying persistent volume claims") {
t.Errorf("Expected error about querying PVCs, got %v", err)
// And envVars should not be nil (should contain basic kube config vars)
if envVars == nil {
t.Error("Expected non-nil envVars with basic kube config")
}

// And envVars should be nil
if envVars != nil {
t.Errorf("Expected nil envVars, got %v", envVars)
// And basic kubernetes environment variables should be present
if _, exists := envVars["KUBECONFIG"]; !exists {
t.Error("Expected KUBECONFIG to be present in envVars")
}
if _, exists := envVars["KUBE_CONFIG_PATH"]; !exists {
t.Error("Expected KUBE_CONFIG_PATH to be present in envVars")
}
})

Expand Down
Loading