Skip to content

Commit cd16773

Browse files
authored
Merge branch 'main' into renovate/github.com-codesphere-cloud-cs-go-0.x
2 parents 6b3c7b3 + 8458f62 commit cd16773

File tree

8 files changed

+2118
-3178
lines changed

8 files changed

+2118
-3178
lines changed

cli/cmd/bootstrap_gcp.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (c *BootstrapGcpCmd) RunE(_ *cobra.Command, args []string) error {
3838
return nil
3939
}
4040

41-
func AddBootstrapGcpCmd(root *cobra.Command, opts *GlobalOptions) {
41+
func AddBootstrapGcpCmd(parent *cobra.Command, opts *GlobalOptions) {
4242
bootstrapGcpCmd := BootstrapGcpCmd{
4343
cmd: &cobra.Command{
4444
Use: "bootstrap-gcp",
@@ -53,6 +53,7 @@ func AddBootstrapGcpCmd(root *cobra.Command, opts *GlobalOptions) {
5353
Env: env.NewEnv(),
5454
CodesphereEnv: &gcp.CodesphereEnvironment{},
5555
}
56+
bootstrapGcpCmd.cmd.RunE = bootstrapGcpCmd.RunE
5657

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

85-
bootstrapGcpCmd.cmd.RunE = bootstrapGcpCmd.RunE
86-
root.AddCommand(bootstrapGcpCmd.cmd)
86+
parent.AddCommand(bootstrapGcpCmd.cmd)
87+
AddBootstrapGcpPostconfigCmd(bootstrapGcpCmd.cmd, opts)
8788
}
8889

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

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

104104
err = bs.Bootstrap()
105105
envBytes, err2 := json.MarshalIndent(bs.Env, "", " ")
106+
106107
envString := string(envBytes)
107108
if err2 != nil {
108109
envString = ""
109110
}
111+
110112
if err != nil {
111-
if bs.Env.Jumpbox != nil && bs.Env.Jumpbox.GetExternalIP() != "" {
113+
if bs.Env.Jumpbox.GetExternalIP() != "" {
112114
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())
113115
}
114116
return fmt.Errorf("failed to bootstrap GCP: %w, env: %s", err, envString)
115117
}
116118

119+
workdir := env.NewEnv().GetOmsWorkdir()
120+
err = fw.MkdirAll(workdir, 0755)
121+
if err != nil {
122+
return fmt.Errorf("failed to create workdir: %w", err)
123+
}
124+
infraFilePath := gcp.GetInfraFilePath()
125+
err = fw.WriteFile(infraFilePath, envBytes, 0644)
126+
if err != nil {
127+
return fmt.Errorf("failed to write gcp bootstrap env file: %w", err)
128+
}
129+
117130
log.Println("\n🎉🎉🎉 GCP infrastructure bootstrapped successfully!")
118131
log.Println(envString)
132+
log.Printf("Infrastructure details written to %s", infraFilePath)
119133
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())
120-
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())
121134

122-
return err
135+
return nil
123136
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) Codesphere Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package cmd
5+
6+
import (
7+
"encoding/json"
8+
"fmt"
9+
"log"
10+
11+
"github.com/codesphere-cloud/cs-go/pkg/io"
12+
"github.com/codesphere-cloud/oms/internal/bootstrap/gcp"
13+
"github.com/codesphere-cloud/oms/internal/installer"
14+
"github.com/codesphere-cloud/oms/internal/util"
15+
"github.com/spf13/cobra"
16+
)
17+
18+
type BootstrapGcpPostconfigCmd struct {
19+
cmd *cobra.Command
20+
21+
Opts *BootstrapGcpPostconfigOpts
22+
CodesphereEnv gcp.CodesphereEnvironment
23+
}
24+
25+
type BootstrapGcpPostconfigOpts struct {
26+
*GlobalOptions
27+
InstallConfigPath string
28+
PrivateKeyPath string
29+
}
30+
31+
func (c *BootstrapGcpPostconfigCmd) RunE(_ *cobra.Command, args []string) error {
32+
log.Printf("running post-configuration steps...")
33+
34+
icg := installer.NewInstallConfigManager()
35+
36+
fw := util.NewFilesystemWriter()
37+
38+
envFileContent, err := fw.ReadFile(gcp.GetInfraFilePath())
39+
if err != nil {
40+
return fmt.Errorf("failed to read gcp infra file: %w", err)
41+
}
42+
43+
err = json.Unmarshal(envFileContent, &c.CodesphereEnv)
44+
if err != nil {
45+
return fmt.Errorf("failed to unmarshal gcp infra file: %w", err)
46+
}
47+
48+
err = icg.LoadInstallConfigFromFile(c.Opts.InstallConfigPath)
49+
if err != nil {
50+
return fmt.Errorf("failed to load config file: %w", err)
51+
}
52+
53+
return fmt.Errorf("not implemented: run config script on k0s-1 node to install GCP CCM")
54+
}
55+
56+
func AddBootstrapGcpPostconfigCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions) {
57+
postconfig := BootstrapGcpPostconfigCmd{
58+
cmd: &cobra.Command{
59+
Use: "postconfig",
60+
Short: "Run post-configuration steps for GCP bootstrapping",
61+
Long: io.Long(`After bootstrapping GCP infrastructure, this command runs additional configuration steps
62+
to finalize the setup for the Codesphere cluster on GCP:
63+
64+
* Install Google Cloud Controller Manager for ingress management.`),
65+
},
66+
Opts: &BootstrapGcpPostconfigOpts{
67+
GlobalOptions: opts,
68+
},
69+
}
70+
71+
flags := postconfig.cmd.Flags()
72+
flags.StringVar(&postconfig.Opts.InstallConfigPath, "install-config-path", "config.yaml", "Path to the installation configuration file")
73+
flags.StringVar(&postconfig.Opts.PrivateKeyPath, "private-key-path", "", "Path to the GCP service account private key file (optional)")
74+
75+
bootstrapGcp.AddCommand(postconfig.cmd)
76+
postconfig.cmd.RunE = postconfig.RunE
77+
}

docs/oms-cli_beta_bootstrap-gcp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ oms-cli beta bootstrap-gcp [flags]
4545
### SEE ALSO
4646

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## oms-cli beta bootstrap-gcp postconfig
2+
3+
Run post-configuration steps for GCP bootstrapping
4+
5+
### Synopsis
6+
7+
After bootstrapping GCP infrastructure, this command runs additional configuration steps
8+
to finalize the setup for the Codesphere cluster on GCP:
9+
10+
* Install Google Cloud Controller Manager for ingress management.
11+
12+
```
13+
oms-cli beta bootstrap-gcp postconfig [flags]
14+
```
15+
16+
### Options
17+
18+
```
19+
-h, --help help for postconfig
20+
--install-config-path string Path to the installation configuration file (default "config.yaml")
21+
--private-key-path string Path to the GCP service account private key file (optional)
22+
```
23+
24+
### SEE ALSO
25+
26+
* [oms-cli beta bootstrap-gcp](oms-cli_beta_bootstrap-gcp.md) - Bootstrap GCP infrastructure for Codesphere
27+

0 commit comments

Comments
 (0)