Introduce --karmada-context flag to karmada-agent to select context in
kubeconfig file Signed-off-by: lihanbo <lihanbo2@huawei.com>
This commit is contained in:
parent
bd0d3b8a0c
commit
280abfe468
|
@ -26,6 +26,7 @@ spec:
|
|||
command:
|
||||
- /bin/karmada-agent
|
||||
- --karmada-kubeconfig=/etc/kubeconfig/karmada-kubeconfig
|
||||
- --karmada-context=karmada-apiserver
|
||||
- --cluster-name={{member_cluster_name}}
|
||||
- --cluster-status-update-frequency=10s
|
||||
- --v=4
|
||||
|
|
|
@ -30,12 +30,13 @@ import (
|
|||
// NewAgentCommand creates a *cobra.Command object with default parameters
|
||||
func NewAgentCommand(ctx context.Context) *cobra.Command {
|
||||
opts := options.NewOptions()
|
||||
karmadaConfig := karmadactl.NewKarmadaConfig(clientcmd.NewDefaultPathOptions())
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "karmada-agent",
|
||||
Long: `The karmada agent runs the cluster registration agent`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := run(ctx, opts); err != nil {
|
||||
if err := run(ctx, karmadaConfig, opts); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -47,8 +48,8 @@ func NewAgentCommand(ctx context.Context) *cobra.Command {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func run(ctx context.Context, opts *options.Options) error {
|
||||
controlPlaneRestConfig, err := clientcmd.BuildConfigFromFlags("", opts.KarmadaKubeConfig)
|
||||
func run(ctx context.Context, karmadaConfig karmadactl.KarmadaConfig, opts *options.Options) error {
|
||||
controlPlaneRestConfig, err := karmadaConfig.GetRestConfig(opts.KarmadaContext, opts.KarmadaKubeConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error building kubeconfig of karmada control plane: %s", err.Error())
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ import (
|
|||
// Options contains everything necessary to create and run controller-manager.
|
||||
type Options struct {
|
||||
KarmadaKubeConfig string
|
||||
// ClusterContext is the name of the cluster context in control plane KUBECONFIG file.
|
||||
// Default value is the current-context.
|
||||
KarmadaContext string
|
||||
ClusterName string
|
||||
|
||||
// ClusterStatusUpdateFrequency is the frequency that karmada-agent computes cluster status.
|
||||
|
@ -30,7 +33,8 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
|
|||
return
|
||||
}
|
||||
|
||||
fs.StringVar(&o.KarmadaKubeConfig, "karmada-kubeconfig", o.KarmadaKubeConfig, "Path to karmada kubeconfig.")
|
||||
fs.StringVar(&o.KarmadaKubeConfig, "karmada-kubeconfig", o.KarmadaKubeConfig, "Path to karmada control plane kubeconfig file.")
|
||||
fs.StringVar(&o.KarmadaContext, "karmada-context", "", "Name of the cluster context in karmada control plane kubeconfig file.")
|
||||
fs.StringVar(&o.ClusterName, "cluster-name", o.ClusterName, "Name of member cluster that the agent serves for.")
|
||||
fs.DurationVar(&o.ClusterStatusUpdateFrequency.Duration, "cluster-status-update-frequency", 10*time.Second, "Specifies how often karmada-agent posts cluster status to karmada-apiserver. Note: be cautious when changing the constant, it must work with ClusterMonitorGracePeriod in karmada-controller-manager.")
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ source ${REPO_ROOT}/hack/util.sh
|
|||
function usage() {
|
||||
echo "This script will deploy karmada agent to a cluster."
|
||||
echo "Usage: hack/deploy-karmada-agent.sh"
|
||||
echo "Example: hack/deploy-karmada.sh"
|
||||
echo "Example: hack/deploy-karmada-agent.sh"
|
||||
}
|
||||
|
||||
export REGISTRY="swr.ap-southeast-1.myhuaweicloud.com/karmada"
|
||||
|
|
|
@ -24,8 +24,8 @@ type GlobalCommandOptions struct {
|
|||
|
||||
// AddFlags adds flags to the specified FlagSet.
|
||||
func (o *GlobalCommandOptions) AddFlags(flags *pflag.FlagSet) {
|
||||
flags.StringVar(&o.KubeConfig, "kubeconfig", "", "Path to the control plane KUBECONFIG file.")
|
||||
flags.StringVar(&o.KarmadaContext, "karmada-context", "", "Name of the cluster context in control plane KUBECONFIG file.")
|
||||
flags.StringVar(&o.KubeConfig, "kubeconfig", "", "Path to the control plane kubeconfig file.")
|
||||
flags.StringVar(&o.KarmadaContext, "karmada-context", "", "Name of the cluster context in control plane kubeconfig file.")
|
||||
flags.StringVar(&o.ClusterNamespace, "cluster-namespace", DefaultKarmadaClusterNamespace, "Namespace in the control plane where member cluster are stored.")
|
||||
flags.BoolVar(&o.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue