{"action":"created","comment":{"url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/comments/168640196","pull_request_review_id":97043696,"id":168640196,"diff_hunk":"@@ -3,10 +3,42 @@ package ovn\n import (\n \t\"github.com/Sirupsen/logrus\"\n \tkapi \"k8s.io/api/core/v1\"\n+\t\"os/exec\"\n+\t\"strings\"\n \t\"sync\"\n \t\"time\"\n )\n \n+func (oc *Controller) syncNamespaces(namespaces []interface{}) {\n+\texpectedNs := make(map[string]bool)\n+\tfor _, nsInterface := range namespaces {\n+\t\tns, ok := nsInterface.(*kapi.Namespace)\n+\t\tif !ok {\n+\t\t\tlogrus.Errorf(\"Spurious object in syncNamespaces: %v\", nsInterface)\n+\t\t\tcontinue\n+\t\t}\n+\t\texpectedNs[ns.Name] = true\n+\t}\n+\t// get the list of address sets from OVN\n+\toutput, err := exec.Command(OvnNbctl, \"--data=bare\", \"--no-heading\",","path":"go-controller/pkg/ovn/namespace.go","position":21,"original_position":21,"commit_id":"e6d35f5f3c901ce69f0b4f50d5f55a7d801f5af0","original_commit_id":"e6d35f5f3c901ce69f0b4f50d5f55a7d801f5af0","user":{"login":"dcbw","id":10926354,"avatar_url":"https://avatars2.githubusercontent.com/u/10926354?v=4","gravatar_id":"","url":"https://api.github.com/users/dcbw","html_url":"https://github.com/dcbw","followers_url":"https://api.github.com/users/dcbw/followers","following_url":"https://api.github.com/users/dcbw/following{/other_user}","gists_url":"https://api.github.com/users/dcbw/gists{/gist_id}","starred_url":"https://api.github.com/users/dcbw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcbw/subscriptions","organizations_url":"https://api.github.com/users/dcbw/orgs","repos_url":"https://api.github.com/users/dcbw/repos","events_url":"https://api.github.com/users/dcbw/events{/privacy}","received_events_url":"https://api.github.com/users/dcbw/received_events","type":"User","site_admin":false},"body":"For this bit, and the same code in syncNetworkPolicies(), I was going to suggest making a discrete function for enumerating the address_sets, something like:\r\n\r\n```golang\r\nfunc forEachAddressSet(iteratorFn func(string, string, string)) error {\r\n    output, err := exec.Command(OvnNbctl, \"--data=bare\", \"--no-heading\",\r\n        \"--columns=external_ids\", \"find\", \"address_set\").Output()\r\n    if err != nil {\r\n        logrus.Errorf(\"Error in obtaining list of address sets from OVN: %v\", err)\r\n        return\r\n    }\r\n\r\n    for _, addrSet := range strings.Fields(string(output)) {\r\n        if !strings.HasPrefix(addrSet, \"name=\") {\r\n            continue\r\n        }\r\n        addrSetName := addrSet[5:]\r\n        names := strings.Split(addrSetName, \".\")\r\n        asNamespace := names[0]\r\n        asName := \"\"\r\n        if len(names) >= 2 {\r\n            asName = names[1]\r\n        }\r\n        iteratorFn(addrSetName, asNamespace, asName)\r\n    }\r\n    return nil\r\n}\r\n\r\n    err := forEachAddressSet(func(addrSetName, asNamespace, asName string) error {\r\n        if asName == \"\" && !isDefaultKubeNamespace(asNamespace) && !expectedNs[asNamespace] {\r\n            // delete the address sets for this policy from OVN\r\n           oc.deleteAddressSet(hashedAddressSet(addrSetName))\r\n        }\r\n    })\r\n\r\n    err := forEachAddressSet(func(addrSetName, asNamespace, asName string) error {\r\n        if asName != \"\" && !expectedPolicies[asNamespace][asName] {\r\n            // policy doesn't exist on k8s delete acl rules from OVN\r\n            oc.deleteAclsPolicy(asNamespace, asName)\r\n            // delete the address sets for this policy from OVN\r\n            oc.deleteAddressSet(hashedAddressSet(addrSetName))\r\n    }\r\n```\r\n\r\nOr something like that.  It would consolidate the address_set parsing code and simplify each location that uses addres sets.","created_at":"2018-02-15T23:28:22Z","updated_at":"2018-02-15T23:28:22Z","html_url":"https://github.com/openvswitch/ovn-kubernetes/pull/227#discussion_r168640196","pull_request_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/227","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/comments/168640196"},"html":{"href":"https://github.com/openvswitch/ovn-kubernetes/pull/227#discussion_r168640196"},"pull_request":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/227"}}},"pull_request":{"url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/227","id":168997621,"html_url":"https://github.com/openvswitch/ovn-kubernetes/pull/227","diff_url":"https://github.com/openvswitch/ovn-kubernetes/pull/227.diff","patch_url":"https://github.com/openvswitch/ovn-kubernetes/pull/227.patch","issue_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/issues/227","number":227,"state":"open","locked":false,"title":"[WIP]Sync k8s resources with OVN backend when watcher starts","user":{"login":"tong101","id":5994086,"avatar_url":"https://avatars3.githubusercontent.com/u/5994086?v=4","gravatar_id":"","url":"https://api.github.com/users/tong101","html_url":"https://github.com/tong101","followers_url":"https://api.github.com/users/tong101/followers","following_url":"https://api.github.com/users/tong101/following{/other_user}","gists_url":"https://api.github.com/users/tong101/gists{/gist_id}","starred_url":"https://api.github.com/users/tong101/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tong101/subscriptions","organizations_url":"https://api.github.com/users/tong101/orgs","repos_url":"https://api.github.com/users/tong101/repos","events_url":"https://api.github.com/users/tong101/events{/privacy}","received_events_url":"https://api.github.com/users/tong101/received_events","type":"User","site_admin":false},"body":"When ovnkube watcher starts, sync k8s resources with OVN backend\r\nincluding pods, policies, and namespaces. If there is any obsolete\r\nresource left on OVN after k8s resource has been deleted, clean up\r\nthe stale resource from OVN.\r\n\r\nSigned-off-by: Tong Liu <tongl@vmware.com>","created_at":"2018-02-14T00:59:09Z","updated_at":"2018-02-15T23:28:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3890d4ffd473db463a14384dee0fa469288263e3","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/227/commits","review_comments_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/227/comments","review_comment_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/issues/227/comments","statuses_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/statuses/e6d35f5f3c901ce69f0b4f50d5f55a7d801f5af0","head":{"label":"tong101:sync","ref":"sync","sha":"e6d35f5f3c901ce69f0b4f50d5f55a7d801f5af0","user":{"login":"tong101","id":5994086,"avatar_url":"https://avatars3.githubusercontent.com/u/5994086?v=4","gravatar_id":"","url":"https://api.github.com/users/tong101","html_url":"https://github.com/tong101","followers_url":"https://api.github.com/users/tong101/followers","following_url":"https://api.github.com/users/tong101/following{/other_user}","gists_url":"https://api.github.com/users/tong101/gists{/gist_id}","starred_url":"https://api.github.com/users/tong101/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tong101/subscriptions","organizations_url":"https://api.github.com/users/tong101/orgs","repos_url":"https://api.github.com/users/tong101/repos","events_url":"https://api.github.com/users/tong101/events{/privacy}","received_events_url":"https://api.github.com/users/tong101/received_events","type":"User","site_admin":false},"repo":{"id":114818012,"name":"ovn-kubernetes","full_name":"tong101/ovn-kubernetes","owner":{"login":"tong101","id":5994086,"avatar_url":"https://avatars3.githubusercontent.com/u/5994086?v=4","gravatar_id":"","url":"https://api.github.com/users/tong101","html_url":"https://github.com/tong101","followers_url":"https://api.github.com/users/tong101/followers","following_url":"https://api.github.com/users/tong101/following{/other_user}","gists_url":"https://api.github.com/users/tong101/gists{/gist_id}","starred_url":"https://api.github.com/users/tong101/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tong101/subscriptions","organizations_url":"https://api.github.com/users/tong101/orgs","repos_url":"https://api.github.com/users/tong101/repos","events_url":"https://api.github.com/users/tong101/events{/privacy}","received_events_url":"https://api.github.com/users/tong101/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tong101/ovn-kubernetes","description":"Kubernetes integration for OVN","fork":true,"url":"https://api.github.com/repos/tong101/ovn-kubernetes","forks_url":"https://api.github.com/repos/tong101/ovn-kubernetes/forks","keys_url":"https://api.github.com/repos/tong101/ovn-kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tong101/ovn-kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tong101/ovn-kubernetes/teams","hooks_url":"https://api.github.com/repos/tong101/ovn-kubernetes/hooks","issue_events_url":"https://api.github.com/repos/tong101/ovn-kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/tong101/ovn-kubernetes/events","assignees_url":"https://api.github.com/repos/tong101/ovn-kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/tong101/ovn-kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/tong101/ovn-kubernetes/tags","blobs_url":"https://api.github.com/repos/tong101/ovn-kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tong101/ovn-kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tong101/ovn-kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/tong101/ovn-kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tong101/ovn-kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/tong101/ovn-kubernetes/languages","stargazers_url":"https://api.github.com/repos/tong101/ovn-kubernetes/stargazers","contributors_url":"https://api.github.com/repos/tong101/ovn-kubernetes/contributors","subscribers_url":"https://api.github.com/repos/tong101/ovn-kubernetes/subscribers","subscription_url":"https://api.github.com/repos/tong101/ovn-kubernetes/subscription","commits_url":"https://api.github.com/repos/tong101/ovn-kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/tong101/ovn-kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/tong101/ovn-kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/tong101/ovn-kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/tong101/ovn-kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/tong101/ovn-kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tong101/ovn-kubernetes/merges","archive_url":"https://api.github.com/repos/tong101/ovn-kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tong101/ovn-kubernetes/downloads","issues_url":"https://api.github.com/repos/tong101/ovn-kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/tong101/ovn-kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/tong101/ovn-kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/tong101/ovn-kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tong101/ovn-kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/tong101/ovn-kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/tong101/ovn-kubernetes/deployments","created_at":"2017-12-19T22:38:43Z","updated_at":"2017-12-19T22:38:45Z","pushed_at":"2018-02-14T22:41:04Z","git_url":"git://github.com/tong101/ovn-kubernetes.git","ssh_url":"git@github.com:tong101/ovn-kubernetes.git","clone_url":"https://github.com/tong101/ovn-kubernetes.git","svn_url":"https://github.com/tong101/ovn-kubernetes","homepage":null,"size":15056,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openvswitch:master","ref":"master","sha":"dee20d9ae0f9fc16e12ca5a96a2c6d4fea9c4260","user":{"login":"openvswitch","id":7143863,"avatar_url":"https://avatars3.githubusercontent.com/u/7143863?v=4","gravatar_id":"","url":"https://api.github.com/users/openvswitch","html_url":"https://github.com/openvswitch","followers_url":"https://api.github.com/users/openvswitch/followers","following_url":"https://api.github.com/users/openvswitch/following{/other_user}","gists_url":"https://api.github.com/users/openvswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/openvswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openvswitch/subscriptions","organizations_url":"https://api.github.com/users/openvswitch/orgs","repos_url":"https://api.github.com/users/openvswitch/repos","events_url":"https://api.github.com/users/openvswitch/events{/privacy}","received_events_url":"https://api.github.com/users/openvswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":65489927,"name":"ovn-kubernetes","full_name":"openvswitch/ovn-kubernetes","owner":{"login":"openvswitch","id":7143863,"avatar_url":"https://avatars3.githubusercontent.com/u/7143863?v=4","gravatar_id":"","url":"https://api.github.com/users/openvswitch","html_url":"https://github.com/openvswitch","followers_url":"https://api.github.com/users/openvswitch/followers","following_url":"https://api.github.com/users/openvswitch/following{/other_user}","gists_url":"https://api.github.com/users/openvswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/openvswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openvswitch/subscriptions","organizations_url":"https://api.github.com/users/openvswitch/orgs","repos_url":"https://api.github.com/users/openvswitch/repos","events_url":"https://api.github.com/users/openvswitch/events{/privacy}","received_events_url":"https://api.github.com/users/openvswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openvswitch/ovn-kubernetes","description":"Kubernetes integration for OVN","fork":false,"url":"https://api.github.com/repos/openvswitch/ovn-kubernetes","forks_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/forks","keys_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/teams","hooks_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/hooks","issue_events_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/events","assignees_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/tags","blobs_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/languages","stargazers_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/stargazers","contributors_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/contributors","subscribers_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/subscribers","subscription_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/subscription","commits_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/merges","archive_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/downloads","issues_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/openvswitch/ovn-kubernetes/deployments","created_at":"2016-08-11T17:51:02Z","updated_at":"2018-02-09T13:12:57Z","pushed_at":"2018-02-15T22:53:45Z","git_url":"git://github.com/openvswitch/ovn-kubernetes.git","ssh_url":"git@github.com:openvswitch/ovn-kubernetes.git","clone_url":"https://github.com/openvswitch/ovn-kubernetes.git","svn_url":"https://github.com/openvswitch/ovn-kubernetes","homepage":null,"size":15067,"stargazers_count":100,"watchers_count":100,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":65,"mirror_url":null,"archived":false,"open_issues_count":29,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":65,"open_issues":29,"watchers":100,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/227"},"html":{"href":"https://github.com/openvswitch/ovn-kubernetes/pull/227"},"issue":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/issues/227"},"comments":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/issues/227/comments"},"review_comments":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/227/comments"},"review_comment":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/pulls/227/commits"},"statuses":{"href":"https://api.github.com/repos/openvswitch/ovn-kubernetes/statuses/e6d35f5f3c901ce69f0b4f50d5f55a7d801f5af0"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"dcbw"}}