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

ConfigMaps From Host Sync: #2439

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

hidalgopl
Copy link
Contributor

@hidalgopl hidalgopl commented Jan 31, 2025

  • adds sync.fromHost.configMaps config options
  • parses namespaces in sync.fromHost.configMaps.selector.mappings and creates Roles and RoleBindings accordingly
  • implements translator based on the sync.fromHost.configMaps.selector.mappings
  • adds from host syncer for ConfigMap, it watches for ConfigMaps in additional namespaces in the host, so it uses also uncachedPhysicalClient
  • adds E2E test for syncing config maps from two different namespaces in the host to another one in vCluster, then creates a Pod that uses these ConfigMaps as EnvVar source

What issue type does this pull request address? (keep at least one, remove the others)
/kind feature
/kind test

What does this pull request do? Which issues does it resolve? (use resolves #<issue_number> if possible)
resolves ENG-5653

Please provide a short message that should be published in the vcluster release notes
ConfigMaps From Host Sync

What else do we need to know?
Roles and RoleBindings created by helm assume that all Namespaces listed in the sync.fromHost.configMaps.selector.mappings already exist in the host. I added creating foobar namespace (which is used in e2e test) to Justfile & e2e CI (it has to happen before creating vCluster).

In the following up PR, which implements from host syncing for Secret, I'll make the syncer more generic so only kind-specific details has to be implemented, but otherwise the logic can be re-used.

- adds sync.fromHost.configMaps config options
- parses namespaces in sync.fromHost.configMaps.selector.mappings and creates Roles and RoleBindings accordingly
- implements translator based on the sync.fromHost.configMaps.selector.mappings
- adds from host syncer for ConfigMap, it watches for ConfigMaps in additional namespaces in the host, so it uses also uncachedPhysicalClient
- adds E2E test for syncing config maps from two different namespaces in the host to another one in vCluster, then creates a Pod that uses these ConfigMaps as EnvVar source

Signed-off-by: Paweł Bojanowski <[email protected]>
Copy link

netlify bot commented Jan 31, 2025

Deploy Preview for vcluster-docs canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 4148083
🔍 Latest deploy log https://app.netlify.com/sites/vcluster-docs/deploys/67a1d9db3db5b30008308a32

- adds sync.fromHost.configMaps config options
- parses namespaces in sync.fromHost.configMaps.selector.mappings and creates Roles and RoleBindings accordingly
- implements translator based on the sync.fromHost.configMaps.selector.mappings
- adds from host syncer for ConfigMap, it watches for ConfigMaps in additional namespaces in the host, so it uses also uncachedPhysicalClient
- adds E2E test for syncing config maps from two different namespaces in the host to another one in vCluster, then creates a Pod that uses these ConfigMaps as EnvVar source
- adds helm unittests

Signed-off-by: Paweł Bojanowski <[email protected]>
Signed-off-by: Paweł Bojanowski <[email protected]>
@hidalgopl hidalgopl requested a review from a team February 3, 2025 07:31
Signed-off-by: Paweł Bojanowski <[email protected]>
Justfile Outdated Show resolved Hide resolved
@@ -15,3 +15,49 @@
{{ .repository }}:{{ .tag }}
{{- end -}}
{{- end -}}

{{- define "extractNamespacesFromHostMappings" -}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding:

  • When a user adds a host namespace here that does not exist, this would lead to a helm error during install/update?
  • What happens with the syncer when a user deletes a host namespace during runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yes, it leads to helm error:
16:40:45 fatal error executing helm upgrade vcluster ./chart/ --create-namespace --kubeconfig /tmp/3659476771 --namespace vcluster --install --repository-config='' --values /tmp/3887008891 --values ./dist/commonValues.yaml --values ./test/e2e/values.yaml: Release "vcluster" does not exist. Installing it now.
Error: 2 errors occurred:
        * namespaces "foobar2" not found
  1. Well, the vCluster will periodically log an error saying that it does not have enough permissions to watch for configmaps in <deleted-namespace>. This is because the Role & RoleBinding gets too during namespace deletion. Synced ConfigMap will stay unchanged in the vCluster.
    I also changed default error handler, so we can log a more helpful error message about it: https://github.com/loft-sh/vcluster/pull/2439/files#diff-098628cf79dfa68abeae1696afdb72b5c484c5f8638fb1a0b7db7e60faee8efaR140-R148
    Thanks for bringing this up. I think it would be good to document these assumptions in the docs, gonna do it in the docs PR.

return hostName == "kube-root-ca.crt"
}

func matchesHostObject(hostName, hostNamespace string, resourceMappings map[string]string, vClusterHostNamespace string, skippers ...skipHostObject) (types.NamespacedName, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When matched, should we also check if the host namespace still exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to do this: in most cases, this method is called with pObj.GetName() & pObj.GetNamespace() as arguments, where pObj is fetched from host cluster by uncached client (so it will error out there if namespace does not exist)

Signed-off-by: Paweł Bojanowski <[email protected]>
Signed-off-by: Paweł Bojanowski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants