(ctx context.Context, environ expand.Environ, dir, manifest string)
| 109 | } |
| 110 | |
| 111 | func (k *kubectlBuilder) Build(ctx context.Context, environ expand.Environ, dir, manifest string) ([]*unstructured.Unstructured, error) { |
| 112 | tempFile, err := os.CreateTemp("", "") |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | defer os.Remove(tempFile.Name()) |
| 117 | |
| 118 | data, err := clientcmd.Write(k.kubeConfig) |
| 119 | if err != nil { |
| 120 | return nil, err |
| 121 | } |
| 122 | |
| 123 | _, err = tempFile.Write(data) |
| 124 | if err != nil { |
| 125 | return nil, err |
| 126 | } |
| 127 | _ = tempFile.Close() |
| 128 | |
| 129 | args := []string{"create"} |
| 130 | |
| 131 | // decides which --dry-run value is to be used |
| 132 | uodr, err := useOldDryRun(ctx, environ, dir, k.path) |
| 133 | if err != nil { |
| 134 | return nil, err |
| 135 | } |
| 136 | |
| 137 | if uodr { |
| 138 | args = append(args, "--dry-run", "--output", "yaml", "--validate=false") |
| 139 | } else { |
| 140 | args = append(args, "--dry-run=client", "--output", "yaml", "--validate=false") |
| 141 | } |
| 142 | |
| 143 | if k.config.Kubectl.Kustomize != nil && *k.config.Kubectl.Kustomize { |
| 144 | args = append(args, "--kustomize", manifest) |
| 145 | } else { |
| 146 | args = append(args, "--filename", manifest) |
| 147 | } |
| 148 | |
| 149 | // Add extra args |
| 150 | args = append(args, k.config.Kubectl.CreateArgs...) |
| 151 | |
| 152 | // Execute command |
| 153 | output, err := command.Output(ctx, dir, env.NewVariableEnvProvider(environ, map[string]string{ |
| 154 | "KUBECONFIG": tempFile.Name(), |
| 155 | }), k.path, args...) |
| 156 | if err != nil { |
| 157 | exitError, ok := err.(*exec.ExitError) |
| 158 | if ok { |
| 159 | return nil, errors.New(string(exitError.Stderr)) |
| 160 | } |
| 161 | |
| 162 | return nil, err |
| 163 | } |
| 164 | |
| 165 | return stringToUnstructuredArray(string(output)) |
| 166 | } |
| 167 | |
| 168 | var diffSeparator = regexp.MustCompile(`\n---`) |
nothing calls this directly
no test coverage detected