Skip to content

Commit

Permalink
fix panic when inferring stack with empty image
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
  • Loading branch information
andreafalzetti committed May 23, 2024
1 parent 98675e6 commit edd9899
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/model/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
oktetoLog "github.com/okteto/okteto/pkg/log"
"github.com/okteto/okteto/pkg/model/forward"
"github.com/spf13/afero"
yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
yaml3 "gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -1052,6 +1052,14 @@ func (m *Manifest) InferFromStack(cwd string) (*Manifest, error) {

svcInfo.Build = buildInfo
} else {
if buildInfo == nil {
buildInfo = &build.Info{}
}

if len(svcInfo.VolumeMounts) > 0 {
buildInfo.VolumesToInclude = svcInfo.VolumeMounts
}

if svcInfo.Image != "" {
buildInfo.Image = svcInfo.Image
}
Expand Down
45 changes: 45 additions & 0 deletions pkg/model/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,51 @@ func TestInferFromStack(t *testing.T) {
},
},
},
{
name: "infer from stack empty build section and empty image",
currentManifest: &Manifest{
Deploy: &DeployInfo{
Image: constants.OktetoPipelineRunnerImage,
ComposeSection: &ComposeSectionInfo{
Stack: &Stack{
Services: map[string]*Service{
"test": {
Build: nil,
Image: "",
Ports: []Port{
{
HostPort: 8080,
ContainerPort: 8080,
},
},
},
},
},
},
},
},
expectedManifest: &Manifest{
Destroy: &DestroyInfo{},
Deploy: &DeployInfo{
Image: constants.OktetoPipelineRunnerImage,
ComposeSection: &ComposeSectionInfo{
Stack: &Stack{
Services: map[string]*Service{
"test": {
Image: "",
Ports: []Port{
{
HostPort: 8080,
ContainerPort: 8080,
},
},
},
},
},
},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit edd9899

Please sign in to comment.