Skip to content

Commit aeea596

Browse files
committed
fix: do not replace manifest values by matching image config names
1 parent f61de88 commit aeea596

8 files changed

Lines changed: 222 additions & 129 deletions

File tree

e2e/tests/localregistry/localregistry.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ var _ = DevSpaceDescribe("localregistry", func() {
119119
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container2"), pollingDurationLong, pollingInterval).
120120
Should(gomega.MatchRegexp(`^localhost`))
121121

122-
ginkgo.By("Checking deployment container3")
123-
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container3"), pollingDurationLong, pollingInterval).
124-
Should(gomega.MatchRegexp(`^localhost`))
125-
126122
err = <-done
127123
framework.ExpectNoError(err)
128124
})
@@ -187,10 +183,6 @@ var _ = DevSpaceDescribe("localregistry", func() {
187183
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container2"), pollingDurationLong, pollingInterval).
188184
Should(gomega.MatchRegexp(`^localhost`))
189185

190-
ginkgo.By("Checking deployment container3")
191-
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container3"), pollingDurationLong, pollingInterval).
192-
Should(gomega.MatchRegexp(`^localhost`))
193-
194186
err = <-done
195187
framework.ExpectNoError(err)
196188
})
@@ -231,10 +223,6 @@ var _ = DevSpaceDescribe("localregistry", func() {
231223
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container2"), pollingDurationLong, pollingInterval).
232224
Should(gomega.MatchRegexp(`^localhost`))
233225

234-
ginkgo.By("Checking deployment container3")
235-
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container3"), pollingDurationLong, pollingInterval).
236-
Should(gomega.MatchRegexp(`^localhost`))
237-
238226
err = <-done
239227
framework.ExpectNoError(err)
240228
})

e2e/tests/localregistry/testdata/local-registry-buildkit/devspace.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ deployments:
1515
image: image(app):tag(app)
1616
- name: container2
1717
image: my-docker-username/helloworld
18-
- name: container3
19-
image: app
2018
dev:
2119
app:
2220
labelSelector:

e2e/tests/localregistry/testdata/local-registry-docker/devspace.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ deployments:
1414
image: image(app):tag(app)
1515
- name: container2
1616
image: my-docker-username/helloworld
17-
- name: container3
18-
image: app
1917
dev:
2018
app:
2119
imageSelector: my-docker-username/helloworld

e2e/tests/localregistry/testdata/local-registry-image-selectors/devspace.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ deployments:
1616
image: image(app):tag(app)
1717
- name: container2
1818
image: my-docker-username/helloworld
19-
- name: container3
20-
image: app
2119
dev:
2220
app:
2321
imageSelector: my-docker-username/helloworld

e2e/tests/localregistry/testdata/local-registry-kubectl/manifests/deployment.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,5 @@ spec:
5555
name: "container1"
5656
- image: image(app):tag(app)
5757
name: "container2"
58-
- image: app
59-
name: "container3"
6058
initContainers:
6159
volumes:

pkg/devspace/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,12 @@ func Ensure(config Config) Config {
113113
retConfig = NewConfig(retConfig.Raw(), retConfig.RawBeforeConversion(), retConfig.Config(), retConfig.LocalCache(), retConfig.RemoteCache(), map[string]interface{}{}, retConfig.Path())
114114
}
115115

116+
if config != nil {
117+
runtimeVars := config.ListRuntimeVariables()
118+
for k, v := range runtimeVars {
119+
retConfig.SetRuntimeVariable(k, v)
120+
}
121+
}
122+
116123
return retConfig
117124
}

pkg/devspace/config/loader/variable/legacy/replace.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
buildtypes "github.com/loft-sh/devspace/pkg/devspace/build/types"
99
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
10+
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
1011
"github.com/loft-sh/devspace/pkg/devspace/imageselector"
1112
"github.com/loft-sh/devspace/pkg/util/dockerfile"
1213

@@ -92,9 +93,24 @@ func resolveImage(value string, config config2.Config, dependencies []types.Depe
9293
// strip out images from cache that are not in the images conf anymore
9394
imageCacheMap := config.LocalCache().ListImageCache()
9495

96+
// Find matching image in image cache
97+
var imageCache *localcache.ImageCache
98+
if tryImageKey {
99+
if match, ok := imageCacheMap[value]; ok {
100+
imageCache = &match
101+
}
102+
} else {
103+
for _, match := range imageCacheMap {
104+
if match.ImageName == value {
105+
imageCache = &match
106+
break
107+
}
108+
}
109+
}
110+
95111
// strip original image name
96112
originalImage := ""
97-
if imageCache, ok := imageCacheMap[value]; ok {
113+
if imageCache != nil {
98114
strippedImage, _, err := dockerfile.GetStrippedDockerImageName(imageCache.ImageName)
99115
if err != nil {
100116
return false, false, "", nil
@@ -117,6 +133,23 @@ func resolveImage(value string, config config2.Config, dependencies []types.Depe
117133
}
118134
}
119135

136+
// Found a match in the image cache
137+
if imageCache != nil {
138+
if onlyImage {
139+
return true, shouldRedeploy, imageCache.ResolveImage(), nil
140+
}
141+
142+
if onlyTag {
143+
if imageCache.Tag == "" {
144+
return true, shouldRedeploy, "latest", nil
145+
}
146+
147+
return true, shouldRedeploy, imageCache.Tag, nil
148+
}
149+
150+
return true, shouldRedeploy, imageCache.ResolveImage() + ":" + imageCache.Tag, nil
151+
}
152+
120153
// config images
121154
configImages := config.Config().Images
122155
if configImages == nil {
@@ -210,7 +243,8 @@ func Replace(value string, config config2.Config, dependencies []types.Dependenc
210243
return shouldRedeploy, resolvedImage, nil
211244
}
212245

213-
return ReplaceHelpers(value, config, dependencies)
246+
helperShouldRedeploy, helperResolvedImage, err := ReplaceHelpers(value, config, dependencies)
247+
return shouldRedeploy || helperShouldRedeploy, helperResolvedImage, err
214248
}
215249

216250
func ReplaceHelpers(value string, config config2.Config, dependencies []types.Dependency) (bool, interface{}, error) {

0 commit comments

Comments
 (0)