-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize environment configuration (#6293)
* Define central config * Use envConfig in GenericRun for segment parameters * Pass the env config into the context passed to CLI methods * Use PodmanCmd and DockerCmd from context * Remove tests now that ODO_DISABLE_TELEMETRY is checked for a bool value * deploy.Deploy: Use values from ctx instead of parameters + use FS from DI * dev.Start: Use values from ctx instead of parameters * image.Build*: Use values from ctx instead of parameters * Use telemetry file from context * Pass ctx to segment.getTelemetryForDevfileRegistry * Use ctx in getTelemetryForDevfileRegistry * Call IsTelemetryEnabled once and use scontext.GetTelemetryStatus after * Fix unit tests * Use envConfig in segment.IsTelemetryEnabled * Define TelemetryCaller constant in test helper * IsTrackingConsentEnabled: get value from envconfig instead of env * Use ctx instead of GLOBALODOCONFIG * Place ODO_EXPERIMENTAL_MODE in configuration * Use maintained envconfig package * Define default values when exist * Document accepted boolean values
- Loading branch information
Showing
80 changed files
with
2,089 additions
and
449 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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package alizer | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/redhat-developer/alizer/go/pkg/apis/recognizer" | ||
"github.com/redhat-developer/odo/pkg/api" | ||
) | ||
|
||
type Client interface { | ||
DetectFramework(path string) (recognizer.DevFileType, api.Registry, error) | ||
DetectFramework(ctx context.Context, path string) (recognizer.DevFileType, api.Registry, error) | ||
DetectName(path string) (string, error) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,29 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sethvargo/go-envconfig" | ||
) | ||
|
||
type Configuration struct { | ||
DevfileProxy *string `env:"DEVFILE_PROXY,noinit"` | ||
DockerCmd string `env:"DOCKER_CMD,default=docker"` | ||
Globalodoconfig *string `env:"GLOBALODOCONFIG,noinit"` | ||
OdoDebugTelemetryFile *string `env:"ODO_DEBUG_TELEMETRY_FILE,noinit"` | ||
OdoDisableTelemetry *bool `env:"ODO_DISABLE_TELEMETRY,noinit"` | ||
OdoLogLevel *int `env:"ODO_LOG_LEVEL,noinit"` | ||
OdoTrackingConsent *string `env:"ODO_TRACKING_CONSENT,noinit"` | ||
PodmanCmd string `env:"PODMAN_CMD,default=podman"` | ||
TelemetryCaller string `env:"TELEMETRY_CALLER,default="` | ||
OdoExperimentalMode bool `env:"ODO_EXPERIMENTAL_MODE,default=false"` | ||
} | ||
|
||
func GetConfiguration() (*Configuration, error) { | ||
var s Configuration | ||
err := envconfig.Process(context.Background(), &s) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &s, nil | ||
} |
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,54 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestDefaultValues(t *testing.T) { | ||
cfg, err := GetConfiguration() | ||
if err != nil { | ||
t.Errorf("Error is not expected: %v", err) | ||
} | ||
|
||
checkDefaultStringValue(t, "DockerCmd", cfg.DockerCmd, "docker") | ||
checkDefaultStringValue(t, "PodmanCmd", cfg.PodmanCmd, "podman") | ||
checkDefaultStringValue(t, "TelemetryCaller", cfg.TelemetryCaller, "") | ||
checkDefaultBoolValue(t, "OdoExperimentalMode", cfg.OdoExperimentalMode, false) | ||
|
||
// Use noinit to set non initialized value as nil instead of zero-value | ||
checkNilString(t, "DevfileProxy", cfg.DevfileProxy) | ||
checkNilString(t, "Globalodoconfig", cfg.Globalodoconfig) | ||
checkNilString(t, "Globalodoconfig", cfg.Globalodoconfig) | ||
checkNilString(t, "OdoDebugTelemetryFile", cfg.OdoDebugTelemetryFile) | ||
checkNilBool(t, "OdoDisableTelemetry", cfg.OdoDisableTelemetry) | ||
checkNilString(t, "OdoTrackingConsent", cfg.OdoTrackingConsent) | ||
|
||
} | ||
|
||
func checkDefaultStringValue(t *testing.T, fieldName string, field string, def string) { | ||
if field != def { | ||
t.Errorf("default value for %q should be %q but is %q", fieldName, def, field) | ||
} | ||
|
||
} | ||
|
||
func checkDefaultBoolValue(t *testing.T, fieldName string, field bool, def bool) { | ||
if field != def { | ||
t.Errorf("default value for %q should be %v but is %v", fieldName, def, field) | ||
} | ||
|
||
} | ||
|
||
func checkNilString(t *testing.T, fieldName string, field *string) { | ||
if field != nil { | ||
t.Errorf("value for non specified env var %q should be nil but is %q", fieldName, *field) | ||
|
||
} | ||
} | ||
|
||
func checkNilBool(t *testing.T, fieldName string, field *bool) { | ||
if field != nil { | ||
t.Errorf("value for non specified env var %q should be nil but is %v", fieldName, *field) | ||
|
||
} | ||
} |
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,25 @@ | ||
package context | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/redhat-developer/odo/pkg/config" | ||
) | ||
|
||
type contextKey struct{} | ||
|
||
var key = contextKey{} | ||
|
||
// WithEnvConfig sets the environment configuration in ctx | ||
func WithEnvConfig(ctx context.Context, val config.Configuration) context.Context { | ||
return context.WithValue(ctx, key, val) | ||
} | ||
|
||
// GetEnvConfig returns the environment configuration from ctx | ||
func GetEnvConfig(ctx context.Context) config.Configuration { | ||
value := ctx.Value(key) | ||
if cast, ok := value.(config.Configuration); ok { | ||
return cast | ||
} | ||
panic("GetEnvConfig can be called only after WithEnvConfig has been called") | ||
} |
Oops, something went wrong.