Skip to content

Commit

Permalink
fix: issue backend + add some var k3s tf
Browse files Browse the repository at this point in the history
Signed-off-by: jomo, Jonathan Monnet <[email protected]>
  • Loading branch information
jomo, Jonathan Monnet authored and DrummyFloyd committed Dec 19, 2023
1 parent a5c67e3 commit de70714
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
8 changes: 8 additions & 0 deletions cmd/k3s/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ var (
// TODO: add ssh key flag to connect on k3s targets
alertsEmailFlag string
ciFlag bool
cloudRegionFlag string
clusterNameFlag string
clusterTypeFlag string
k3sIpServersFlag []string
k3sIpAgentsFlag []string
k3sSshUserflag string
k3sSshPrivateKeyflag string
dnsProviderFlag string
domainNameFlag string
githubOrgFlag string
Expand Down Expand Up @@ -75,11 +78,16 @@ func Create() *cobra.Command {
createCmd.Flags().StringVar(&alertsEmailFlag, "alerts-email", "", "email address for let's encrypt certificate notifications (required)")
createCmd.MarkFlagRequired("alerts-email")
createCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")
createCmd.Flags().StringVar(&cloudRegionFlag, "cloud-region", "on-premise", "NOT USED, PRESENT FOR COMPATIBILITY ISSUE")
createCmd.Flags().StringVar(&clusterNameFlag, "cluster-name", "kubefirst", "the name of the cluster to create")
createCmd.Flags().StringVar(&clusterTypeFlag, "cluster-type", "mgmt", "the type of cluster to create (i.e. mgmt|workload)")
createCmd.Flags().StringSliceVar(&k3sIpServersFlag, "k3s-ip-servers", []string{}, "the list of k3s (servers) ip x.x.x.x y.y.y.y space separated (required)")
createCmd.MarkFlagRequired("k3s-ips-servers")
createCmd.Flags().StringSliceVar(&k3sIpAgentsFlag, "k3s-ip-agents", []string{}, "the list of k3s (agents) ip x.x.x.x y.y.y.y space separated")
createCmd.Flags().StringVar(&k3sSshUserflag, "k3s-ssh-user", "root", "the user used to log into servers with ssh connection")
createCmd.MarkFlagRequired("k3s-ssh-user")
createCmd.Flags().StringVar(&k3sSshPrivateKeyflag, "k3s-ssh-private-key", "", "the private key used to log into servers with ssh connection")
createCmd.MarkFlagRequired("k3s-ssh-private-key")
createCmd.Flags().StringVar(&dnsProviderFlag, "dns-provider", "cloudflare", fmt.Sprintf("the dns provider - one of: %s", supportedDNSProviders))
createCmd.Flags().StringVar(&domainNameFlag, "domain-name", "", "the cloudProvider DNS Name to use for DNS records (i.e. your-domain.com|subdomain.your-domain.com) (required)")
createCmd.Flags().StringVar(&gitProviderFlag, "git-provider", "github", fmt.Sprintf("the git provider - one of: %s", supportedGitProviders))
Expand Down
3 changes: 3 additions & 0 deletions internal/progress/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func DisplaySuccessMessage(cluster types.Cluster) successMsg {

case "vultr":
cloudCliKubeconfig = fmt.Sprintf("vultr-cli kubernetes config %s", cluster.ClusterName)

case "k3s":
cloudCliKubeconfig = fmt.Sprint(("use the kubeconfig file outputed from terraform to acces to the cluster"))
break

}
Expand Down
5 changes: 5 additions & 0 deletions internal/types/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ type CliFlags struct {
Ecr bool
NodeType string
NodeCount string
K3sSshUser string
K3sSshPrivateKey string

UseTelemetry bool
Ecr bool
}
38 changes: 26 additions & 12 deletions internal/utilities/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error)
return cliFlags, err
}

cloudRegionFlag, err := cmd.Flags().GetString("cloud-region")
if err != nil {
progress.Error(err.Error())
return cliFlags, err
}

clusterNameFlag, err := cmd.Flags().GetString("cluster-name")
if err != nil {
progress.Error(err.Error())
Expand Down Expand Up @@ -85,6 +91,14 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error)
progress.Error(err.Error())
return cliFlags, err
}
// TODO: reafactor this part
if cloudProvider == "k3s" {
k3sIpServersFlag, err := cmd.Flags().GetStringSlice("k3s-ip-servers")
if err != nil {
progress.Error(err.Error())
return cliFlags, err
}
cliFlags.K3sIpServers = k3sIpServersFlag

nodeTypeFlag, err := cmd.Flags().GetString("node-type")
if err != nil {
Expand All @@ -98,27 +112,26 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error)
return cliFlags, err
if cloudProvider != "k3s" {
cloudRegionFlag, err := cmd.Flags().GetString("cloud-region")
k3sIpAgentsFlag, err := cmd.Flags().GetStringSlice("k3s-ip-agents")
if err != nil {
progress.Error(err.Error())
return cliFlags, err
}
cliFlags.CloudRegion = cloudRegionFlag
}
if cloudProvider == "k3s" {
k3sIpServers, err := cmd.Flags().GetStringSlice("k3s-ip-servers")
cliFlags.K3sIpAgents = k3sIpAgentsFlag

k3sSshUserFlag, err := cmd.Flags().GetString("k3s-ssh-user")
if err != nil {
progress.Error(err.Error())
return cliFlags, err
}
cliFlags.K3sIpServers = k3sIpServers
}
if cloudProvider == "k3s" {
k3sIpAgents, err := cmd.Flags().GetStringSlice("k3s-ip-servers")
cliFlags.K3sSshUser = k3sSshUserFlag

k3sSshPrivateKeyFlag, err := cmd.Flags().GetString("k3s-ssh-private-key")
if err != nil {
progress.Error(err.Error())
return cliFlags, err
}
cliFlags.K3sIpAgents = k3sIpAgents
cliFlags.K3sSshPrivateKey = k3sSshPrivateKeyFlag
}

if cloudProvider == "aws" {
Expand All @@ -142,6 +155,7 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error)
}

cliFlags.AlertsEmail = alertsEmailFlag
cliFlags.CloudRegion = cloudRegionFlag
cliFlags.ClusterName = clusterNameFlag
cliFlags.DnsProvider = dnsProviderFlag
cliFlags.DomainName = domainNameFlag
Expand All @@ -162,13 +176,13 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error)
viper.Set("flags.domain-name", cliFlags.DomainName)
viper.Set("flags.git-provider", cliFlags.GitProvider)
viper.Set("flags.git-protocol", cliFlags.GitProtocol)
if cloudProvider != "k3s" {
viper.Set("flags.cloud-region", cliFlags.CloudRegion)
}
viper.Set("flags.cloud-region", cliFlags.CloudRegion)
viper.Set("kubefirst.cloud-provider", cloudProvider)
if cloudProvider == "k3s" {
viper.Set("flags.k3s-ip-servers", cliFlags.K3sIpServers)
viper.Set("flags.k3s-ip-agents", cliFlags.K3sIpAgents)
viper.Set("flags.k3s-ssh-user", cliFlags.K3sSshUser)
viper.Set("flags.k3s-ssh-private-key", cliFlags.K3sSshPrivateKey)
}
viper.WriteConfig()

Expand Down

0 comments on commit de70714

Please sign in to comment.