Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions cli/cmd/bootstrap_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *BootstrapGcpCmd) RunE(_ *cobra.Command, args []string) error {
return nil
}

func AddBootstrapGcpCmd(root *cobra.Command, opts *GlobalOptions) {
func AddBootstrapGcpCmd(parent *cobra.Command, opts *GlobalOptions) {
bootstrapGcpCmd := BootstrapGcpCmd{
cmd: &cobra.Command{
Use: "bootstrap-gcp",
Expand All @@ -53,6 +53,7 @@ func AddBootstrapGcpCmd(root *cobra.Command, opts *GlobalOptions) {
Env: env.NewEnv(),
CodesphereEnv: &gcp.CodesphereEnvironment{},
}
bootstrapGcpCmd.cmd.RunE = bootstrapGcpCmd.RunE

flags := bootstrapGcpCmd.cmd.Flags()
flags.StringVar(&bootstrapGcpCmd.CodesphereEnv.ProjectName, "project-name", "", "Unique GCP Project Name (required)")
Expand Down Expand Up @@ -82,8 +83,8 @@ func AddBootstrapGcpCmd(root *cobra.Command, opts *GlobalOptions) {
util.MarkFlagRequired(bootstrapGcpCmd.cmd, "billing-account")
util.MarkFlagRequired(bootstrapGcpCmd.cmd, "base-domain")

bootstrapGcpCmd.cmd.RunE = bootstrapGcpCmd.RunE
root.AddCommand(bootstrapGcpCmd.cmd)
parent.AddCommand(bootstrapGcpCmd.cmd)
AddBootstrapGcpPostconfigCmd(bootstrapGcpCmd.cmd, opts)
}

func (c *BootstrapGcpCmd) BootstrapGcp() error {
Expand All @@ -92,9 +93,8 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error {
icg := installer.NewInstallConfigManager()
gcpClient := gcp.NewGCPClient(ctx, stlog, os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
fw := util.NewFilesystemWriter()
nm := node.NewNode(fw, c.CodesphereEnv.SSHPrivateKeyPath, c.SSHQuiet)

bs, err := gcp.NewGCPBootstrapper(ctx, c.Env, stlog, c.CodesphereEnv, icg, gcpClient, nm, fw)
bs, err := gcp.NewGCPBootstrapper(ctx, c.Env, stlog, c.CodesphereEnv, icg, gcpClient, fw, node.NewSSHNodeClient(c.SSHQuiet))
if err != nil {
return err
}
Expand All @@ -103,21 +103,34 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error {

err = bs.Bootstrap()
envBytes, err2 := json.MarshalIndent(bs.Env, "", " ")

envString := string(envBytes)
if err2 != nil {
envString = ""
}

if err != nil {
if bs.Env.Jumpbox != nil && bs.Env.Jumpbox.GetExternalIP() != "" {
if bs.Env.Jumpbox.GetExternalIP() != "" {
log.Printf("To debug on the jumpbox host:\nssh-add $SSH_KEY_PATH; ssh -o StrictHostKeyChecking=no -o ForwardAgent=yes -o SendEnv=OMS_PORTAL_API_KEY root@%s", bs.Env.Jumpbox.GetExternalIP())
}
return fmt.Errorf("failed to bootstrap GCP: %w, env: %s", err, envString)
}

workdir := env.NewEnv().GetOmsWorkdir()
err = fw.MkdirAll(workdir, 0755)
if err != nil {
return fmt.Errorf("failed to create workdir: %w", err)
}
infraFilePath := gcp.GetInfraFilePath()
err = fw.WriteFile(infraFilePath, envBytes, 0644)
if err != nil {
return fmt.Errorf("failed to write gcp bootstrap env file: %w", err)
}

log.Println("\n🎉🎉🎉 GCP infrastructure bootstrapped successfully!")
log.Println(envString)
log.Printf("Infrastructure details written to %s", infraFilePath)
log.Printf("Start the Codesphere installation using OMS from the jumpbox host:\nssh-add $SSH_KEY_PATH; ssh -o StrictHostKeyChecking=no -o ForwardAgent=yes -o SendEnv=OMS_PORTAL_API_KEY root@%s", bs.Env.Jumpbox.GetExternalIP())
log.Printf("When the installation is done, run the k0s configuration script generated at the k0s-1 host %s /root/configure-k0s.sh.", bs.Env.ControlPlaneNodes[0].GetInternalIP())

return err
return nil
}
77 changes: 77 additions & 0 deletions cli/cmd/bootstrap_gcp_postconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0

package cmd

import (
"encoding/json"
"fmt"
"log"

"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/internal/bootstrap/gcp"
"github.com/codesphere-cloud/oms/internal/installer"
"github.com/codesphere-cloud/oms/internal/util"
"github.com/spf13/cobra"
)

type BootstrapGcpPostconfigCmd struct {
cmd *cobra.Command

Opts *BootstrapGcpPostconfigOpts
CodesphereEnv gcp.CodesphereEnvironment
}

type BootstrapGcpPostconfigOpts struct {
*GlobalOptions
InstallConfigPath string
PrivateKeyPath string
}

func (c *BootstrapGcpPostconfigCmd) RunE(_ *cobra.Command, args []string) error {
log.Printf("running post-configuration steps...")

icg := installer.NewInstallConfigManager()

fw := util.NewFilesystemWriter()

envFileContent, err := fw.ReadFile(gcp.GetInfraFilePath())
if err != nil {
return fmt.Errorf("failed to read gcp infra file: %w", err)
}

err = json.Unmarshal(envFileContent, &c.CodesphereEnv)
if err != nil {
return fmt.Errorf("failed to unmarshal gcp infra file: %w", err)
}

err = icg.LoadInstallConfigFromFile(c.Opts.InstallConfigPath)
if err != nil {
return fmt.Errorf("failed to load config file: %w", err)
}

return fmt.Errorf("not implemented: run config script on k0s-1 node to install GCP CCM")
}

func AddBootstrapGcpPostconfigCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions) {
postconfig := BootstrapGcpPostconfigCmd{
cmd: &cobra.Command{
Use: "postconfig",
Short: "Run post-configuration steps for GCP bootstrapping",
Long: io.Long(`After bootstrapping GCP infrastructure, this command runs additional configuration steps
to finalize the setup for the Codesphere cluster on GCP:

* Install Google Cloud Controller Manager for ingress management.`),
},
Opts: &BootstrapGcpPostconfigOpts{
GlobalOptions: opts,
},
}

flags := postconfig.cmd.Flags()
flags.StringVar(&postconfig.Opts.InstallConfigPath, "install-config-path", "config.yaml", "Path to the installation configuration file")
flags.StringVar(&postconfig.Opts.PrivateKeyPath, "private-key-path", "", "Path to the GCP service account private key file (optional)")

bootstrapGcp.AddCommand(postconfig.cmd)
postconfig.cmd.RunE = postconfig.RunE
}
1 change: 1 addition & 0 deletions docs/oms-cli_beta_bootstrap-gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ oms-cli beta bootstrap-gcp [flags]
### SEE ALSO

* [oms-cli beta](oms-cli_beta.md) - Commands for early testing
* [oms-cli beta bootstrap-gcp postconfig](oms-cli_beta_bootstrap-gcp_postconfig.md) - Run post-configuration steps for GCP bootstrapping

27 changes: 27 additions & 0 deletions docs/oms-cli_beta_bootstrap-gcp_postconfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## oms-cli beta bootstrap-gcp postconfig

Run post-configuration steps for GCP bootstrapping

### Synopsis

After bootstrapping GCP infrastructure, this command runs additional configuration steps
to finalize the setup for the Codesphere cluster on GCP:

* Install Google Cloud Controller Manager for ingress management.

```
oms-cli beta bootstrap-gcp postconfig [flags]
```

### Options

```
-h, --help help for postconfig
--install-config-path string Path to the installation configuration file (default "config.yaml")
--private-key-path string Path to the GCP service account private key file (optional)
```

### SEE ALSO

* [oms-cli beta bootstrap-gcp](oms-cli_beta_bootstrap-gcp.md) - Bootstrap GCP infrastructure for Codesphere

Loading