add --as-* options to join command (#5016)
Signed-off-by: Michael Grosser <michael@grosser.it>
This commit is contained in:
parent
1f9e0783b6
commit
0bc96a2f67
|
@ -107,6 +107,15 @@ type CommandJoinOption struct {
|
|||
// more details about running Kubernetes in multiple zones.
|
||||
ClusterZones []string
|
||||
|
||||
// HostAs represents the host cluster username to impersonate for the operation. User could be a regular user or a service account in a namespace
|
||||
HostAs string
|
||||
|
||||
// HostAsGroups represents the host cluster group to impersonate for the operation, this flag can be repeated to specify multiple groups
|
||||
HostAsGroups []string
|
||||
|
||||
// HostAsUID represents the host cluster UID to impersonate for the operation.
|
||||
HostAsUID string
|
||||
|
||||
// DryRun tells if run the command in dry-run mode, without making any server requests.
|
||||
DryRun bool
|
||||
}
|
||||
|
@ -150,6 +159,12 @@ func (j *CommandJoinOption) AddFlags(flags *pflag.FlagSet) {
|
|||
flags.StringVar(&j.ClusterProvider, "cluster-provider", "", "Provider of the joining cluster. The Karmada scheduler can use this information to spread workloads across providers for higher availability.")
|
||||
flags.StringVar(&j.ClusterRegion, "cluster-region", "", "The region of the joining cluster. The Karmada scheduler can use this information to spread workloads across regions for higher availability.")
|
||||
flags.StringSliceVar(&j.ClusterZones, "cluster-zones", nil, "The zones of the joining cluster. The Karmada scheduler can use this information to spread workloads across zones for higher availability.")
|
||||
flags.StringVar(&j.HostAs, "host-as", "",
|
||||
"Host cluster username to impersonate for the operation. User could be a regular user or a service account in a namespace.")
|
||||
flags.StringArrayVar(&j.HostAsGroups, "host-as-group", []string{},
|
||||
"Host cluster group to impersonate for the operation, this flag can be repeated to specify multiple groups.")
|
||||
flags.StringVar(&j.HostAsUID, "host-as-uid", "",
|
||||
"Host cluster UID to impersonate for the operation.")
|
||||
flags.BoolVar(&j.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
|
||||
}
|
||||
|
||||
|
@ -165,6 +180,11 @@ func (j *CommandJoinOption) Run(f cmdutil.Factory) error {
|
|||
*options.DefaultConfigFlags.Context, *options.DefaultConfigFlags.KubeConfig, err)
|
||||
}
|
||||
|
||||
// Configure impersonation
|
||||
controlPlaneRestConfig.Impersonate.UserName = j.HostAs
|
||||
controlPlaneRestConfig.Impersonate.Groups = j.HostAsGroups
|
||||
controlPlaneRestConfig.Impersonate.UID = j.HostAsUID
|
||||
|
||||
// Get cluster config
|
||||
clusterConfig, err := apiclient.RestConfig(j.ClusterContext, j.ClusterKubeConfig)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue