(repository string, image string, version string, imagePathEnvName string)
| 23 | ) |
| 24 | |
| 25 | func ImagePath(repository string, image string, version string, imagePathEnvName string) (string, error) { |
| 26 | // ImagePath is obtained using following priority |
| 27 | // 1. CR (i.e through repository/image/path variables in CRD) |
| 28 | var crdImagePath string |
| 29 | if repository == "" && version == "" { |
| 30 | if image != "" { |
| 31 | // this is useful for tools like kbld(carvel) which transform templates into image as path@digest |
| 32 | crdImagePath = image |
| 33 | } |
| 34 | } else { |
| 35 | // use @ if image digest is specified instead of tag |
| 36 | if strings.HasPrefix(version, "sha256:") { |
| 37 | crdImagePath = repository + "/" + image + "@" + version |
| 38 | } else { |
| 39 | crdImagePath = repository + "/" + image + ":" + version |
| 40 | } |
| 41 | } |
| 42 | if crdImagePath != "" { |
| 43 | return crdImagePath, nil |
| 44 | } |
| 45 | |
| 46 | // 2. Env passed to GPU Operator Pod (eg OLM) |
| 47 | envImagePath := os.Getenv(imagePathEnvName) |
| 48 | if envImagePath != "" { |
| 49 | return envImagePath, nil |
| 50 | } |
| 51 | |
| 52 | // 3. If both are not set, error out |
| 53 | return "", fmt.Errorf("empty image path provided through both CR and ENV %s", imagePathEnvName) |
| 54 | } |
no outgoing calls
no test coverage detected