-
Notifications
You must be signed in to change notification settings - Fork 32
Tag based gateway deployment #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tharsanan1
wants to merge
3
commits into
wso2:main
Choose a base branch
from
Tharsanan1:tag-based-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,71 @@ | ||
| package it | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log" | ||
| "strings" | ||
| "sync" | ||
|
|
||
| "github.com/cucumber/godog" | ||
| ) | ||
|
|
||
| const ConfigTagPrefix = "@config-" | ||
|
|
||
| // GatewayConfigManager handles configuration switching for the gateway | ||
| type GatewayConfigManager struct { | ||
| registry *ConfigProfileRegistry | ||
| composeManager *ComposeManager | ||
| currentProfile string | ||
| mu sync.Mutex | ||
| } | ||
|
|
||
| // NewGatewayConfigManager creates a new config manager | ||
| func NewGatewayConfigManager(cm *ComposeManager) *GatewayConfigManager { | ||
| return &GatewayConfigManager{ | ||
| registry: NewConfigProfileRegistry(), | ||
| composeManager: cm, | ||
| currentProfile: "default", // Assume default on startup | ||
| } | ||
| } | ||
|
|
||
| // EnsureConfig checks the scenario tags and restarts the gateway if a different config is required | ||
| func (m *GatewayConfigManager) EnsureConfig(ctx context.Context, sc *godog.Scenario) error { | ||
| m.mu.Lock() | ||
| defer m.mu.Unlock() | ||
|
|
||
| requiredProfile := m.extractConfigTag(sc) | ||
| if requiredProfile == "" { | ||
| requiredProfile = "default" | ||
| } | ||
|
|
||
| if m.currentProfile == requiredProfile { | ||
| return nil // No restart needed | ||
| } | ||
|
|
||
| log.Printf("Switching gateway config from '%s' to '%s'...", m.currentProfile, requiredProfile) | ||
|
|
||
| profile, ok := m.registry.Get(requiredProfile) | ||
| if !ok { | ||
| return fmt.Errorf("unknown config profile: %s", requiredProfile) | ||
| } | ||
|
|
||
| // Restart gateway-controller with new env vars | ||
| if err := m.composeManager.RestartGatewayController(ctx, profile.EnvVars); err != nil { | ||
| return fmt.Errorf("failed to restart gateway with profile %s: %w", requiredProfile, err) | ||
| } | ||
|
|
||
| m.currentProfile = requiredProfile | ||
| log.Printf("Switched to '%s' profile successfully", requiredProfile) | ||
| return nil | ||
| } | ||
|
|
||
| // extractConfigTag finds the first tag starting with @config- and returns the suffix | ||
| func (m *GatewayConfigManager) extractConfigTag(sc *godog.Scenario) string { | ||
| for _, tag := range sc.Tags { | ||
| if strings.HasPrefix(tag.Name, ConfigTagPrefix) { | ||
| return strings.TrimPrefix(tag.Name, ConfigTagPrefix) | ||
| } | ||
| } | ||
| return "" | ||
| } |
This file contains hidden or 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,74 @@ | ||
| package it | ||
|
|
||
| // ConfigProfile defines a named configuration set for the gateway | ||
| type ConfigProfile struct { | ||
| Name string | ||
| EnvVars map[string]string | ||
| Description string | ||
| } | ||
|
|
||
| // ConfigProfileRegistry manages the available configuration profiles | ||
| type ConfigProfileRegistry struct { | ||
| profiles map[string]*ConfigProfile | ||
| defaultProfile string | ||
| } | ||
|
|
||
| // NewConfigProfileRegistry creates a new registry with standard profiles | ||
| func NewConfigProfileRegistry() *ConfigProfileRegistry { | ||
| registry := &ConfigProfileRegistry{ | ||
| profiles: make(map[string]*ConfigProfile), | ||
| defaultProfile: "default", | ||
| } | ||
|
|
||
| // Register standard profiles | ||
| registry.Register(&ConfigProfile{ | ||
| Name: "default", | ||
| EnvVars: map[string]string{ | ||
| "GATEWAY_LOGGING_LEVEL": "info", | ||
| "GATEWAY_STORAGE_TYPE": "sqlite", | ||
| }, | ||
| Description: "Standard configuration using SQLite and Info logging", | ||
| }) | ||
|
|
||
| registry.Register(&ConfigProfile{ | ||
| Name: "debug", | ||
| EnvVars: map[string]string{ | ||
| "GATEWAY_LOGGING_LEVEL": "debug", | ||
| "GATEWAY_STORAGE_TYPE": "sqlite", | ||
| }, | ||
| Description: "Debug configuration enabling verbose logging", | ||
| }) | ||
|
|
||
| registry.Register(&ConfigProfile{ | ||
| Name: "memory", | ||
| EnvVars: map[string]string{ | ||
| "GATEWAY_LOGGING_LEVEL": "info", | ||
| "GATEWAY_STORAGE_TYPE": "memory", | ||
| }, | ||
| Description: "In-memory storage configuration (non-persistent)", | ||
| }) | ||
|
|
||
| registry.Register(&ConfigProfile{ | ||
| Name: "tracing", | ||
| EnvVars: map[string]string{ | ||
| "GATEWAY_LOGGING_LEVEL": "info", | ||
| "GATEWAY_STORAGE_TYPE": "memory", | ||
| "GATEWAY_TRACING_ENABLED": "true", | ||
| }, | ||
| Description: "Configuration with OpenTelemetry tracing enabled", | ||
| }) | ||
|
|
||
| return registry | ||
|
|
||
| } | ||
|
|
||
| // Register adds a profile to the registry | ||
| func (r *ConfigProfileRegistry) Register(profile *ConfigProfile) { | ||
| r.profiles[profile.Name] = profile | ||
| } | ||
|
|
||
| // Get retrieves a profile by name | ||
| func (r *ConfigProfileRegistry) Get(name string) (*ConfigProfile, bool) { | ||
| profile, ok := r.profiles[name] | ||
| return profile, ok | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: wso2/api-platform
Length of output: 82
🏁 Script executed:
Repository: wso2/api-platform
Length of output: 2154
🏁 Script executed:
Repository: wso2/api-platform
Length of output: 1571
🏁 Script executed:
Repository: wso2/api-platform
Length of output: 790
Portability issue:
script -q /dev/nullsyntax is macOS/BSD-specific and will fail on Linux.The
testtarget uses BSD-stylescript -q /dev/nullsyntax, which is incompatible with GNUscripton Linux systems. This breaks cross-platform development and CI/CD pipelines running on Linux.Additionally, the
test-verbosetarget (line 36) runs tests without the script wrapper, creating inconsistent behavior between the two targets.The
-count=1flag is correct for disabling test caching in integration tests. However,go test -valready provides line-buffered streaming output; the script wrapper may be unnecessary. Consider either:go test -voutput buffering🤖 Prompt for AI Agents