Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing some comments about synthesis #133

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/symbolicexpr/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func (term atomicTerm) labelKey() string {
// todo - make sure that the label is allowed by open shift
switch term.property.(type) {
case *collector.Segment:
return "segment"
Expand Down
4 changes: 2 additions & 2 deletions pkg/synthesis/createK8sResources.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func newNetworkPolicy(name, description string) *networking.NetworkPolicy {
pol.TypeMeta.Kind = "NetworkPolicy"
pol.TypeMeta.APIVersion = k8sAPIVersion
pol.ObjectMeta.Name = name
pol.ObjectMeta.Labels = map[string]string{"description": description}
pol.ObjectMeta.Annotations = map[string]string{"description": description}
return pol
}

Expand Down Expand Up @@ -175,7 +175,7 @@ func toPods(model *AbstractModelSyn) []*core.Pod {
pod.ObjectMeta.Labels = map[string]string{}
for _, group := range model.epToGroups[vm] {
label, _ := symbolicexpr.NewAtomicTerm(group, group.Name(), false).AsSelector()
pod.ObjectMeta.Labels[label] = label
pod.ObjectMeta.Labels[label] = "true"
}
pods = append(pods, pod)
}
Expand Down
23 changes: 15 additions & 8 deletions pkg/synthesis/synthesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ func (synTest *synthesisTest) runConvertToAbstract(t *testing.T, mode testMode,
suffix = "_ConvertToAbstract.txt"
}
outDir := path.Join("out", synTest.name)
abstractModel, err := NSXToK8sSynthesis(rc, outDir, hintsParm)
require.Nil(t, err)
addDebugFiles(t, rc, abstractModel, outDir)
expectedOutputFileName := filepath.Join(getTestsDirOut(), synTest.name+suffix)
actualOutput := strAllowOnlyPolicy(abstractModel.policy[0])
fmt.Println(actualOutput)
compareOrRegenerateOutputPerTest(t, mode, actualOutput, expectedOutputFileName, synTest.name)
}
func addDebugFiles(t *testing.T, rc *collector.ResourcesContainerModel, abstractModel *AbstractModelSyn, outDir string) {
for _, format := range []string{"txt", "dot"} {
params := common.OutputParameters{
Format: format,
Expand All @@ -121,13 +130,9 @@ func (synTest *synthesisTest) runConvertToAbstract(t *testing.T, mode testMode,
err = common.WriteToFile(path.Join(outDir, "vmware_connectivity."+format), analyzed)
require.Nil(t, err)
}
abstractModel, err := NSXToK8sSynthesis(rc, outDir, hintsParm)
require.Nil(t, err)

actualOutput := strAllowOnlyPolicy(abstractModel.policy[0])
fmt.Println(actualOutput)
expectedOutputFileName := filepath.Join(getTestsDirOut(), synTest.name+suffix)
compareOrRegenerateOutputPerTest(t, mode, actualOutput, expectedOutputFileName, synTest.name)
err := common.WriteToFile(path.Join(outDir, "abstract_model.txt"), actualOutput)
require.Nil(t, err)
}

func TestCollectAndConvertToAbstract(t *testing.T) {
Expand All @@ -146,11 +151,13 @@ func TestCollectAndConvertToAbstract(t *testing.T) {
t.Errorf("didnt got resources")
return
}

abstractModel, err := NSXToK8sSynthesis(rc, path.Join("out", "from_collection"),
outDir := path.Join("out", "from_collection")
abstractModel, err := NSXToK8sSynthesis(rc, outDir,
&symbolicexpr.Hints{GroupsDisjoint: [][]string{}})
require.Nil(t, err)
fmt.Println(strAllowOnlyPolicy(abstractModel.policy[0]))
addDebugFiles(t, rc, abstractModel, outDir)
require.Nil(t, err)
}

func TestConvertToAbsract(t *testing.T) {
Expand Down
Loading