Skip to content

Commit

Permalink
add --as-* options to join command (#5016)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Grosser <michael@grosser.it>
  • Loading branch information
grosser committed Jun 20, 2024
1 parent 1f9e078 commit 0bc96a2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/karmadactl/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.")
}

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

0 comments on commit 0bc96a2

Please sign in to comment.