BREAKING. Support for namespace label matching and secret event handling #161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The two functional goals of this PR are:
Many changes were made to support these two functional goals, and more changes were made to simplify the code. I categorize these changes as breaking, functional, and cleanup.
BREAKING
valueFrom
inside thedata
field will no longer designate a source secret. To use a secret as the source, a newfromSecret
field (an object with required stringsname
andnamespace
and optional string arraykeys
) is added to the CRD. A ClusterSecret will only be valid if it has one ofdata
orfromSecret
, but not both.ownerReferences
on secrets (instead of theCREATE_BY_ANNOTATION
) now, which will break installations withREPLACE_EXISTING: false
as the controller will refuse to update preexisting secrets.Functional
matchLabels
andmatchedSetsJoin
matchLabels
takes objects with string values. It looks the same as labels set on a kubernetes resource.matchedSetsJoin
takes a string with value "union" or "intersection" and performs that operation to join the namespace lists generated by eachmatchLabel
and bymatchNamespace
.get_ns_list
and duplicated in a newsecret_belongs
function.on_namespace_event
and is triggered bykopf.on.event
instead ofkopf.on.create
(this also prevents kopf from setting the status field on namespace resources, which seemed excessive). The handler uses the newsecret_belongs
function to check every clustersecret to find if any match the new namespace state and syncs, deletes, or does nothing to reach the desired state.secret_belongs
function is added to check if a single namespace matches a clustersecret. This allows us to avoid a fullget_ns_list
call when only one namespace or secret changes.on_field_match_namespace
handler is renamed toon_match_fields
and handles events for changes to thematchNamespace
,avoidNamespaces
,matchLabels
, andmatchedSetsJoin
fields.on_field_data
handler now also handles events for changes to thefromSecret
field.on_secret_event
handler is added to both re-sync secrets managed by a ClusterSecret (determined by whether anownerReference
withkind: ClusterSecret
is set on the secret) and trigger a full cluster secret re-sync if the changed secret is the source for a ClusterSecret.create_secret_metadata
function now adds anownerReference
to managed secrets' metadata. This is used by theon_secret_event
handler and allows us to reduce theon_delete
handler as secret deletion will be handled by kubernetes on clustersecret deletion.Cleanup
CREATE_BY_ANNOTATION
is removed from secrets in favor ofownerReferences
.on_delete
handler is reduced to only removing the deleted ClusterSecret from the cache, as all secrets are now deleted by kubernetes through theownerReferences
.LAST_SYNC_ANNOTATION
is removed from secrets. It seems unnecessary and complicates current vs desired state comparisons done before secret updates. If added again, thesync_secret
function will need to be updated to ignore this annotation when comparing desired to current secret states.secret_belongs
is added to test whether a single namespace matches a ClusterSecret.sync_clustersecret
is added to sync all targets of a ClusterSecret.startup_fn
handler now syncs all ClusterSecrets found in the cluster on operator start. Thecreate_fn
handler no longer handles ClusterSecret resume events.fromSecret
field is added to the ClusterSecret CRD, which can be used to designate a source secret. This allows ClusterSecret structure validation to be handled by kubernetes, and allowsvalueFrom
to be a key in ClusterSecret data.sync_secret
function. With the new CRD the validations are unnecessary.read_data_secret
function is moved into thesync_secret
function, the only calling location.CREATE_BY_LABEL
is added with value set to the controlling ClusterSecret's name.get_child_secret_namespaces
is added to get a list of synced namespaces for a clustersecret using theCREATE_BY_LABEL
. This is used in place of the removed syncedns lists.This PR is not ready to be merged. There are several TODOs and a few potential improvements.
TODO
Potential Improvements
Update CRD to limitdone 19ddde5data
field to only key/value pairs with string values now thatvalueFrom
indata
is unsupported (seematchLabels
definition).matchedSetsJoin
string (ensure it's one of union or intersection) - can this be done in the CRD?Remove the cache - all comparisons could be done against cluster state instead of cached state.Removed syncedns from the cache, leaving the clustersecret body 4463328Removedone 4463328syncedns
from ClusterSecret status - deletion of secrets that used to match would need to be handled differently.