From 732865f20e7fae7a46f54be7bc469ce2b3bc44e2 Mon Sep 17 00:00:00 2001 From: lokeshrangineni <19699092+lokeshrangineni@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:24:33 -0700 Subject: [PATCH] feat: Go Operator - Parsing the output to go structs (#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> --- infra/feast-operator/test/e2e/e2e_test.go | 3 +- infra/feast-operator/test/e2e/test_util.go | 54 +++++----------------- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/infra/feast-operator/test/e2e/e2e_test.go b/infra/feast-operator/test/e2e/e2e_test.go index 23637ff224..fdf58d8f3b 100644 --- a/infra/feast-operator/test/e2e/e2e_test.go +++ b/infra/feast-operator/test/e2e/e2e_test.go @@ -124,10 +124,11 @@ var _ = Describe("controller", Ordered, func() { validateTheFeatureStoreCustomResource(namespace, featureStoreName, timeout) var remoteRegistryNs = "remote-registry" + By(fmt.Sprintf("Creating the remote registry namespace=%s", remoteRegistryNs)) cmd = exec.Command("kubectl", "create", "ns", remoteRegistryNs) _, _ = utils.Run(cmd) - By("deploying the Simple Feast remote registry Custom Resource to Kubernetes") + By("deploying the Simple Feast remote registry Custom Resource on Kubernetes") cmd = exec.Command("kubectl", "apply", "-f", "test/testdata/feast_integration_test_crs/v1alpha1_remote_registry_featurestore.yaml", "-n", remoteRegistryNs) _, cmdOutputerr = utils.Run(cmd) diff --git a/infra/feast-operator/test/e2e/test_util.go b/infra/feast-operator/test/e2e/test_util.go index 7d44ac1296..d92f719fb9 100644 --- a/infra/feast-operator/test/e2e/test_util.go +++ b/infra/feast-operator/test/e2e/test_util.go @@ -9,6 +9,8 @@ import ( "strings" "time" + appsv1 "k8s.io/api/apps/v1" + "github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1" ) @@ -26,36 +28,17 @@ func checkIfFeatureStoreCustomResourceConditionsInReady(featureStoreName, namesp featureStoreName, namespace, err, stderr.String()) } - // Parse the JSON into a generic map - var resource map[string]interface{} + // Parse the JSON into FeatureStore + var resource v1alpha1.FeatureStore if err := json.Unmarshal(out.Bytes(), &resource); err != nil { return fmt.Errorf("failed to parse the resource JSON. Error: %v", err) } - // Traverse the JSON structure to extract conditions - status, ok := resource["status"].(map[string]interface{}) - if !ok { - return fmt.Errorf("status field is missing or invalid in the resource JSON") - } - - conditions, ok := status["conditions"].([]interface{}) - if !ok { - return fmt.Errorf("conditions field is missing or invalid in the status section") - } - // Validate all conditions - for _, condition := range conditions { - conditionMap, ok := condition.(map[string]interface{}) - if !ok { - return fmt.Errorf("invalid condition format") - } - - conditionType := conditionMap["type"].(string) - conditionStatus := conditionMap["status"].(string) - - if conditionStatus != "True" { + for _, condition := range resource.Status.Conditions { + if condition.Status != "True" { return fmt.Errorf(" FeatureStore=%s condition '%s' is not in 'Ready' state. Status: %s", - featureStoreName, conditionType, conditionStatus) + featureStoreName, condition.Type, condition.Status) } } @@ -87,30 +70,15 @@ func checkIfDeploymentExistsAndAvailable(namespace string, deploymentName string continue } - // Parse the JSON output into a map - var result map[string]interface{} + // Parse the JSON output into Deployment + var result appsv1.Deployment if err := json.Unmarshal(output.Bytes(), &result); err != nil { return fmt.Errorf("failed to parse deployment JSON: %v", err) } - // Navigate to status.conditions - status, ok := result["status"].(map[string]interface{}) - if !ok { - return fmt.Errorf("failed to get status field from deployment JSON") - } - - conditions, ok := status["conditions"].([]interface{}) - if !ok { - return fmt.Errorf("failed to get conditions field from deployment JSON") - } - // Check for Available condition - for _, condition := range conditions { - cond, ok := condition.(map[string]interface{}) - if !ok { - continue - } - if cond["type"] == "Available" && cond["status"] == "True" { + for _, condition := range result.Status.Conditions { + if condition.Type == "Available" && condition.Status == "True" { return nil // Deployment is available } }