Skip to content

Commit

Permalink
Add workspaceId to policy_yaml (accuknox#629)
Browse files Browse the repository at this point in the history
Signed-off-by: Eswar Rajan Subramanian <eswar@accuknox.com>
  • Loading branch information
seswarrajan authored and Prateeknandle committed Jan 12, 2023
1 parent f5401eb commit 9e02fba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
30 changes: 16 additions & 14 deletions src/networkpolicy/networkPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2247,13 +2247,14 @@ func writeNetworkPoliciesYamlToDB(policies []types.KnoxNetworkPolicy) {
}

policyYaml := types.PolicyYaml{
Type: types.PolicyTypeNetwork,
Kind: np.Kind,
Name: np.Name,
Namespace: np.Namespace,
Cluster: clusters[i],
Labels: np.Labels,
Yaml: yamlBytes,
Type: types.PolicyTypeNetwork,
Kind: np.Kind,
Name: np.Name,
Namespace: np.Namespace,
WorkspaceId: cfg.GetCfgWorkspaceId(),
Cluster: clusters[i],
Labels: np.Labels,
Yaml: yamlBytes,
}
res = append(res, policyYaml)

Expand Down Expand Up @@ -2285,13 +2286,14 @@ func writeNetworkPoliciesYamlToDB(policies []types.KnoxNetworkPolicy) {
}

policyYaml := types.PolicyYaml{
Type: types.PolicyTypeNetwork,
Kind: ciliumPolicy.Kind,
Name: ciliumPolicy.Metadata["name"],
Namespace: ciliumPolicy.Metadata["namespace"],
Cluster: clusters[i],
Labels: labels,
Yaml: yamlBytes,
Type: types.PolicyTypeNetwork,
Kind: ciliumPolicy.Kind,
Name: ciliumPolicy.Metadata["name"],
Namespace: ciliumPolicy.Metadata["namespace"],
Cluster: clusters[i],
WorkspaceId: cfg.GetCfgWorkspaceId(),
Labels: labels,
Yaml: yamlBytes,
}
res = append(res, policyYaml)

Expand Down
15 changes: 8 additions & 7 deletions src/systempolicy/systemPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,13 +1398,14 @@ func insertSysPoliciesYamlToDB(policies []types.KnoxSystemPolicy) {
}

policyYaml := types.PolicyYaml{
Type: types.PolicyTypeSystem,
Kind: kubearmorPolicy.Kind,
Name: kubearmorPolicy.Metadata["name"],
Namespace: kubearmorPolicy.Metadata["namespace"],
Cluster: clusters[i],
Labels: kubearmorPolicy.Spec.Selector.MatchLabels,
Yaml: yamlBytes,
Type: types.PolicyTypeSystem,
Kind: kubearmorPolicy.Kind,
Name: kubearmorPolicy.Metadata["name"],
Namespace: kubearmorPolicy.Metadata["namespace"],
Cluster: clusters[i],
WorkspaceId: cfg.GetCfgWorkspaceId(),
Labels: kubearmorPolicy.Spec.Selector.MatchLabels,
Yaml: yamlBytes,
}
res = append(res, policyYaml)

Expand Down
15 changes: 8 additions & 7 deletions src/types/policyData.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,12 @@ type PolicyFilter struct {

// PolicyYaml stores a policy in YAML format along with its metadata
type PolicyYaml struct {
Type string `json:"type,omitempty"`
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Cluster string `json:"cluster,omitempty"`
Labels LabelMap `json:"labels,omitempty"`
Yaml []byte `json:"yaml,omitempty"`
Type string `json:"type,omitempty"`
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
Cluster string `json:"cluster,omitempty"`
WorkspaceId int32 `json:"workspace_id,omitempty"`
Labels LabelMap `json:"labels,omitempty"`
Yaml []byte `json:"yaml,omitempty"`
}

0 comments on commit 9e02fba

Please sign in to comment.