-
Notifications
You must be signed in to change notification settings - Fork 106
fix(operator): apply feature flags when scheduled sessions trigger #1572
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
adf081b
0f878ef
3526563
8b8f93f
d1e318c
3766205
6212122
0f9edb0
e688b0b
fcc3f22
1d3cde4
ab35cd2
7c9edfe
513ff9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| package trigger | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes/fake" | ||
| ) | ||
|
|
||
| func TestSanitizeName(t *testing.T) { | ||
|
|
@@ -104,3 +109,120 @@ func TestSanitizeName_TruncationPreservesValidSuffix(t *testing.T) { | |
| t.Errorf("sanitizeName(%q) ends with hyphen: %q", input, result) | ||
| } | ||
| } | ||
|
|
||
| func TestApplyFeatureFlagOverrides(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| configMapData map[string]string | ||
| existingEnvVars map[string]interface{} | ||
| expectedEnvVars map[string]interface{} | ||
| }{ | ||
| { | ||
| name: "jira-write enabled sets JIRA_READ_ONLY_MODE to false", | ||
| configMapData: map[string]string{"jira-write": "true"}, | ||
| existingEnvVars: nil, | ||
| expectedEnvVars: map[string]interface{}{"JIRA_READ_ONLY_MODE": "false"}, | ||
| }, | ||
| { | ||
| name: "jira-write disabled does not set env var", | ||
| configMapData: map[string]string{"jira-write": "false"}, | ||
| existingEnvVars: nil, | ||
| expectedEnvVars: nil, | ||
| }, | ||
| { | ||
| name: "no overrides ConfigMap does not set env var", | ||
| configMapData: nil, | ||
| existingEnvVars: nil, | ||
| expectedEnvVars: nil, | ||
| }, | ||
| { | ||
| name: "preserves existing env vars", | ||
| configMapData: map[string]string{"jira-write": "true"}, | ||
| existingEnvVars: map[string]interface{}{"CUSTOM_VAR": "value"}, | ||
| expectedEnvVars: map[string]interface{}{ | ||
| "CUSTOM_VAR": "value", | ||
| "JIRA_READ_ONLY_MODE": "false", | ||
| }, | ||
| }, | ||
| { | ||
| name: "other flags do not affect env vars", | ||
| configMapData: map[string]string{"other-flag": "true"}, | ||
| existingEnvVars: nil, | ||
| expectedEnvVars: nil, | ||
| }, | ||
| { | ||
| name: "jira-write with non-true value does not set env var", | ||
| configMapData: map[string]string{"jira-write": "yes"}, | ||
| existingEnvVars: nil, | ||
| expectedEnvVars: nil, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // Create fake K8s client | ||
| var k8sClient *fake.Clientset | ||
| if tt.configMapData != nil { | ||
| configMap := &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "feature-flag-overrides", | ||
| Namespace: "test-namespace", | ||
| }, | ||
| Data: tt.configMapData, | ||
| } | ||
| k8sClient = fake.NewSimpleClientset(configMap) | ||
| } else { | ||
| k8sClient = fake.NewSimpleClientset() | ||
| } | ||
|
|
||
| // Create template with optional existing env vars | ||
| template := map[string]interface{}{ | ||
| "spec": map[string]interface{}{}, | ||
| } | ||
| if tt.existingEnvVars != nil { | ||
| spec := template["spec"].(map[string]interface{}) | ||
| spec["environmentVariables"] = tt.existingEnvVars | ||
| } | ||
|
Comment on lines
+181
to
+187
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test fixture uses a nested
Suggested fix- template := map[string]interface{}{
- "spec": map[string]interface{}{},
- }
+ template := map[string]interface{}{}
if tt.existingEnvVars != nil {
- spec := template["spec"].(map[string]interface{})
- spec["environmentVariables"] = tt.existingEnvVars
+ template["environmentVariables"] = tt.existingEnvVars
}
@@
- spec, ok := template["spec"].(map[string]interface{})
- if !ok {
- t.Fatal("template[spec] is not a map")
- }
-
- envVars, ok := spec["environmentVariables"].(map[string]interface{})
+ envVars, ok := template["environmentVariables"].(map[string]interface{})
if tt.expectedEnvVars == nil {Also applies to: 195-210 🤖 Prompt for AI Agents |
||
|
|
||
| // Apply feature flag overrides | ||
| ctx := context.Background() | ||
| err := applyFeatureFlagOverrides(ctx, k8sClient, "test-namespace", template) | ||
| if err != nil { | ||
| t.Fatalf("applyFeatureFlagOverrides() unexpected error: %v", err) | ||
| } | ||
|
|
||
| // Verify environment variables | ||
| spec, ok := template["spec"].(map[string]interface{}) | ||
| if !ok { | ||
| t.Fatal("template[spec] is not a map") | ||
| } | ||
|
|
||
| envVars, ok := spec["environmentVariables"].(map[string]interface{}) | ||
| if tt.expectedEnvVars == nil { | ||
| if envVars != nil && len(envVars) > 0 { | ||
| t.Errorf("Expected no environmentVariables, got %v", envVars) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| if !ok { | ||
| t.Fatal("spec[environmentVariables] is not a map") | ||
| } | ||
|
|
||
| if len(envVars) != len(tt.expectedEnvVars) { | ||
| t.Errorf("environmentVariables count = %d, want %d", len(envVars), len(tt.expectedEnvVars)) | ||
| } | ||
|
|
||
| for key, expectedVal := range tt.expectedEnvVars { | ||
| actualVal, exists := envVars[key] | ||
| if !exists { | ||
| t.Errorf("environmentVariables[%q] missing, want %q", key, expectedVal) | ||
| continue | ||
| } | ||
| if actualVal != expectedVal { | ||
| t.Errorf("environmentVariables[%q] = %q, want %q", key, actualVal, expectedVal) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
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.
Feature-flag override is written to the wrong object level (
spec.spec).templateis already the AgenticSession spec (Line 337 sets"spec": template), but this function writes totemplate["spec"]["environmentVariables"]. That producesspec.spec.environmentVariables, soJIRA_READ_ONLY_MODEwon’t be applied where runtime expects it.Suggested fix
Also applies to: 337-337
🤖 Prompt for AI Agents