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

Support annotations on Policy objects #471

Merged
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
3 changes: 3 additions & 0 deletions lib/api/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type PolicyMetadata struct {

// The name of the selector-based security policy.
Name string `json:"name,omitempty" validate:"omitempty,namespacedname"`

// Arbitrary key-value information to be used by clients.
Annotations map[string]string `json:"annotations,omitempty" validate:"omitempty"`
}

// PolicySpec contains the specification for a selector-based security Policy resource.
Expand Down
11 changes: 6 additions & 5 deletions lib/backend/model/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ func (options PolicyListOptions) KeyFromDefaultPath(path string) Key {
}

type Policy struct {
Order *float64 `json:"order,omitempty" validate:"omitempty"`
InboundRules []Rule `json:"inbound_rules,omitempty" validate:"omitempty,dive"`
OutboundRules []Rule `json:"outbound_rules,omitempty" validate:"omitempty,dive"`
Selector string `json:"selector" validate:"selector"`
DoNotTrack bool `json:"untracked,omitempty"`
Order *float64 `json:"order,omitempty" validate:"omitempty"`
InboundRules []Rule `json:"inbound_rules,omitempty" validate:"omitempty,dive"`
OutboundRules []Rule `json:"outbound_rules,omitempty" validate:"omitempty,dive"`
Selector string `json:"selector" validate:"selector"`
DoNotTrack bool `json:"untracked,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}

func (p Policy) String() string {
Expand Down
5 changes: 4 additions & 1 deletion lib/client/policy_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ var _ = testutils.E2eDatastoreDescribe("Policy tests", testutils.DatastoreEtcdV2
Expect(outError1).NotTo(HaveOccurred())
Expect(outPolicy1.Spec).To(Equal(spec2))

// Assert the Metadata for policy with meta1 matches meta1.
Expect(outPolicy1.Metadata).To(Equal(meta1))

By("List all the policies and compare")

// Get a list of policiess.
Expand Down Expand Up @@ -179,7 +182,7 @@ var _ = testutils.E2eDatastoreDescribe("Policy tests", testutils.DatastoreEtcdV2

// Test 1: Pass two fully populated PolicySpecs and expect the series of operations to succeed.
Entry("Two fully populated PolicySpecs",
api.PolicyMetadata{Name: "policy-1/with.foo"},
api.PolicyMetadata{Name: "policy-1/with.foo", Annotations: map[string]string{"key": "value"}},
api.PolicyMetadata{Name: "policy.1"},
policySpec1,
policySpec2,
Expand Down
2 changes: 2 additions & 0 deletions lib/converter/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (p PolicyConverter) ConvertAPIToKVPair(a unversioned.Resource) (*model.KVPa
OutboundRules: RulesAPIToBackend(ap.Spec.EgressRules),
Selector: ap.Spec.Selector,
DoNotTrack: ap.Spec.DoNotTrack,
Annotations: ap.Metadata.Annotations,
},
}

Expand All @@ -64,6 +65,7 @@ func (p PolicyConverter) ConvertKVPairToAPI(d *model.KVPair) (unversioned.Resour

ap := api.NewPolicy()
ap.Metadata.Name = bk.Name
ap.Metadata.Annotations = bp.Annotations
ap.Spec.Order = bp.Order
ap.Spec.IngressRules = RulesBackendToAPI(bp.InboundRules)
ap.Spec.EgressRules = RulesBackendToAPI(bp.OutboundRules)
Expand Down