Skip to content

Commit

Permalink
Merge pull request #209 from jp-gouin/cli
Browse files Browse the repository at this point in the history
add flag to override kubernetes server value in the generated kubeconfig
  • Loading branch information
jp-gouin authored Jan 24, 2025
2 parents 8b0383f + ec93371 commit 8f24151
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
34 changes: 22 additions & 12 deletions cli/cmds/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ func init() {
}

var (
name string
token string
clusterCIDR string
serviceCIDR string
servers int64
agents int64
serverArgs cli.StringSlice
agentArgs cli.StringSlice
persistenceType string
storageClassName string
version string
mode string
name string
token string
clusterCIDR string
serviceCIDR string
servers int64
agents int64
serverArgs cli.StringSlice
agentArgs cli.StringSlice
persistenceType string
storageClassName string
version string
mode string
kubeconfigServerHost string

clusterCreateFlags = []cli.Flag{
&cli.StringFlag{
Expand Down Expand Up @@ -115,6 +116,12 @@ var (
Destination: &mode,
Value: "shared",
},
&cli.StringFlag{
Name: "kubeconfig-server",
Usage: "override the kubeconfig server host",
Destination: &kubeconfigServerHost,
Value: "",
},
}
)

Expand Down Expand Up @@ -169,6 +176,9 @@ func create(clx *cli.Context) error {
return err
}
host := strings.Split(url.Host, ":")
if kubeconfigServerHost != "" {
host = []string{kubeconfigServerHost}
}
cluster.Spec.TLSSANs = []string{host[0]}

if err := ctrlClient.Create(ctx, cluster); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions cli/cmds/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
altNames cli.StringSlice
expirationDays int64
configName string
kubeconfigServerHost string
generateKubeconfigFlags = []cli.Flag{
&cli.StringFlag{
Name: "name",
Expand Down Expand Up @@ -71,6 +72,12 @@ var (
Destination: &expirationDays,
Value: 356,
},
&cli.StringFlag{
Name: "kubeconfig-server",
Usage: "override the kubeconfig server host",
Destination: &kubeconfigServerHost,
Value: "",
},
}
)

Expand Down Expand Up @@ -121,6 +128,13 @@ func generate(clx *cli.Context) error {
return err
}
host := strings.Split(url.Host, ":")
if kubeconfigServerHost != "" {
host = []string{kubeconfigServerHost}
err := altNames.Set(kubeconfigServerHost)
if err != nil {
return err
}
}

certAltNames := certs.AddSANs(altNames.Value())

Expand Down

0 comments on commit 8f24151

Please sign in to comment.