AddKubectlDeployment adds a new kubectl deployment to the provided config
(deploymentName string, isKustomization bool)
| 25 | |
| 26 | // AddKubectlDeployment adds a new kubectl deployment to the provided config |
| 27 | func (m *manager) AddKubectlDeployment(deploymentName string, isKustomization bool) error { |
| 28 | question := "Please enter the paths to your Kubernetes manifests (comma separated, glob patterns are allowed, e.g. 'manifests/**' or 'kube/pod.yaml') [Enter to abort]" |
| 29 | if isKustomization { |
| 30 | question = "Please enter path to your Kustomization folder (e.g. ./kube/kustomization/)" |
| 31 | } |
| 32 | |
| 33 | manifests, err := m.log.Question(&survey.QuestionOptions{ |
| 34 | Question: question, |
| 35 | ValidationFunc: func(value string) error { |
| 36 | if value == "" { |
| 37 | return nil |
| 38 | } |
| 39 | |
| 40 | if isKustomization { |
| 41 | fileNames := []string{"kustomization.yaml", "kustomization.yml"} |
| 42 | for _, fileName := range fileNames { |
| 43 | stat, err := os.Stat(path.Join(value, fileName)) |
| 44 | if err == nil && !stat.IsDir() { |
| 45 | return nil |
| 46 | } |
| 47 | } |
| 48 | return fmt.Errorf("path `%s` is not a Kustomization (kustomization.yaml or kustomization.yml missing)", value) |
| 49 | } else { |
| 50 | matches, err := filepath.Glob(value) |
| 51 | if err != nil { |
| 52 | return fmt.Errorf("path `%s` is not a valid glob pattern", value) |
| 53 | } |
| 54 | if len(matches) == 0 { |
| 55 | return fmt.Errorf("path `%s` did not match any manifests", value) |
| 56 | } |
| 57 | } |
| 58 | return nil |
| 59 | }, |
| 60 | }) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | if manifests == "" { |
| 66 | return fmt.Errorf("adding kubectl deployment aborted") |
| 67 | } |
| 68 | |
| 69 | splitted := strings.Split(manifests, ",") |
| 70 | splittedPointer := []string{} |
| 71 | |
| 72 | for _, s := range splitted { |
| 73 | trimmed := strings.TrimSpace(s) |
| 74 | splittedPointer = append(splittedPointer, trimmed) |
| 75 | } |
| 76 | |
| 77 | if m.config.Deployments == nil { |
| 78 | m.config.Deployments = map[string]*latest.DeploymentConfig{} |
| 79 | } |
| 80 | m.config.Deployments[deploymentName] = &latest.DeploymentConfig{ |
| 81 | Name: deploymentName, |
| 82 | Kubectl: &latest.KubectlConfig{ |
| 83 | Manifests: splittedPointer, |
| 84 | }, |