Skip to content

Commit 732865f

Browse files
feat: Go Operator - Parsing the output to go structs (feast-dev#4832)
Now parsing the output to go lang structs rather than a Map to simplify the parsing logic. Signed-off-by: lrangine <19699092+lokeshrangineni@users.noreply.github.com>
1 parent d558ef7 commit 732865f

File tree

2 files changed

+13
-44
lines changed

2 files changed

+13
-44
lines changed

infra/feast-operator/test/e2e/e2e_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ var _ = Describe("controller", Ordered, func() {
124124
validateTheFeatureStoreCustomResource(namespace, featureStoreName, timeout)
125125

126126
var remoteRegistryNs = "remote-registry"
127+
By(fmt.Sprintf("Creating the remote registry namespace=%s", remoteRegistryNs))
127128
cmd = exec.Command("kubectl", "create", "ns", remoteRegistryNs)
128129
_, _ = utils.Run(cmd)
129130

130-
By("deploying the Simple Feast remote registry Custom Resource to Kubernetes")
131+
By("deploying the Simple Feast remote registry Custom Resource on Kubernetes")
131132
cmd = exec.Command("kubectl", "apply", "-f",
132133
"test/testdata/feast_integration_test_crs/v1alpha1_remote_registry_featurestore.yaml", "-n", remoteRegistryNs)
133134
_, cmdOutputerr = utils.Run(cmd)

infra/feast-operator/test/e2e/test_util.go

+11-43
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
"time"
1111

12+
appsv1 "k8s.io/api/apps/v1"
13+
1214
"github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1"
1315
)
1416

@@ -26,36 +28,17 @@ func checkIfFeatureStoreCustomResourceConditionsInReady(featureStoreName, namesp
2628
featureStoreName, namespace, err, stderr.String())
2729
}
2830

29-
// Parse the JSON into a generic map
30-
var resource map[string]interface{}
31+
// Parse the JSON into FeatureStore
32+
var resource v1alpha1.FeatureStore
3133
if err := json.Unmarshal(out.Bytes(), &resource); err != nil {
3234
return fmt.Errorf("failed to parse the resource JSON. Error: %v", err)
3335
}
3436

35-
// Traverse the JSON structure to extract conditions
36-
status, ok := resource["status"].(map[string]interface{})
37-
if !ok {
38-
return fmt.Errorf("status field is missing or invalid in the resource JSON")
39-
}
40-
41-
conditions, ok := status["conditions"].([]interface{})
42-
if !ok {
43-
return fmt.Errorf("conditions field is missing or invalid in the status section")
44-
}
45-
4637
// Validate all conditions
47-
for _, condition := range conditions {
48-
conditionMap, ok := condition.(map[string]interface{})
49-
if !ok {
50-
return fmt.Errorf("invalid condition format")
51-
}
52-
53-
conditionType := conditionMap["type"].(string)
54-
conditionStatus := conditionMap["status"].(string)
55-
56-
if conditionStatus != "True" {
38+
for _, condition := range resource.Status.Conditions {
39+
if condition.Status != "True" {
5740
return fmt.Errorf(" FeatureStore=%s condition '%s' is not in 'Ready' state. Status: %s",
58-
featureStoreName, conditionType, conditionStatus)
41+
featureStoreName, condition.Type, condition.Status)
5942
}
6043
}
6144

@@ -87,30 +70,15 @@ func checkIfDeploymentExistsAndAvailable(namespace string, deploymentName string
8770
continue
8871
}
8972

90-
// Parse the JSON output into a map
91-
var result map[string]interface{}
73+
// Parse the JSON output into Deployment
74+
var result appsv1.Deployment
9275
if err := json.Unmarshal(output.Bytes(), &result); err != nil {
9376
return fmt.Errorf("failed to parse deployment JSON: %v", err)
9477
}
9578

96-
// Navigate to status.conditions
97-
status, ok := result["status"].(map[string]interface{})
98-
if !ok {
99-
return fmt.Errorf("failed to get status field from deployment JSON")
100-
}
101-
102-
conditions, ok := status["conditions"].([]interface{})
103-
if !ok {
104-
return fmt.Errorf("failed to get conditions field from deployment JSON")
105-
}
106-
10779
// Check for Available condition
108-
for _, condition := range conditions {
109-
cond, ok := condition.(map[string]interface{})
110-
if !ok {
111-
continue
112-
}
113-
if cond["type"] == "Available" && cond["status"] == "True" {
80+
for _, condition := range result.Status.Conditions {
81+
if condition.Type == "Available" && condition.Status == "True" {
11482
return nil // Deployment is available
11583
}
11684
}

0 commit comments

Comments
 (0)