Commit Graph
181 Commits
Author SHA1 Message Date
renovate-rancher[bot]andGitHub 1faf0fc58a Update Kubernetes dependencies 2026-07-30 05:26:57 +00:00
Enrico CandinoandGitHub bf0c8f0c32 Keep PersistentVolumeClaim to "varlibrancherk3s" (#1090)
* Keep PersistentVolumeClaim to "varlibrancherk3s"

* Rename volume name to "varlibrancherk3s" in pod specification
2026-07-29 11:17:56 +02:00
Kevin McDermottandGitHub f77083b563 Switch out the Go YAML package (#1089)
This replaces direct usage of "gopkg.in/yaml.v3" with "go.yaml.in/yaml/v4".

The original package is now a dependency of the testify packages.
2026-07-28 11:58:46 +01:00
Hussein GalalandGitHub 11bf7a2dc4 Add PodSecurityContext and Security Context to helm chart and cluster spec (#1058)
* Add securityContext and podSecurityContext to the chart and cluster pods

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-07-28 13:53:11 +03:00
Enrico CandinoandGitHub 7d2105ecf5 Update golang.org/x/text to v0.39.0 (#1038)
* Update `golang.org/x/text` to `v0.39.0`

* align dependencies
2026-07-16 17:00:16 +02:00
e1ae07c836 Isolate only virtual cluster workload Pods (#989)
* Enhance network policy to isolate synced workload pods and improve cross-cluster pod isolation handling

* Add test for label update on synced Pod to ensure isolation label persistence

* Derive host pod CIDRs dynamically for the isolation NetworkPolicy

Compute the egress-exclude CIDRs from the --cluster-cidr flag or the live
Node PodCIDR(s) via FindPodCIDRs, instead of a hardcoded guess, so cross-cluster
pod isolation is enforced against the host's real pod network. Adds unit,
integration, and e2e coverage.

* update comment

* Sort CIDR list in FindPodCIDRs function to ensure consistent order for egress rules

* Use `t.Context()` instead of `context.Background()`

Co-authored-by: Kevin McDermott <bigkevmcd@gmail.com>

* Use Ginkgo provided context

* Refactor FindPodCIDRs to use sets for CIDR collection and simplify logic

* fix lint

---------

Co-authored-by: Kevin McDermott <bigkevmcd@gmail.com>
2026-07-16 15:18:04 +02:00
10a0b42c6a Move pkg/apis to its own package (#1026)
* move apis to seperate package

* move github.com/rancher/k3k/pkg/apis in go.mod

---------

Co-authored-by: Enrico Candino <enrico.candino@suse.com>
2026-07-16 11:35:43 +02:00
Enrico CandinoandGitHub 3a4d93f5fb Fix dangling Pods (#1021)
* Add tests asserting GetPods is scoped to the node's own Pods

Adds a unit test (fake host + virtual clients, Pods across multiple nodes plus
a dangling one) and a multi-node e2e test (a Deployment with one nginx Pod per
node via required anti-affinity; restart every k3k-kubelet agent Pod; assert no
workload Pod is deleted from the host or virtual cluster). Both pin the intended
behavior and fail against the current code; the fix follows in the next commit.

* Scope Provider.GetPods to the node's own Pods to prevent cross-node dangling-pod deletion

GetPods() listed host Pods cluster-wide (by the k3k.io/clusterName label only).
The vendored virtual-kubelet library's deleteDanglingPods reconciliation deletes
any Pod returned here that is missing from this instance's virtual Pod lister,
which is scoped to spec.nodeName == agentHostname. On a multi-node host cluster,
every restarting k3k-kubelet instance therefore saw Pods owned by other nodes as
'dangling' and deleted them from the host (and, in turn, the virtual cluster).

Scope GetPods by the *virtual* Pod's spec.nodeName -- the same ownership signal
the framework uses -- excluding Pods owned by other nodes while still returning
own-node Pods and genuinely dangling ones. The host Pod's physical node is not a
reliable owner (it is scheduled with only a soft, sometimes-absent affinity), so
it must not be used. Virtual Pods are read live to avoid a startup cache-sync
race. Makes the previous commit's tests pass.

* Refactor GetPods to scope to the cluster namespace and update tests accordingly

* Add AgentNameLabel to track Pods synced by the k3k-kubelet agent and update tests accordingly

* Add failing test for updatePod
2026-07-15 17:02:30 +02:00
bcraftandGitHub 120d964281 set machine id on server pod if not exists (#1011) 2026-07-10 12:58:37 +02:00
Enrico CandinoandGitHub 3d0438edc9 Update k8s dependencies to v1.36 (main) (#979)
* Update k3s version in test suites to v1.36.2-k3s1

- Updated the k3sVersion and k3sOldVersion constants in both cli and e2e test suites to reflect the new version v1.36.2-k3s1 and the previous version v1.36.0-k3s1.

* updated README.md
2026-07-08 15:58:06 +02:00
39cc69f3e3 Added HCP (Hosted Control Plane) mode (#876)
* Add HCP (Hosted Control Plane) support

Introduce hosted control plane mode for k3k virtual clusters, including
API types, controller logic, server endpoint handling, CLI flags,
CRD updates, kubeconfig generation, and examples.

Co-Authored-By: RuFlo <ruv@ruv.net>

* removed hcpRegitration command

added HCP conformance tests

warning for hcp

fix multi-VM HCP conformance test networking

  Both QEMU workers booted with `-net user` and ended up registering the
  same InternalIP (10.0.2.15) because each VM gets its own isolated NAT
  slirp. Flannel propagated this to `public-ip` on both nodes, so VXLAN
  could not tunnel between workers and any cross-node pod traffic broke
  (89 failed / 335 passed of 424 conformance specs).

  Replace user-mode networking with a Linux bridge (k3kbr0,
  192.168.100.0/24) and one TAP device per VM, so the two workers share
  an L2 segment with unique routable IPs. NAT outbound from the bridge
  keeps internet access working for image pulls.

  Also set unique hostnames via cloud-init (worker-1/worker-2) and drop
  the `--node-name` flag from INSTALL_K3S_EXEC, since k3s now picks the
  correct node name from the OS hostname on its own.

  Bump hydrophone back to `--parallel 4` to match the single-VM job
  (parallelism was reduced earlier when the failure was thought to be
  resource-related).

added HCP print command

updated crds

adding e2e tests

Refactor selectNonLoopbackSAN function to accept SANs directly and update related logic in ensureHCPRegistration

* Update agent flag validation and enhance ingress host check with a warning log

Refactor descriptions for cluster provisioning mode and role in CRDs and documentation

Refactor logging in ServerURL function to use controller-runtime logger

Rename selectNonLoopbackSAN to findNonLoopbackSAN for clarity and update references

Refactor ServerURL function and related code to remove unused parameters and improve clarity

Remove unused imports from kubeconfig.go to improve code clarity

* suggested changes

* fix comment

* fix test

---------

Co-authored-by: jpgouin <jeanphilippe.gouin@suse.com>
Co-authored-by: RuFlo <ruv@ruv.net>
2026-07-07 14:12:19 +02:00
Kevin McDermott 4cd5bd85d0 Refactor the service tests. 2026-07-06 08:42:20 +01:00
Kevin McDermott f1dbf33435 Support annotations on exposed Services
This adds a new .spec.expose.annotations field which is applied to the
service when it's created.
2026-07-06 08:19:30 +01:00
fa16898689 fix EXTRA_ARGS parsing in the startup command (#951)
* fix EXTRA_ARGS parsing in the startup command and add multi server args test

* fix lint

* Refactor server config tests to improve readability and maintainability

---------

Co-authored-by: Enrico Candino <enrico.candino@suse.com>
2026-07-01 18:17:58 +02:00
Hussein GalalandGitHub 3abffae92d External datastore support (#879)
* Adding new k3s function to get the config
* Adding a new way to get the bootstrap data directly from the server Pod
* Gate the bootstrap fetch if external datastore is in use
---------

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-06-26 17:22:00 +03:00
Enrico CandinoandGitHub 244011e68d Refactor kubeconfig URL generation (#938)
* Refactor kubeconfig generation to remove unused port parameter and update related functions

* Refactor kubeconfig generation to streamline error handling and remove unused imports

* Refactor kubeconfig URL generation functions and deprecate old implementation

* restore old behavior

* Add 'k3kcli kubeconfig get' command and update documentation

* Refactor URL generation by removing deprecated getURLFromService function and updating tests to use new implementation

* Fix expected URL for LoadBalancer test case to include hostname

* Refactor kubeconfig test documentation to clarify URL generation behavior for ClusterIP, NodePort, and LoadBalancer service types

* Refactor kubeconfig URL generation functions to improve clarity and maintainability

* Remove deprecated 'k3kcli kubeconfig get' command and update related documentation

* Set logger to discard in NewRootCmd for improved logging control

* Refactor getURLFromService to streamline ingress key retrieval
2026-06-26 11:16:54 +02:00
Enrico CandinoandGitHub 1e23fdb4fa Add unit tests for URL generation across service types in kubeconfig (#939)
* Add unit tests for URL generation across service types in kubeconfig

* addressed comments for SchemeBuilder and Context

* Refactor client creation and REST config loading in NewRootCmd

* Refactor scheme and schemeBuilder initialization

* use t.Helper in helper funcs
2026-06-25 14:44:19 +02:00
Enrico CandinoandGitHub 651da42ef0 Added provider.cattle.io=k3k label to Clusters (#901)
* added provider k3k label

* small change to check  build
2026-06-12 16:12:38 +02:00
ff02eb5473 Initial support for kata runtimes (#814)
* update shell script to exec and remove pipe, add conditional kmsg mount for kata

update logging config

Apply suggestions from code review

Co-authored-by: Enrico Candino <enrico.candino@gmail.com>

pr comments, remove isKata, fix agent unit tests, update config

fix validation

fix template

revert log changes

update init script

remove emptydir mounts from kata

remove emptydir mounts from kata

fix tests

lint

* add quickstart docs

* centralise kata spotspec modifications

* update doc

* update docs
2026-06-12 13:57:42 +03:00
Hussein GalalandGitHub 5bd779cdaa Refactor bootstrap data management (#869)
* Refactor bootstrap data management

* Change errors from errors.New to fmt.Errorf

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-06-03 19:40:31 +03:00
Kevin McDermott 4795ef5ae7 Mirror events for the cluster into the virtual cluster.
Adds a controller to watch for virtual cluster namespace events and
mirrors them into the virtual cluster.
2026-05-22 08:44:13 +01:00
Hussein GalalandGitHub 8457d3a20b Refactor servers and agents configuration management (#827)
* Refactor server config secret

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* lint fixes

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* Refactor Agents configuration for virtual and shared mode

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* wsl

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* fixes

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* fix typo

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* fix unit tests

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* Remove go assert depednecny

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

---------

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-05-12 15:57:24 +03:00
Hussein GalalandGitHub 1ca9e7274c Add server and worker resource request and limits (#832)
* Add server and worker resource request and limits

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* docs

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

---------

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-04-30 16:16:11 +03:00
Hussein GalalandGitHub d4c8f56639 Fix cgroup dirs for virtual mode clusters (#792)
* Fix cgroup dirs for virtual mode clusters

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-04-28 16:06:30 +03:00
Hussein GalalandGitHub d8f962e5dc Add WorkerLimit to shared cluster and add unit tests (#798)
* Fix WorkerLimit to shared agents
* Add unit tests for pod spec for both virtual and shared modes
* Fix image registry for virtual mode

---------

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-04-17 13:07:45 +02:00
Hussein GalalandGitHub 28acb94d8a Add hostUsers to cluster spec (#787)
* Add hostUsers to cluster spec

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* wsl

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* Fix the do comment for hostusers

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* Fix the do comment for hostusers

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

---------

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-04-15 15:46:23 +02:00
Enrico CandinoandGitHub 737dcf998e Added Policy finalizer (#781)
* added policy finalizer

* check with a small timeout

* comments

* removed requeue, renamed log
2026-04-15 11:14:22 +02:00
Enrico CandinoandGitHub 06c5aee7c9 add importas linter (#779) 2026-04-13 17:25:17 +02:00
Enrico CandinoandGitHub ba1648e560 Refactoring of tests moving common logic in tests/framework (#769)
* first commit

* refactor: update golangci configuration and reorder imports in namespace.go

* refactor: update golangci configuration for linters and formatters

* check restart for logs fetch

* rverted a bit the structure

* requested changes

* WriteLogs rename
2026-04-13 12:50:38 +02:00
Hussein GalalandGitHub 96d812a3cb Custom runtime class and security context (#742)
* Add experimental runtimeClass and securityContext to spec

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-04-09 10:22:46 +02:00
Gaurav MehtaandGitHub 8add97934e minor fix to translated ingress tls secrets in ingress object (#672)
* minor fix to translated ingress tls secrets in ingress object

updated cluster ingress sync options to include extra field for SyncTLSSecrets

Signed-off-by: Gaurav Mehta <gaurav.mehta@suse.com>

* rebase changes from main, include feedback for renaming ingress secret sync field to DisableTLSSecretTranslation, and add kubelet integration tests to verify secret name translation

Signed-off-by: Gaurav Mehta <gaurav.mehta@suse.com>

---------

Signed-off-by: Gaurav Mehta <gaurav.mehta@suse.com>
2026-04-08 11:39:23 +02:00
Hussein GalalandGitHub 183c5a0a5a Fix networkpolicy for kube-ovn network (#691)
Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-04-03 15:32:32 +02:00
Enrico CandinoandGitHub 18889ba6b7 Removed Pod mutating Webhook (shared mode) (#699)
* removed all webhook references

* fix tests

* removal of webhook

* updated doc

* add downward API test

* small refactor of virtual-kubelet

* split tests
2026-03-31 10:29:22 +02:00
Jonathan CrowtherandGitHub 624fee98d7 Refactor tests to their own directories (#723)
* Move cli tests

* Move e2e tests to their own directory

* Move integration tests

* Fix path within the cli tests

* Move k3k-kubelet tests

* Improve the various make test- options

* Remove dead code from cli tests

* Update development.md with the new make commands
2026-03-26 09:45:31 -04:00
Jonathan CrowtherandGitHub 25e910ccaf Add initial affinity to podspecs (#696)
* Add initial affinity to podspecs

* Fix go generate

* Add field to the policy and prioritize it over the cluster spec

* Fix linter issue

* Add docs

* Address comments

* Fix the tests and improve the field descriptions

* Fix formatter issues

* Change logs to info level

* run validation

* undo pandoc changes
2026-03-23 16:16:30 -04:00
Enrico CandinoandGitHub 9554628fc5 Update virtual-kubelet (v1.12) and Kubernetes deps (v1.35) (#716)
* bump virtual-kubelet and k8s

* bump controller-manager

* fix upgrade-downgrade

* fix kubernetes version

* Update tests_suite_test.go

* removed direct dep of yaml.v2, bump etcd modules
2026-03-23 12:51:43 +01:00
Kevin McDermott 056b36e8b5 Don't start the metrics server in tests.
This prevents the metrics server from starting when testing.

None of the tests check the metrics server.
2026-03-19 14:06:59 +00:00
Enrico CandinoandGitHub 7b0f695248 Bump some tes dependencies and fix lint (#708) 2026-03-18 17:43:41 +01:00
Enrico CandinoandGitHub 7641a1c9c5 Add sync of Host StorageClasses (#681)
* initial impl

* wip test

* fix

* wip tests

* Refactor storage class sync logic and enhance test coverage

* fix test

* remove storageclass sync test

* removed commented code

* added sync to cluster status to apply policy configuration

* fix for storageClass policy indexes

* fix for missing indexed field, and label sync

* - update sync options descriptions for resource types
- added storage class tests sync with policy
- requested changes

* fix for nil map
2026-03-17 16:53:29 +01:00
Enrico CandinoandGitHub 9836f8376d Added policy in Cluster Status (#663)
* initial implementation

restored policyName

* added test, fixed priority scheduling

* requested changes from review

- wrapped errors
- fixed some kube-api-linter issues to match k8s conventions
- moved policy namespace check in the same condition branch
2026-02-17 16:15:13 +01:00
Enrico CandinoandGitHub 0164c785ab Show correct allocatable resources when a Policy is applied (#638)
* wip

* wip

* wip

* fix lint and tests

* fixed bugs for missing resources

* cleanup and refactor

* removed coreClient from configureNode

* added comments to distribute algorithm
2026-01-27 15:56:37 +01:00
Hussein GalalandGitHub c1b7da4c72 SecretMounts feature and private registries (#570)
* Add SecretMounts field

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-01-26 21:47:40 +02:00
Kevin McDermottandGitHub c0418267c9 Merge pull request #623 from bigkevmcd/resource-quantity
Use resource.Quantity instead of a string for storageRequestSize in the Cluster definition.
2026-01-22 13:13:06 +00:00
Kevin McDermott eaa20c16e7 Make the storageRequestSize immutable.
It can't be changed in the StatefulSet and modifying the value causes an
error.
2026-01-22 08:27:20 +00:00
jpgouinandGitHub 0cea0c9e14 Only reconcile the server resource on the StatefullSet Controller (fix #618) 2026-01-21 16:53:52 +01:00
Kevin McDermott d12f3ea757 Fix lint issues and failing test.
golangci-lint was complaining about duplicate imports of corev1 and the
ordering of them in the files.
2026-01-21 14:50:30 +00:00
Kevin McDermott 9ea81c861b Use resource.Quantity for storageRequestSize
Previously the resource.Quantity was stored as string which allowed
invalid values to be created.

This performs validation on the strings using the standard K8s resource
mechanism.
2026-01-21 14:50:28 +00:00
jpgouinandGitHub ff6862e511 fix virtual pod NodeSelector #572 (#616) 2026-01-20 11:33:42 +01:00
Hussein GalalandGitHub a871917aec Refactor startup command to wait for node IP changes (#598)
* Patch node ip when server pod restarts

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* wsl

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* Refactor startup command and adding safe mode

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* Add date/time logging to the startup script

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* fixes

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

---------

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
2026-01-09 16:29:47 +02:00
Enrico CandinoandGitHub e385ceb66f Fixed missing Kubernetes host version when specified (#585)
* fix for missing host version

* added test

* fix test

* fix test
2025-12-03 09:21:27 +01:00