-
Notifications
You must be signed in to change notification settings - Fork 186
feat: Add additionalMetadataList Support for Conditional Metadata Assignment #1339
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
feat: Add additionalMetadataList Support for Conditional Metadata Assignment #1339
Conversation
✅ Deploy Preview for capsule-documentation canceled.
|
821eb00
to
a9a7b02
Compare
a9a7b02
to
e0d1bae
Compare
We'll have to do some discussions around this. I am currently refactoring to a generic CEL based approach which would also solve this case. But thanks for the commit for now, I will get back to it |
@oliverbaehler Any news on the discussion? Our usecase for this is that we want to implement pod security baseline and restricted policies on specific namespaces (https://kubernetes.io/docs/concepts/security/pod-security-standards/). Is there any way we can speedup this feature request? |
@peterbosalliandercom yes i get your use-case and it does make sense. However we want to move away from such specific implementations and refactor into more generic solutions, since they are technical dept. Such that we could eg. deprecated the additionalMetadata for pod, services etc. as well. A generic approach to having patches for any kind of manifests on tenant basis with given selector options. That's what i would aim for. I will have to create a poc on the weekend and see how difficult that is to implement. Based on these findings we will either merge this as is and keep the prospect, that it will be deprecated in the v1 api bump or i will port the same functionality to that generic feature. Make sense? |
Generally speaking, we're always happy to receive newer contributions: we have limited resources to allocate to the project, especially considering the efforts in reviewing code from non-maintainers. Remember that Capsule is backed by two vendors (CLASTIX and PeakScale) which offer features prioritisations as well as other professional services, and addons.
We should go toward CEL and drop support of custom handlers where it is possible: @maxgio92 started a PoC with VAP/CEL while working at CLASTIX. |
Sorry i haven't had time yet. I am happy to accept this change in the current spec. @Deofex could you merge and resolve the conflicts on the crd? |
f988c2d
to
c80a0d0
Compare
controllers/tenant/namespaces.go
Outdated
|
||
for k, v := range additionalMetadata.Labels { | ||
labels[k] = v | ||
} |
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.
Add annotations as well
} | |
for k, v := range additionalMetadata.Annotations{ | |
annotations[k] = v | |
} | |
} |
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.
Added
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.
this should not be touched with your change
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.
Not sure what happened here, but the changes in this file are removed
pkg/api/additional_metadata.go
Outdated
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"` | ||
Labels map[string]string `json:"labels,omitempty"` | ||
Annotations map[string]string `json:"annotations,omitempty"` | ||
} |
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.
Create a new spec for this, otherwise the other apis also have a nemspaceSelector field out of context.
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"` | |
Labels map[string]string `json:"labels,omitempty"` | |
Annotations map[string]string `json:"annotations,omitempty"` | |
} | |
Labels map[string]string `json:"labels,omitempty"` | |
Annotations map[string]string `json:"annotations,omitempty"` | |
} | |
type AdditionalMetadataSelectorSpec struct | |
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"` | |
Labels map[string]string `json:"labels,omitempty"` | |
Annotations map[string]string `json:"annotations,omitempty"` | |
} | |
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.
Added the spec
api/v1beta2/namespace_options.go
Outdated
@@ -13,6 +13,8 @@ type NamespaceOptions struct { | |||
Quota *int32 `json:"quota,omitempty"` | |||
// Specifies additional labels and annotations the Capsule operator places on any Namespace resource in the Tenant. Optional. | |||
AdditionalMetadata *api.AdditionalMetadataSpec `json:"additionalMetadata,omitempty"` | |||
// Specifies additional labels and annotations the Capsule operator places on any Namespace resource in the Tenant via a list. Optional. | |||
AdditionalMetadataList []api.AdditionalMetadataSpec `json:"additionalMetadataList,omitempty"` |
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.
AdditionalMetadataList []api.AdditionalMetadataSpec `json:"additionalMetadataList,omitempty"` | |
AdditionalMetadataList []api.AdditionalMetadataSelectorSpec `json:"additionalMetadataList,omitempty"` |
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.
Changed
Sorry for the delayed reply — GitHub has been flooding me with notifications but somehow skipping the important ones. I definitely need to look into that. As you already noticed (and reviewed), the conflicts are resolved. |
@Deofex workflows approved. Lets see a green e2e :) |
There's quite a bit of red there, unfortunately. Classic “it works on my machine” 🙃:
I'll take a look, but if anyone has an idea of what’s causing the failures, I’d appreciate the input — I’m not seeing anything in my code that would explain them. I also noticed the linter is failing on a Cyclomatic Complexity check. I’ll see if I can split up the Is the |
7a5484f
to
ec302db
Compare
I refactored the Can someone review the refactored method and try the 2e2 test again in the pipeline? |
Signed-off-by: Deofex <28751252+Deofex@users.noreply.github.com>
Signed-off-by: Deofex <28751252+Deofex@users.noreply.github.com>
Signed-off-by: Deofex 28751252+Deofex@users.noreply.github.com
Signed-off-by: Deofex <28751252+Deofex@users.noreply.github.com>
Signed-off-by: Deofex <28751252+Deofex@users.noreply.github.com>
Signed-off-by: Deofex <28751252+Deofex@users.noreply.github.com>
ec302db
to
16ba9eb
Compare
Signed-off-by: Deofex <28751252+Deofex@users.noreply.github.com>
16ba9eb
to
4d5a3bb
Compare
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.
Thank you very much, i'm going to extend the docs later
Summary
This PR introduces support for additionalMetadataList, allowing cluster admins to define conditional labels and annotations for namespaces within a tenant. This enhancement builds upon the existing additionalMetadata functionality, providing more granular control through namespaceSelector expressions.
Changes Introduced
Example Configuration
Defining both global and conditional metadata in a tenant:
Impact & Compatibility
Fully backward compatible: Existing additionalMetadata configurations will continue to work as before.
New functionality is opt-in, meaning it does not affect existing tenants unless additionalMetadataList is explicitly configured.