Skip to content

Commit

Permalink
Merge branch 'main' into users/xingdli/fault
Browse files Browse the repository at this point in the history
  • Loading branch information
msftcoderdjw authored Nov 22, 2024
2 parents d1964a8 + c302471 commit aaf9edd
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ func (m *CatalogConfigProvider) ReadObject(ctx context.Context, object string, l
return nil, err
}
errList := make([]error, 0)
allProperties, err := m.getCatalogPropertiesAll(ctx, catalog, namespace)
ret := map[string]interface{}{}
for k, v := range catalog.Spec.Properties {
for k, v := range allProperties {
tv, err := m.traceValue(ctx, v, localcontext, nil)
if err != nil {
// Wrap the error using fmt.Errorf("%w", err)
Expand All @@ -198,6 +199,57 @@ func (m *CatalogConfigProvider) ReadObject(ctx context.Context, object string, l
}
}

func (m *CatalogConfigProvider) getCatalogPropertiesAll(ctx context.Context, catalog model.CatalogState, namespace string) (map[string]interface{}, error) {
ret := map[string]interface{}{}
if catalog.Spec.ParentName != "" {
metaName := utils.ConvertReferenceToObjectName(catalog.Spec.ParentName)
parent, err := m.ApiClient.GetCatalog(ctx, metaName, namespace, m.Config.User, m.Config.Password)
if err != nil {
return nil, err
}
parentProperties, err := m.getCatalogPropertiesAll(ctx, parent, namespace)
if err != nil {
return nil, err
}
for k, v := range parentProperties {
ret[k] = v
}
}
for k, v := range catalog.Spec.Properties {
// we should deep extend the properties
// if the property is a map, we should deep extend the map
// if the property is a list, we should deep extend the list
// if the property is a string, we should just set the string
// if the property is a number, we should just set the number
// if the property is a boolean, we should just set the boolean
// if the property is a null, we should just set the null
ret[k] = deepExtend(ret[k], v)
}
return ret, nil
}

func deepExtend(dst, src interface{}) interface{} {
switch src := src.(type) {
case map[string]interface{}:
if dstMap, ok := dst.(map[string]interface{}); ok {
for k, v := range src {
// if the key is not in the dstMap, just set the key
if _, ok := dstMap[k]; !ok {
dstMap[k] = v
} else {
dstMap[k] = deepExtend(dstMap[k], v)
}
}
return dstMap
}
return src
case []interface{}:
return src
default:
return src
}
}

func (m *CatalogConfigProvider) traceValue(ctx context.Context, v interface{}, localcontext interface{}, dependencyList map[string]map[string]bool) (interface{}, error) {
switch val := v.(type) {
case string:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func TestReadObject(t *testing.T) {
Spec: &model.CatalogSpec{
Properties: map[string]interface{}{
"parentAttribute": "This is father",
"components": map[string]interface{}{
"Name": "notaname",
},
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions cli/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ downloadFile() {

echo "Downloading $DOWNLOAD_URL ..."
if [ "$SYMPHONY_HTTP_REQUEST_CLI" == "curl" ]; then
curl -SsL "$DOWNLOAD_URL" -o "$ARTIFACT_TMP_FILE"
curl -SL "$DOWNLOAD_URL" -o "$ARTIFACT_TMP_FILE"
else
wget -q -O "$ARTIFACT_TMP_FILE" "$DOWNLOAD_URL"
wget -O "$ARTIFACT_TMP_FILE" "$DOWNLOAD_URL"
fi

if [ ! -f "$ARTIFACT_TMP_FILE" ]; then
Expand Down
10 changes: 10 additions & 0 deletions test/integration/scenarios/10.catalogEval/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
"test/integration/scenarios/10.catalogEval/manifest/catalog-catalog.yaml",
"test/integration/scenarios/10.catalogEval/manifest/catalog-catalog2.yaml",
"test/integration/scenarios/10.catalogEval/manifest/catalog-catalog3.yaml",
"test/integration/scenarios/10.catalogEval/manifest/catalog-catalog4.yaml",
}

// Tests to run
Expand All @@ -55,6 +56,8 @@ var (
testEvalUpdate = "test/integration/scenarios/10.catalogEval/manifest/evalUpdate.yaml"

testEval03 = "test/integration/scenarios/10.catalogEval/manifest/eval03.yaml"

testEval04 = "test/integration/scenarios/10.catalogEval/manifest/eval04.yaml"
)

// Entry point for running the tests
Expand Down Expand Up @@ -138,6 +141,13 @@ func DeployManifests() error {
return err
}

// create eval catalog evaluateevalcatalog04
eval04C := filepath.Join(repoPath, testEval04)
err = shellcmd.Command(fmt.Sprintf("kubectl apply -f %s -n %s", eval04C, namespace)).Run()
if err != nil {
return err
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: federation.symphony/v1
kind: Catalog
metadata:
name: evalcatalog-v-v4
spec:
rootResource: evalcatalog
catalogType: catalog
parentName: evalcatalog:v1
properties:
city: "${{$config('evalcatalog:v2','city')}}"
country: "${{$config('evalcatalog:v2','country')}}"
from:
state: Virginia
12 changes: 12 additions & 0 deletions test/integration/scenarios/10.catalogEval/manifest/eval04.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: federation.symphony/v1
kind: CatalogEvalExpression
metadata:
name: evaluateevalcatalog04
annotations:
management.azure.com/operationId: "3"
spec:
resourceRef:
apiGroup: federation.symphony
kind: Catalog
name: evalcatalog-v-v4
namespace: default
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestBasic_Catalogs(t *testing.T) {
catalogs = append(catalogs, item.GetName())
}
fmt.Printf("Catalogs: %v\n", catalogs)
if len(resources.Items) == 3 {
if len(resources.Items) == 4 {
break
}

Expand Down Expand Up @@ -146,6 +146,50 @@ func Test_CatalogsEvals(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "Sydney", city)

// check evaluateevalcatalog04
retryWithTimeout(func() (any, error) {
evaluateevalcatalog, err = dyn.Resource(schema.GroupVersionResource{
Group: "federation.symphony",
Version: "v1",
Resource: "catalogevalexpressions",
}).Namespace(namespace).Get(context.Background(), "evaluateevalcatalog04", metav1.GetOptions{})
require.NoError(t, err)
status, _, err := unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "status")
require.NoError(t, err)
require.Contains(t, []string{"Succeeded", "Failed"}, status)
return evaluateevalcatalog, nil
}, time.Minute*1)
status, _, err = unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "output", "evaluationStatus")
require.NoError(t, err)
require.Equal(t, "Failed", status)

address, _, err = unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "output", "address")
require.NoError(t, err)
require.Equal(t, "1st Avenue", address)

city, _, err = unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "output", "city")
require.NoError(t, err)
require.Equal(t, "Sydney", city)

zipcode, _, err = unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "output", "zipcode")
require.NoError(t, err)
require.Contains(t, zipcode, "Not Found")

county, _, err = unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "output", "county")
require.NoError(t, err)
require.Contains(t, county, "Not Found")

country, _, err = unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "output", "country")
require.NoError(t, err)
require.Equal(t, "Australia", country)

fromCountry, _, err = unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "output", "from", "country")
require.NoError(t, err)
require.Equal(t, "Australia", fromCountry)

fromState, _, err := unstructured.NestedString(evaluateevalcatalog.Object, "status", "actionStatus", "output", "from", "state")
require.NoError(t, err)
require.Equal(t, "Virginia", fromState)
}

func retryWithTimeout(fn func() (any, error), timeout time.Duration) (any, error) {
Expand Down

0 comments on commit aaf9edd

Please sign in to comment.