-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Clusterwide K8s Cilium Network Policies #9381
Conversation
pkg/k8s/apis/cilium.io/v2/types.go
Outdated
// CiliumGlobalNetworkPolicy is a Kubernetes third-party resource with an extended version | ||
// of CiliumNetworkPolicy which is cluster scoped rather than namespace scoped. | ||
type CiliumGlobalNetworkPolicy struct { | ||
// +k8s:openapi-gen=false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do this we get all of the methods already implemented for CNP for free.
type CiliumGlobalNetworkPolicy struct {
CiliumNetworkPolicy
}
8dc8a24
to
800d637
Compare
8b979c5
to
79f2142
Compare
559fb57
to
2f59927
Compare
k8sAPIGroupCRD = "CustomResourceDefinition" | ||
k8sAPIGroupNodeV1Core = "core/v1::Node" | ||
k8sAPIGroupNamespaceV1Core = "core/v1::Namespace" | ||
K8sAPIGroupServiceV1Core = "core/v1::Service" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported const K8sAPIGroupServiceV1Core should have comment (or a comment on this block) or be unexported
Hi @fristonio , sorry for moving the pr from draft, I had to check something in regards to CI failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good so far only small nits. Next step CI! 💯
pkg/k8s/apis/cilium.io/v2/types.go
Outdated
// rules. This is similar to the parse function used in CiliumNetworkPolicy with | ||
// the only difference that since the CRD is cluster scoped we don't send any namespace | ||
// here. | ||
func (r *CiliumClusterwideNetworkPolicy) Parse() (api.Rules, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this removed in follow up commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
pkg/k8s/apis/cilium.io/v2/types.go
Outdated
} | ||
|
||
// GetControllerName returns the unique name for the controller manager. | ||
func (r *CiliumClusterwideNetworkPolicy) GetControllerName() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this removed in follow up commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
pkg/k8s/apis/cilium.io/v2/types.go
Outdated
} | ||
|
||
// GetIdentityLabels returns all rule labels in the CiliumNetworkPolicy. | ||
func (r *CiliumClusterwideNetworkPolicy) GetIdentityLabels() labels.LabelArray { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this removed in follow up commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tes
pkg/k8s/apis/cilium.io/v2/types.go
Outdated
@@ -276,58 +276,6 @@ type CiliumClusterwideNetworkPolicy struct { | |||
CiliumNetworkPolicy | |||
} | |||
|
|||
// Parse parses a CiliumClusterwideNetworkPolicy and returns a list of cilium policy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can squash this change with the previous commit
pkg/k8s/factory_functions.go
Outdated
@@ -386,24 +387,39 @@ func ConvertToCNPWithStatus(obj interface{}) interface{} { | |||
return &types.SlimCNP{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a new function dedicated for the conversion of CiliumClusterwideNetworkPolicy
to types.SlimpCNP
002ddd5
to
d39c134
Compare
test-me-please |
a0df602
to
dd5297d
Compare
test-me-please |
dd5297d
to
1ac45e2
Compare
test-me-please |
1ac45e2
to
9b16060
Compare
test-me-please |
1 similar comment
test-me-please |
d8082f8
to
a96bdf9
Compare
test-me-please |
test-me-please |
test-upstream-k8s |
test-missed-k8s previous test https://jenkins.cilium.io/job/Cilium-PR-Ginkgo-Tests-K8s/2603/ |
test-missed-k8s |
test-upstream-k8s |
Upstream k8s tests got stuck:
I hit this in a recent PR as well; re-running. |
test-upstream-k8s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks great! I have a few nits mainly surrounding documentation grammar. Thanks for this contribution!!
Documentation/kubernetes/policy.rst
Outdated
@@ -24,6 +24,11 @@ with Kubernetes: | |||
`CustomResourceDefinition` which supports specification of policies | |||
at Layers 3-7 for both ingress and egress. | |||
|
|||
- The `CiliumClusterwideNetworkPolicy` format which is cluster scoped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a cluster-scoped
Documentation/kubernetes/policy.rst
Outdated
@@ -24,6 +24,11 @@ with Kubernetes: | |||
`CustomResourceDefinition` which supports specification of policies | |||
at Layers 3-7 for both ingress and egress. | |||
|
|||
- The `CiliumClusterwideNetworkPolicy` format which is cluster scoped | |||
`CustomResourceDefinition` for specifying cluster wide policies to be enforced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cluster-wide
Documentation/kubernetes/policy.rst
Outdated
|
||
`CiliumClusterwideNetworkPolicy` is same as that of `CiliumNetworkPolicy` with the only | ||
difference in the scope of the policy. Policies defined by `CiliumClusterwideNetworkPolicy` | ||
are non namespaced and are cluster scoped. Internally the policy is composed of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-namespaces and are cluster-scoped.
Documentation/policy/language.rst
Outdated
-------------------- | ||
|
||
`CiliumNetworkPolicy` only allows to bind a policy restricted to a particular namespace. There can be situations | ||
where one wants to have a cluster scoped effect of the policy, this can be done using cilium's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cluster-scoped
Documentation/policy/language.rst
Outdated
-------------------- | ||
|
||
`CiliumNetworkPolicy` only allows to bind a policy restricted to a particular namespace. There can be situations | ||
where one wants to have a cluster scoped effect of the policy, this can be done using cilium's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..., which can be done using Cilium's...
Documentation/policy/language.rst
Outdated
|
||
`CiliumNetworkPolicy` only allows to bind a policy restricted to a particular namespace. There can be situations | ||
where one wants to have a cluster scoped effect of the policy, this can be done using cilium's | ||
`CiliumClusterwideNetworkPolicy` kubernetes custom resource. The specification of the policy is same as that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kubernetes --> Kubernetes
Documentation/policy/language.rst
Outdated
`CiliumNetworkPolicy` only allows to bind a policy restricted to a particular namespace. There can be situations | ||
where one wants to have a cluster scoped effect of the policy, this can be done using cilium's | ||
`CiliumClusterwideNetworkPolicy` kubernetes custom resource. The specification of the policy is same as that | ||
of `CiliumNetworkPolicy` with the only difference that it is not namespaced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the only difference that it is not namespace --> except that it is not namespaced.
CustomResourceDefinitionPluralName = "ciliumclusterwidenetworkpolicies" | ||
|
||
// CustomResourceDefinitionShortNames are the abbreviated names to refer to this CRD's instances | ||
CustomResourceDefinitionShortNames = []string{"ccnp", "ciliumcnp"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think ciliumcnp
is necessary here - CNP is almost always used to abbeviate CiliumNetworkPolicy
, while here it refers to ClusterwideNetworkPolicy
. I'd prefer we keep only ccnp
.
581835d
to
3ac09b4
Compare
test-me-please |
1 similar comment
test-me-please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work. The only change request I have is regarding the name. I think shorter is better but I'm also fine with the current proposal.
|
||
// ResourceTypeCiliumClusterwideNetworkPolicy is the resource type used for the | ||
// PolicyLabelDerivedFrom label | ||
ResourceTypeCiliumClusterwideNetworkPolicy = "CiliumClusterwideNetworkPolicy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this CiliumClusterNetworkPolicy
. It's shorter and also clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline. The naming was discussed in SIG-policy and the conclusion was CiliumClusterwideNetworkPolicy. I'm OK with this.
* Add CiliumGlobalNetowrkPolicy type to Cilium k8s api client. * Update k8s utilities to incorporate changes corresponding to cilium global policies. Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
* Update k8s_watcher.go to include controller to watch for CiliumClusterwideNetworkPolicy CRD. * Update ExtractNamespace function in k8s utils to account for the fact that any object with empty namespace is a cluster scoped object and we should not automatically add default namespace to such objects. Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
* Added k8s manifests for ccnp polices to test common policies * Updated tests to include ccnp policy test manifests Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
Signed-off-by: Deepesh Pathak <deepshpathak@gmail.com>
3ac09b4
to
1f7036f
Compare
test-me-please |
Fixes #9200
CiliumClusterwideNetworkPolicy
resource.This change is