Skip to content

Commit

Permalink
feat: Go Operator - Parsing the output to go structs (feast-dev#4832)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lokeshrangineni authored Dec 11, 2024
1 parent d558ef7 commit 732865f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 44 deletions.
3 changes: 2 additions & 1 deletion infra/feast-operator/test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 11 additions & 43 deletions infra/feast-operator/test/e2e/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"time"

appsv1 "k8s.io/api/apps/v1"

"github.com/feast-dev/feast/infra/feast-operator/api/v1alpha1"
)

Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 732865f

Please sign in to comment.