Skip to content

Commit

Permalink
introduce flag --feature-gates to karmadactl register
Browse files Browse the repository at this point in the history
Signed-off-by: zhzhuang-zju <m17799853869@163.com>
  • Loading branch information
zhzhuang-zju committed Dec 24, 2024
1 parent c9ca6ac commit 50be683
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/karmadactl/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
k8srand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/wait"
kubeclient "k8s.io/client-go/kubernetes"
Expand All @@ -49,6 +50,7 @@ import (
"k8s.io/kubectl/pkg/util/templates"

"github.com/karmada-io/karmada/pkg/apis/cluster/validation"
"github.com/karmada-io/karmada/pkg/features"
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
"github.com/karmada-io/karmada/pkg/karmadactl/options"
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
Expand Down Expand Up @@ -196,6 +198,9 @@ func NewCmdRegister(parentCommand string) *cobra.Command {
flags.Int32Var(&opts.CertExpirationSeconds, "cert-expiration-seconds", DefaultCertExpirationSeconds, "The expiration time of certificate.")
flags.BoolVar(&opts.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
flags.StringVar(&opts.ProxyServerAddress, "proxy-server-address", "", "Address of the proxy server that is used to proxy to the cluster.")
flags.StringVar(&opts.FeatureGates, "feature-gates", "", ""+
"A set of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(features.FeatureGate.KnownFeatures(), "\n"))

return cmd
}
Expand Down Expand Up @@ -259,6 +264,9 @@ type CommandRegisterOption struct {
memberClusterEndpoint string
memberClusterClient *kubeclient.Clientset

// FeatureGates for alpha/experimental features of karmada-agent.
FeatureGates string

// rbacResources contains RBAC resources that grant the necessary permissions for pull mode cluster to access to Karmada control plane.
rbacResources *RBACResources
}
Expand Down Expand Up @@ -315,6 +323,15 @@ func (o *CommandRegisterOption) Validate() error {
return fmt.Errorf("need to verify CACertHashes, or set --discovery-token-unsafe-skip-ca-verification=true")
}

if len(o.FeatureGates) != 0 {
if err := features.FeatureGate.Set(o.FeatureGates); err != nil {
return fmt.Errorf("parse flag --feature-gates failed, %s", err.Error())
}
if errs := features.FeatureGate.Validate(); len(errs) != 0 {
return fmt.Errorf("invalid feature gates(%s): %s", o.FeatureGates, utilerrors.NewAggregate(errs).Error())
}
}

return nil
}

Expand Down Expand Up @@ -1030,6 +1047,7 @@ func (o *CommandRegisterOption) makeKarmadaAgentDeployment() *appsv1.Deployment
fmt.Sprintf("--proxy-server-address=%s", o.ProxyServerAddress),
fmt.Sprintf("--leader-elect-resource-namespace=%s", o.Namespace),
fmt.Sprintf("--cluster-namespace=%s", o.ClusterNamespace),
fmt.Sprintf("--feature-gates=%s", o.FeatureGates),
"--cluster-status-update-frequency=10s",
"--metrics-bind-address=:8080",
"--health-probe-bind-address=0.0.0.0:10357",
Expand Down

0 comments on commit 50be683

Please sign in to comment.