mirror of
https://github.com/rancher/k3k.git
synced 2026-08-19 12:26:17 +00:00
* 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>
84 lines
3.8 KiB
Go
84 lines
3.8 KiB
Go
package cmds
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
|
|
"github.com/rancher/k3k/pkg/apis/k3k.io/v1beta1"
|
|
)
|
|
|
|
func createFlags(cmd *cobra.Command, cfg *CreateConfig) {
|
|
cmd.Flags().IntVar(&cfg.servers, "servers", 1, "number of servers")
|
|
cmd.Flags().IntVar(&cfg.agents, "agents", 0, "number of agents")
|
|
cmd.Flags().StringVar(&cfg.token, "token", "", "token of the cluster")
|
|
cmd.Flags().StringVar(&cfg.clusterCIDR, "cluster-cidr", "", "cluster CIDR")
|
|
cmd.Flags().StringVar(&cfg.serviceCIDR, "service-cidr", "", "service CIDR")
|
|
cmd.Flags().BoolVar(&cfg.mirrorHostNodes, "mirror-host-nodes", false, "Mirror Host Cluster Nodes")
|
|
cmd.Flags().StringVar(&cfg.persistenceType, "persistence-type", string(v1beta1.DynamicPersistenceMode), "persistence mode for the nodes (dynamic, ephemeral)")
|
|
cmd.Flags().StringVar(&cfg.storageClassName, "storage-class-name", "", "storage class name for dynamic persistence type")
|
|
cmd.Flags().StringVar(&cfg.storageRequestSize, "storage-request-size", "", "storage size for dynamic persistence type")
|
|
cmd.Flags().StringSliceVar(&cfg.serverArgs, "server-args", []string{}, "servers extra arguments")
|
|
cmd.Flags().StringSliceVar(&cfg.agentArgs, "agent-args", []string{}, "agents extra arguments")
|
|
cmd.Flags().StringSliceVar(&cfg.serverEnvs, "server-envs", []string{}, "servers extra Envs")
|
|
cmd.Flags().StringSliceVar(&cfg.agentEnvs, "agent-envs", []string{}, "agents extra Envs")
|
|
cmd.Flags().StringSliceVar(&cfg.tlsSANs, "tls-sans", []string{}, "additional Subject Alternative Names for the cluster server TLS certificate")
|
|
cmd.Flags().StringArrayVar(&cfg.labels, "labels", []string{}, "Labels to add to the cluster object (e.g. key=value)")
|
|
cmd.Flags().StringArrayVar(&cfg.annotations, "annotations", []string{}, "Annotations to add to the cluster object (e.g. key=value)")
|
|
cmd.Flags().StringVar(&cfg.version, "version", "", "k3s version")
|
|
cmd.Flags().StringVar(&cfg.mode, "mode", "shared", "k3k mode type (shared, virtual, hcp)")
|
|
cmd.Flags().StringVar(&cfg.kubeconfigServerHost, "kubeconfig-server", "", "override the kubeconfig server host")
|
|
cmd.Flags().StringVar(&cfg.policy, "policy", "", "The policy to create the cluster in")
|
|
cmd.Flags().StringVar(&cfg.customCertsPath, "custom-certs", "", "The path for custom certificate directory")
|
|
cmd.Flags().DurationVar(&cfg.timeout, "timeout", 3*time.Minute, "The timeout for waiting for the cluster to become ready (e.g., 10s, 5m, 1h).")
|
|
|
|
mustRegisterFlagCompletion(cmd, "mode", completeClusterMode)
|
|
mustRegisterFlagCompletion(cmd, "persistence-type", completePersistenceMode)
|
|
|
|
if err := cmd.MarkFlagDirname("custom-certs"); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
}
|
|
|
|
var validPersistenceModes = map[v1beta1.PersistenceMode]struct{}{
|
|
v1beta1.EphemeralPersistenceMode: {},
|
|
v1beta1.DynamicPersistenceMode: {},
|
|
}
|
|
|
|
var validClusterModes = map[v1beta1.ClusterMode]struct{}{
|
|
v1beta1.VirtualClusterMode: {},
|
|
v1beta1.SharedClusterMode: {},
|
|
v1beta1.HCPClusterMode: {},
|
|
}
|
|
|
|
func validateCreateConfig(cfg *CreateConfig) error {
|
|
if cfg.servers <= 0 {
|
|
return errors.New("invalid number of servers: must be 1 or more")
|
|
}
|
|
|
|
if cfg.persistenceType != "" {
|
|
persistenceMode := v1beta1.PersistenceMode(cfg.persistenceType)
|
|
if _, found := validPersistenceModes[persistenceMode]; !found {
|
|
return errors.New(`persistence-type should be one of "dynamic" or "ephemeral"`)
|
|
}
|
|
}
|
|
|
|
if cfg.storageRequestSize != "" {
|
|
if _, err := resource.ParseQuantity(cfg.storageRequestSize); err != nil {
|
|
return errors.New(`invalid storage size, should be a valid resource quantity e.g "10Gi"`)
|
|
}
|
|
}
|
|
|
|
if cfg.mode != "" {
|
|
clusterMode := v1beta1.ClusterMode(cfg.mode)
|
|
if _, found := validClusterModes[clusterMode]; !found {
|
|
return errors.New(`mode should be one of "shared", "virtual" or "hcp"`)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|