Run is responsible for perform the nodeup process
(out io.Writer)
| 81 | |
| 82 | // Run is responsible for perform the nodeup process |
| 83 | func (c *NodeUpCommand) Run(out io.Writer) error { |
| 84 | ctx := context.Background() |
| 85 | |
| 86 | var bootConfig nodeup.BootConfig |
| 87 | if c.ConfigLocation != "" { |
| 88 | b, err := vfs.Context.ReadFile(c.ConfigLocation) |
| 89 | if err != nil { |
| 90 | return fmt.Errorf("error loading configuration %q: %v", c.ConfigLocation, err) |
| 91 | } |
| 92 | |
| 93 | err = utils.YamlUnmarshal(b, &bootConfig) |
| 94 | if err != nil { |
| 95 | return fmt.Errorf("error parsing configuration %q: %v", c.ConfigLocation, err) |
| 96 | } |
| 97 | } else { |
| 98 | return fmt.Errorf("ConfigLocation is required") |
| 99 | } |
| 100 | |
| 101 | if c.CacheDir == "" { |
| 102 | return fmt.Errorf("CacheDir is required") |
| 103 | } |
| 104 | |
| 105 | region, err := getRegion(ctx, &bootConfig) |
| 106 | if err != nil { |
| 107 | return err |
| 108 | } |
| 109 | if err = seedRNG(ctx, &bootConfig, region); err != nil { |
| 110 | return err |
| 111 | } |
| 112 | |
| 113 | var configBase vfs.Path |
| 114 | |
| 115 | // If we're using a config server instead of vfs, nodeConfig will hold our configuration |
| 116 | var nodeConfig *nodeup.NodeConfig |
| 117 | |
| 118 | if bootConfig.ConfigServer != nil && len(bootConfig.ConfigServer.Servers) > 0 { |
| 119 | response, err := getNodeConfigFromServers(ctx, &bootConfig, region) |
| 120 | if err != nil { |
| 121 | return fmt.Errorf("failed to get node config from server: %w", err) |
| 122 | } |
| 123 | nodeConfig = response.NodeConfig |
| 124 | } else if fi.ValueOf(bootConfig.ConfigBase) != "" { |
| 125 | var err error |
| 126 | configBase, err = vfs.Context.BuildVfsPath(*bootConfig.ConfigBase) |
| 127 | if err != nil { |
| 128 | return fmt.Errorf("cannot parse ConfigBase %q: %v", *bootConfig.ConfigBase, err) |
| 129 | } |
| 130 | } else { |
| 131 | return fmt.Errorf("ConfigBase or ConfigServer is required") |
| 132 | } |
| 133 | |
| 134 | var nodeupConfig nodeup.Config |
| 135 | var nodeupConfigHash [32]byte |
| 136 | switch { |
| 137 | case nodeConfig != nil: |
| 138 | if err := utils.YamlUnmarshal([]byte(nodeConfig.NodeupConfig), &nodeupConfig); err != nil { |
| 139 | return fmt.Errorf("error parsing BootConfig config response: %v", err) |
| 140 | } |
no test coverage detected