From 3cdcb04e1aebcd7165052174b94bee7fc796cdef Mon Sep 17 00:00:00 2001 From: Hussein Galal Date: Sat, 6 Jan 2024 02:15:20 +0200 Subject: [PATCH] Add validation for system cluster name for both controller and cli (#81) * Add validation for system cluster name for both controller and cli Signed-off-by: galal-hussein * Add validation for system cluster name for both controller and cli Signed-off-by: galal-hussein * Add validation for system cluster name for both controller and cli Signed-off-by: galal-hussein --------- Signed-off-by: galal-hussein --- cli/cmds/cluster/create.go | 4 ++++ pkg/controller/cluster/cluster.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/cli/cmds/cluster/create.go b/cli/cmds/cluster/create.go index b2aa77e..0621a02 100644 --- a/cli/cmds/cluster/create.go +++ b/cli/cmds/cluster/create.go @@ -12,6 +12,7 @@ import ( "github.com/rancher/k3k/cli/cmds" "github.com/rancher/k3k/pkg/apis/k3k.io/v1alpha1" + "github.com/rancher/k3k/pkg/controller/cluster" "github.com/rancher/k3k/pkg/controller/cluster/server" "github.com/rancher/k3k/pkg/controller/util" "github.com/sirupsen/logrus" @@ -210,6 +211,9 @@ func validateCreateFlags(clx *cli.Context) error { if name == "" { return errors.New("empty cluster name") } + if name == cluster.ClusterInvalidName { + return errors.New("invalid cluster name") + } if servers <= 0 { return errors.New("invalid number of servers") } diff --git a/pkg/controller/cluster/cluster.go b/pkg/controller/cluster/cluster.go index 5f94154..36099c5 100644 --- a/pkg/controller/cluster/cluster.go +++ b/pkg/controller/cluster/cluster.go @@ -40,6 +40,7 @@ const ( clusterController = "k3k-cluster-controller" clusterFinalizerName = "cluster.k3k.io/finalizer" etcdPodFinalizerName = "etcdpod.k3k.io/finalizer" + ClusterInvalidName = "system" maxConcurrentReconciles = 1 @@ -178,6 +179,10 @@ func (c *ClusterReconciler) Reconcile(ctx context.Context, req reconcile.Request } func (c *ClusterReconciler) createCluster(ctx context.Context, cluster *v1alpha1.Cluster) error { + if cluster.Name == ClusterInvalidName { + klog.Errorf("Invalid cluster name %s, no action will be taken", cluster.Name) + return nil + } s := server.New(cluster, c.Client) if cluster.Spec.Persistence != nil {