Skip to content

Commit

Permalink
Merge pull request #2445 from lizardruss/fix-replace-images
Browse files Browse the repository at this point in the history
v6.2.0 Replaces containers names with image tags
  • Loading branch information
FabianKramm authored Nov 30, 2022
2 parents f61de88 + aeea596 commit 796ab32
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 129 deletions.
12 changes: 0 additions & 12 deletions e2e/tests/localregistry/localregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ var _ = DevSpaceDescribe("localregistry", func() {
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container2"), pollingDurationLong, pollingInterval).
Should(gomega.MatchRegexp(`^localhost`))

ginkgo.By("Checking deployment container3")
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container3"), pollingDurationLong, pollingInterval).
Should(gomega.MatchRegexp(`^localhost`))

err = <-done
framework.ExpectNoError(err)
})
Expand Down Expand Up @@ -187,10 +183,6 @@ var _ = DevSpaceDescribe("localregistry", func() {
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container2"), pollingDurationLong, pollingInterval).
Should(gomega.MatchRegexp(`^localhost`))

ginkgo.By("Checking deployment container3")
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container3"), pollingDurationLong, pollingInterval).
Should(gomega.MatchRegexp(`^localhost`))

err = <-done
framework.ExpectNoError(err)
})
Expand Down Expand Up @@ -231,10 +223,6 @@ var _ = DevSpaceDescribe("localregistry", func() {
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container2"), pollingDurationLong, pollingInterval).
Should(gomega.MatchRegexp(`^localhost`))

ginkgo.By("Checking deployment container3")
gomega.Eventually(selectContainerImage(kubeClient, ns, "app", "container3"), pollingDurationLong, pollingInterval).
Should(gomega.MatchRegexp(`^localhost`))

err = <-done
framework.ExpectNoError(err)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ deployments:
image: image(app):tag(app)
- name: container2
image: my-docker-username/helloworld
- name: container3
image: app
dev:
app:
labelSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ deployments:
image: image(app):tag(app)
- name: container2
image: my-docker-username/helloworld
- name: container3
image: app
dev:
app:
imageSelector: my-docker-username/helloworld
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ deployments:
image: image(app):tag(app)
- name: container2
image: my-docker-username/helloworld
- name: container3
image: app
dev:
app:
imageSelector: my-docker-username/helloworld
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,5 @@ spec:
name: "container1"
- image: image(app):tag(app)
name: "container2"
- image: app
name: "container3"
initContainers:
volumes:
7 changes: 7 additions & 0 deletions pkg/devspace/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,12 @@ func Ensure(config Config) Config {
retConfig = NewConfig(retConfig.Raw(), retConfig.RawBeforeConversion(), retConfig.Config(), retConfig.LocalCache(), retConfig.RemoteCache(), map[string]interface{}{}, retConfig.Path())
}

if config != nil {
runtimeVars := config.ListRuntimeVariables()
for k, v := range runtimeVars {
retConfig.SetRuntimeVariable(k, v)
}
}

return retConfig
}
38 changes: 36 additions & 2 deletions pkg/devspace/config/loader/variable/legacy/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

buildtypes "github.com/loft-sh/devspace/pkg/devspace/build/types"
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
"github.com/loft-sh/devspace/pkg/devspace/imageselector"
"github.com/loft-sh/devspace/pkg/util/dockerfile"

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

// Find matching image in image cache
var imageCache *localcache.ImageCache
if tryImageKey {
if match, ok := imageCacheMap[value]; ok {
imageCache = &match
}
} else {
for _, match := range imageCacheMap {
if match.ImageName == value {
imageCache = &match
break
}
}
}

// strip original image name
originalImage := ""
if imageCache, ok := imageCacheMap[value]; ok {
if imageCache != nil {
strippedImage, _, err := dockerfile.GetStrippedDockerImageName(imageCache.ImageName)
if err != nil {
return false, false, "", nil
Expand All @@ -117,6 +133,23 @@ func resolveImage(value string, config config2.Config, dependencies []types.Depe
}
}

// Found a match in the image cache
if imageCache != nil {
if onlyImage {
return true, shouldRedeploy, imageCache.ResolveImage(), nil
}

if onlyTag {
if imageCache.Tag == "" {
return true, shouldRedeploy, "latest", nil
}

return true, shouldRedeploy, imageCache.Tag, nil
}

return true, shouldRedeploy, imageCache.ResolveImage() + ":" + imageCache.Tag, nil
}

// config images
configImages := config.Config().Images
if configImages == nil {
Expand Down Expand Up @@ -210,7 +243,8 @@ func Replace(value string, config config2.Config, dependencies []types.Dependenc
return shouldRedeploy, resolvedImage, nil
}

return ReplaceHelpers(value, config, dependencies)
helperShouldRedeploy, helperResolvedImage, err := ReplaceHelpers(value, config, dependencies)
return shouldRedeploy || helperShouldRedeploy, helperResolvedImage, err
}

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

0 comments on commit 796ab32

Please sign in to comment.