1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414//
15+
1516// Package images is intended to support deploying the operator on restricted networks. It contains
1617// utilities for translating images referenced by environment variables to regular image references,
1718// allowing images that are defined by a tag to be replaced by digests automatically. This allows all
@@ -25,18 +26,13 @@ package images
2526import (
2627 "fmt"
2728 "os"
28- "regexp"
2929
30- dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
3130 logf "sigs.k8s.io/controller-runtime/pkg/log"
3231)
3332
3433var log = logf .Log .WithName ("container-images" )
3534
36- var envRegexp = regexp .MustCompile (`\${(RELATED_IMAGE_.*)}` )
37-
3835const (
39- webTerminalToolingImageEnvVar = "RELATED_IMAGE_web_terminal_tooling"
4036 webhookServerImageEnvVar = "RELATED_IMAGE_devworkspace_webhook_server"
4137 kubeRBACProxyImageEnvVar = "RELATED_IMAGE_kube_rbac_proxy"
4238 pvcCleanupJobImageEnvVar = "RELATED_IMAGE_pvc_cleanup_job"
@@ -67,17 +63,6 @@ func GetKubeRBACProxyImage() string {
6763 return val
6864}
6965
70- // GetWebTerminalToolingImage returns the image reference for the default web tooling image. Returns
71- // the empty string if environment variable RELATED_IMAGE_web_terminal_tooling is not defined
72- func GetWebTerminalToolingImage () string {
73- val , ok := os .LookupEnv (webTerminalToolingImageEnvVar )
74- if ! ok {
75- log .Error (fmt .Errorf ("environment variable %s is not set" , webTerminalToolingImageEnvVar ), "Could not get web terminal tooling image" )
76- return ""
77- }
78- return val
79- }
80-
8166// GetPVCCleanupJobImage returns the image reference for the PVC cleanup job used to clean workspace
8267// files from the common PVC in a namespace.
8368func GetPVCCleanupJobImage () string {
@@ -107,48 +92,11 @@ func GetAsyncStorageSidecarImage() string {
10792 return val
10893}
10994
110- func GetProjectClonerImage () string {
95+ func GetProjectCloneImage () string {
11196 val , ok := os .LookupEnv (projectCloneImageEnvVar )
11297 if ! ok {
11398 log .Info (fmt .Sprintf ("Could not get initial project clone image: environment variable %s is not set" , projectCloneImageEnvVar ))
11499 return ""
115100 }
116101 return val
117102}
118-
119- // FillPluginEnvVars replaces plugin devworkspaceTemplate .spec.components[].container.image environment
120- // variables of the form ${RELATED_IMAGE_*} with values from environment variables with the same name.
121- //
122- // Returns error if any referenced environment variable is undefined.
123- func FillPluginEnvVars (pluginDWT * dw.DevWorkspaceTemplate ) (* dw.DevWorkspaceTemplate , error ) {
124- for idx , component := range pluginDWT .Spec .Components {
125- if component .Container == nil {
126- continue
127- }
128- img , err := getImageForEnvVar (component .Container .Image )
129- if err != nil {
130- return nil , err
131- }
132- pluginDWT .Spec .Components [idx ].Container .Image = img
133- }
134- return pluginDWT , nil
135- }
136-
137- func isImageEnvVar (query string ) bool {
138- return envRegexp .MatchString (query )
139- }
140-
141- func getImageForEnvVar (envStr string ) (string , error ) {
142- if ! isImageEnvVar (envStr ) {
143- // Value passed in is not env var, return unmodified
144- return envStr , nil
145- }
146- matches := envRegexp .FindStringSubmatch (envStr )
147- env := matches [1 ]
148- val , ok := os .LookupEnv (env )
149- if ! ok {
150- log .Info (fmt .Sprintf ("Environment variable '%s' is unset. Cannot determine image to use" , env ))
151- return "" , fmt .Errorf ("environment variable %s is unset" , env )
152- }
153- return val , nil
154- }
0 commit comments