Skip to content

Commit

Permalink
Add validation for system cluster name for both controller and cli (#81)
Browse files Browse the repository at this point in the history
* Add validation for system cluster name for both controller and cli

Signed-off-by: galal-hussein <[email protected]>

* Add validation for system cluster name for both controller and cli

Signed-off-by: galal-hussein <[email protected]>

* Add validation for system cluster name for both controller and cli

Signed-off-by: galal-hussein <[email protected]>

---------

Signed-off-by: galal-hussein <[email protected]>
  • Loading branch information
galal-hussein authored Jan 6, 2024
1 parent fedfa10 commit 3cdcb04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/cmds/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
clusterController = "k3k-cluster-controller"
clusterFinalizerName = "cluster.k3k.io/finalizer"
etcdPodFinalizerName = "etcdpod.k3k.io/finalizer"
ClusterInvalidName = "system"

maxConcurrentReconciles = 1

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3cdcb04

Please sign in to comment.