Skip to content

Commit 0597c7a

Browse files
committed
fix: Keep legacy discovery ConfigMaps in sync
Signed-off-by: Serj <107816087+uberstoic@users.noreply.github.com>
1 parent 2fc42d1 commit 0597c7a

4 files changed

Lines changed: 552 additions & 233 deletions

File tree

‎infra/feast-operator/docs/namespace-registry.md‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@ The Feast Namespace Registry is a feature that automatically creates and maintai
88

99
1. **ConfigMap Creation**: The operator creates a ConfigMap in the appropriate namespace:
1010
- **OpenShift AI**: `redhat-ods-applications` namespace (or DSCi configured namespace)
11-
- **Kubernetes**: `feast-operator-system` namespace
11+
- **Kubernetes**: the namespace where the operator is installed, unless `FEAST_OPERATOR_NAMESPACE` is set
1212

1313
2. **Access Control**: A RoleBinding is created to allow `system:authenticated` users to read the ConfigMap
1414

1515
3. **Automatic Registration & Cleanup**: When a new feature store instance is created, it automatically registers its namespace and client configuration in the ConfigMap. When deleted, it automatically removes its entry from the ConfigMap
1616

1717
4. **Data Structure**: The ConfigMap contains a JSON structure with namespace names as keys and lists of client configuration names as values
1818

19+
### Upgrade Compatibility
20+
21+
For Kubernetes upgrades, if the legacy `feast-configs-registry` ConfigMap already exists in
22+
`feast-operator-system`, the operator continues updating and cleaning up its FeatureStore entries
23+
there as well as in its current namespace. The same compatibility behavior applies to an existing
24+
`feast-openlineage-config` ConfigMap. This keeps clients that still read the legacy location current.
25+
This compatibility lookup only recognizes the legacy `feast-operator-system` namespace; ConfigMaps
26+
in other historical custom namespaces are not discovered automatically.
27+
28+
These ConfigMaps are shared and are not deleted by the operator. Migrate readers before manually
29+
retiring a legacy ConfigMap, and verify that no other operator instance still uses it.
30+
1931
### ConfigMap Structure
2032

2133
The namespace registry ConfigMap (`feast-configs-registry`) contains the following data:
@@ -42,10 +54,13 @@ External applications can discover Feast instances by:
4254
# For OpenShift
4355
kubectl get configmap feast-configs-registry -n redhat-ods-applications -o jsonpath='{.data.namespaces}'
4456

45-
# For Kubernetes
46-
kubectl get configmap feast-configs-registry -n feast-operator-system -o jsonpath='{.data.namespaces}'
57+
# For Kubernetes, use the namespace where the operator is installed
58+
kubectl get configmap feast-configs-registry -n <operator-namespace> -o jsonpath='{.data.namespaces}'
4759
```
4860

61+
During an upgrade, clients may continue reading `feast-operator-system` while its legacy
62+
ConfigMap exists; the operator keeps that ConfigMap's FeatureStore entries current.
63+
4964
### Lifecycle Management
5065

5166
The namespace registry automatically manages the lifecycle of feature store instances:
@@ -54,5 +69,3 @@ The namespace registry automatically manages the lifecycle of feature store inst
5469
2. **Updates**: If a feature store is updated, its entry remains in the ConfigMap
5570
3. **Deletion**: When a feature store is deleted, its entry is automatically removed from the ConfigMap
5671
4. **Namespace Cleanup**: If all feature stores in a namespace are deleted, the namespace entry is also removed
57-
58-
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
/*
2+
Copyright 2026 Feast Community.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package services
18+
19+
import (
20+
"context"
21+
"encoding/json"
22+
"testing"
23+
24+
feastdevv1 "github.com/feast-dev/feast/infra/feast-operator/api/v1"
25+
"github.com/feast-dev/feast/infra/feast-operator/internal/controller/handler"
26+
corev1 "k8s.io/api/core/v1"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/apimachinery/pkg/runtime"
29+
"sigs.k8s.io/controller-runtime/pkg/client"
30+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
31+
)
32+
33+
const (
34+
migrationTestOperatorNamespace = "ml-platform"
35+
migrationTestStoreNamespace = "team-a"
36+
migrationTestStoreName = "fraud"
37+
migrationTestClientConfig = "feast-fraud-client"
38+
)
39+
40+
func newDiscoveryMigrationServices(t *testing.T, featureStore *feastdevv1.FeatureStore, objects ...client.Object) (*FeastServices, client.Client) {
41+
t.Helper()
42+
t.Setenv("FEAST_OPERATOR_NAMESPACE", migrationTestOperatorNamespace)
43+
t.Setenv("POD_NAMESPACE", "")
44+
45+
previousIsOpenShift := isOpenShift
46+
isOpenShift = false
47+
t.Cleanup(func() {
48+
isOpenShift = previousIsOpenShift
49+
})
50+
51+
scheme := runtime.NewScheme()
52+
if err := corev1.AddToScheme(scheme); err != nil {
53+
t.Fatalf("add core scheme: %v", err)
54+
}
55+
56+
k8sClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(objects...).Build()
57+
feast := &FeastServices{
58+
Handler: handler.FeastHandler{
59+
Client: k8sClient,
60+
Context: context.Background(),
61+
FeatureStore: featureStore,
62+
},
63+
}
64+
return feast, k8sClient
65+
}
66+
67+
func namespaceRegistryConfigMap(t *testing.T, namespace string, data NamespaceRegistryData) *corev1.ConfigMap {
68+
t.Helper()
69+
encoded, err := json.Marshal(data)
70+
if err != nil {
71+
t.Fatalf("marshal namespace registry data: %v", err)
72+
}
73+
return &corev1.ConfigMap{
74+
ObjectMeta: metav1.ObjectMeta{
75+
Name: NamespaceRegistryConfigMapName,
76+
Namespace: namespace,
77+
},
78+
Data: map[string]string{NamespaceRegistryDataKey: string(encoded)},
79+
}
80+
}
81+
82+
func openLineageConfigMap(t *testing.T, namespace string, data OpenLineageDiscoveryData) *corev1.ConfigMap {
83+
t.Helper()
84+
encoded, err := json.Marshal(data)
85+
if err != nil {
86+
t.Fatalf("marshal OpenLineage discovery data: %v", err)
87+
}
88+
return &corev1.ConfigMap{
89+
ObjectMeta: metav1.ObjectMeta{
90+
Name: OpenLineageDiscoveryConfigMapName,
91+
Namespace: namespace,
92+
},
93+
Data: map[string]string{OpenLineageDiscoveryEndpointsKey: string(encoded)},
94+
}
95+
}
96+
97+
func readNamespaceRegistry(t *testing.T, k8sClient client.Client, namespace string) NamespaceRegistryData {
98+
t.Helper()
99+
cm := &corev1.ConfigMap{}
100+
if err := k8sClient.Get(context.Background(), client.ObjectKey{
101+
Name: NamespaceRegistryConfigMapName,
102+
Namespace: namespace,
103+
}, cm); err != nil {
104+
t.Fatalf("get namespace registry from %s: %v", namespace, err)
105+
}
106+
107+
var data NamespaceRegistryData
108+
if err := json.Unmarshal([]byte(cm.Data[NamespaceRegistryDataKey]), &data); err != nil {
109+
t.Fatalf("unmarshal namespace registry from %s: %v", namespace, err)
110+
}
111+
return data
112+
}
113+
114+
func readOpenLineageDiscovery(t *testing.T, k8sClient client.Client, namespace string) OpenLineageDiscoveryData {
115+
t.Helper()
116+
cm := &corev1.ConfigMap{}
117+
if err := k8sClient.Get(context.Background(), client.ObjectKey{
118+
Name: OpenLineageDiscoveryConfigMapName,
119+
Namespace: namespace,
120+
}, cm); err != nil {
121+
t.Fatalf("get OpenLineage discovery from %s: %v", namespace, err)
122+
}
123+
124+
var data OpenLineageDiscoveryData
125+
if err := json.Unmarshal([]byte(cm.Data[OpenLineageDiscoveryEndpointsKey]), &data); err != nil {
126+
t.Fatalf("unmarshal OpenLineage discovery from %s: %v", namespace, err)
127+
}
128+
return data
129+
}
130+
131+
func TestNamespaceRegistryKeepsLegacyConfigMapCurrent(t *testing.T) {
132+
featureStore := &feastdevv1.FeatureStore{
133+
ObjectMeta: metav1.ObjectMeta{
134+
Name: migrationTestStoreName,
135+
Namespace: migrationTestStoreNamespace,
136+
},
137+
Status: feastdevv1.FeatureStoreStatus{
138+
ClientConfigMap: migrationTestClientConfig,
139+
},
140+
}
141+
currentConfigMap := namespaceRegistryConfigMap(t, migrationTestOperatorNamespace, NamespaceRegistryData{
142+
Namespaces: map[string][]string{"existing": {"current-client"}},
143+
})
144+
legacyConfigMap := namespaceRegistryConfigMap(t, DefaultKubernetesNamespace, NamespaceRegistryData{
145+
Namespaces: map[string][]string{
146+
"existing": {"legacy-client"},
147+
migrationTestStoreNamespace: {migrationTestClientConfig},
148+
},
149+
})
150+
feast, k8sClient := newDiscoveryMigrationServices(t, featureStore, currentConfigMap, legacyConfigMap)
151+
152+
if err := feast.AddToNamespaceRegistry(); err != nil {
153+
t.Fatalf("add FeatureStore to namespace registry: %v", err)
154+
}
155+
for _, namespace := range []string{migrationTestOperatorNamespace, DefaultKubernetesNamespace} {
156+
data := readNamespaceRegistry(t, k8sClient, namespace)
157+
if got := data.Namespaces[migrationTestStoreNamespace]; len(got) != 1 || got[0] != migrationTestClientConfig {
158+
t.Errorf("registry in %s has %v, want the new client config", namespace, got)
159+
}
160+
if got := data.Namespaces["existing"]; len(got) != 1 {
161+
t.Errorf("registry in %s lost existing entries: %v", namespace, got)
162+
}
163+
}
164+
165+
if err := feast.RemoveFromNamespaceRegistry(); err != nil {
166+
t.Fatalf("remove FeatureStore from namespace registry: %v", err)
167+
}
168+
for _, namespace := range []string{migrationTestOperatorNamespace, DefaultKubernetesNamespace} {
169+
data := readNamespaceRegistry(t, k8sClient, namespace)
170+
if _, found := data.Namespaces[migrationTestStoreNamespace]; found {
171+
t.Errorf("registry in %s still contains the deleted FeatureStore", namespace)
172+
}
173+
if got := data.Namespaces["existing"]; len(got) != 1 {
174+
t.Errorf("registry in %s lost unrelated entries: %v", namespace, got)
175+
}
176+
}
177+
}
178+
179+
func TestOpenLineageDiscoveryKeepsLegacyConfigMapCurrent(t *testing.T) {
180+
featureStore := &feastdevv1.FeatureStore{
181+
ObjectMeta: metav1.ObjectMeta{
182+
Name: migrationTestStoreName,
183+
Namespace: migrationTestStoreNamespace,
184+
},
185+
Status: feastdevv1.FeatureStoreStatus{
186+
Applied: feastdevv1.FeatureStoreSpec{
187+
OpenLineage: &feastdevv1.OpenLineageConfig{
188+
Consumer: &feastdevv1.OpenLineageConsumerConfig{
189+
Enabled: true,
190+
LineageServer: &feastdevv1.LineageServerConfig{},
191+
},
192+
},
193+
},
194+
},
195+
}
196+
otherKey := "team-b/other"
197+
otherConsumer := OpenLineageEndpointInfo{
198+
URL: "http://other.svc:6580",
199+
Endpoint: "api/v1/lineage",
200+
}
201+
storeKey := migrationTestStoreNamespace + "/" + migrationTestStoreName
202+
initialData := OpenLineageDiscoveryData{
203+
Consumers: map[string]OpenLineageEndpointInfo{
204+
otherKey: otherConsumer,
205+
storeKey: {
206+
URL: "http://old-fraud.svc:6580",
207+
Endpoint: "api/v1/lineage",
208+
},
209+
},
210+
}
211+
currentConfigMap := openLineageConfigMap(t, migrationTestOperatorNamespace, initialData)
212+
legacyConfigMap := openLineageConfigMap(t, DefaultKubernetesNamespace, initialData)
213+
feast, k8sClient := newDiscoveryMigrationServices(t, featureStore, currentConfigMap, legacyConfigMap)
214+
215+
if err := feast.AddToOpenLineageDiscovery(); err != nil {
216+
t.Fatalf("add FeatureStore to OpenLineage discovery: %v", err)
217+
}
218+
for _, namespace := range []string{migrationTestOperatorNamespace, DefaultKubernetesNamespace} {
219+
data := readOpenLineageDiscovery(t, k8sClient, namespace)
220+
if got := data.Consumers[storeKey]; got.URL == "" || got.Endpoint != "api/v1/lineage" {
221+
t.Errorf("OpenLineage discovery in %s has no updated entry for %s: %+v", namespace, storeKey, got)
222+
}
223+
if got := data.Consumers[otherKey]; got != otherConsumer {
224+
t.Errorf("OpenLineage discovery in %s changed unrelated consumer: %+v", namespace, got)
225+
}
226+
}
227+
228+
if err := feast.RemoveFromOpenLineageDiscovery(); err != nil {
229+
t.Fatalf("remove FeatureStore from OpenLineage discovery: %v", err)
230+
}
231+
for _, namespace := range []string{migrationTestOperatorNamespace, DefaultKubernetesNamespace} {
232+
data := readOpenLineageDiscovery(t, k8sClient, namespace)
233+
if _, found := data.Consumers[storeKey]; found {
234+
t.Errorf("OpenLineage discovery in %s still contains the deleted FeatureStore", namespace)
235+
}
236+
if got := data.Consumers[otherKey]; got != otherConsumer {
237+
t.Errorf("OpenLineage discovery in %s lost unrelated consumers: %+v", namespace, got)
238+
}
239+
}
240+
}
241+
242+
func TestDiscoveryConfigMapNamespacesSkipsAbsentLegacyMap(t *testing.T) {
243+
feast, _ := newDiscoveryMigrationServices(t, &feastdevv1.FeatureStore{})
244+
namespaces, err := feast.discoveryConfigMapNamespaces(migrationTestOperatorNamespace, NamespaceRegistryConfigMapName)
245+
if err != nil {
246+
t.Fatalf("get discovery namespaces: %v", err)
247+
}
248+
if len(namespaces) != 1 || namespaces[0] != migrationTestOperatorNamespace {
249+
t.Fatalf("got namespaces %v, want only %q", namespaces, migrationTestOperatorNamespace)
250+
}
251+
}

0 commit comments

Comments
 (0)