-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbootstrap_gcp_postconfig.go
More file actions
77 lines (60 loc) · 2.26 KB
/
bootstrap_gcp_postconfig.go
File metadata and controls
77 lines (60 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
}