// MakeKubernetesPlatform constructor func MakeKubernetesPlatform(buildDir, env, pathToServicesFile, pathToSecretsFile, pathToEnvFile string) (*KubernetesPlatform, error) { if ok := utils.Exists(pathToServicesFile); !ok { return nil, errors.Trace(errors.Errorf("File [%s] not found", pathToEnvFile)) } if ok := utils.Exists(pathToSecretsFile); !ok { return nil, errors.Trace(errors.Errorf("File [%s] not found", pathToEnvFile)) } if ok := utils.Exists(pathToEnvFile); !ok { return nil, errors.Trace(errors.Errorf("File [%s] not found", pathToEnvFile)) } data, err := ioutil.ReadFile(pathToServicesFile) if err != nil { return nil, err } srvs := Services{} err = json.Unmarshal(data, &srvs) if err != nil { return nil, err } data, err = ioutil.ReadFile(pathToSecretsFile) if err != nil { return nil, err } secrets := map[string]interface{}{} err = json.Unmarshal(data, &secrets) if err != nil { return nil, err } data, err = ioutil.ReadFile(pathToEnvFile) if err != nil { return nil, err } envVars := map[string]interface{}{} err = json.Unmarshal(data, &envVars) if err != nil { return nil, err } srvs.LoadSecrets(secrets) srvs.LoadEnvVars(envVars) k8s := &KubernetesPlatform{ Services: srvs, BuildDir: buildDir, Env: Environment(env), } return k8s, nil }
func makeDefaultGenerator(tpl, outputPath string) *defaultGenerator { outputPath = strings.TrimRight(outputPath, "/") outputPath = outputPath + string(filepath.Separator) + "gen" ok := utils.Exists(outputPath) if !ok { if err := os.Mkdir(outputPath, 0777); err != nil { log.Fatalf("Could not make dir, %s", err) } } outputFile := outputPath + string(filepath.Separator) + FILE_NAME_INIT return &defaultGenerator{ tpl: tpl, outputFile: outputFile, vm: &viewModel{ PackageName: "gen", Imports: codegen.Imports{ "github.com/nildev/lib/router": codegen.Import{ Alias: "", Path: "github.com/nildev/lib/router", }, }, Services: codegen.Services{}, }, } }
// GenerateReplicationControllers renders k8s ReplicationControllers func GenerateReplicationControllers(outputFile string, rcvm RCViewModel) { basePath := filepath.Dir(outputFile) ok := utils.Exists(basePath) if !ok { if err := os.Mkdir(basePath, 0777); err != nil { log.Fatalf("Could not make dir, %s", err) } } // Open file that we will write all content to output, err := os.OpenFile(outputFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { log.Fatalf("Could not open output file: %s", err) } defer func() { err := output.Close() if err != nil { log.Fatal("Could not close file!", err) } }() if err := codegen.Render(output, string(ReplicationControllerTemplate), rcvm); err != nil { log.Fatalf("Could not render replication controller: %s", err) } }