Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep port when exists #4018

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/azd/pkg/apphost/aca_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func pickIngress(endpointByTargetPortProperties map[string]*acaPort, httpIngress
finalIngress.TargetPort = props.port
if finalIngress.TargetPort == 0 {
finalIngress.TargetPort = defaultPort
finalIngress.UsingDefaultPort = true
}
finalIngress.Transport = acaIngressSchemaHttp
if props.hasHttp2 {
Expand Down
2 changes: 2 additions & 0 deletions cli/azd/pkg/apphost/aca_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestBuildAcaIngress(t *testing.T) {
Transport: acaIngressTransportHttp2,
AllowInsecure: true,
AdditionalPortMappings: []genContainerAppIngressAdditionalPortMappings(nil),
UsingDefaultPort: true,
}
ingress, ingressBinding, err := buildAcaIngress(bindings, 8080)
assert.NoError(t, err)
Expand Down Expand Up @@ -176,6 +177,7 @@ func TestBuildAcaIngress(t *testing.T) {
},
},
},
UsingDefaultPort: true,
}
ingress, ingressBinding, err := buildAcaIngress(bindings, 8080)
assert.NoError(t, err)
Expand Down
14 changes: 13 additions & 1 deletion cli/azd/pkg/apphost/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,19 @@ func ContainerAppManifestTemplateForProject(

var buf bytes.Buffer

tmplCtx := generator.containerAppTemplateContexts[projectName]
type yamlTemplateCtx struct {
genContainerAppManifestTemplateContext
TargetPortExpression string
}
tCtx := generator.containerAppTemplateContexts[projectName]
tmplCtx := yamlTemplateCtx{
genContainerAppManifestTemplateContext: tCtx,
TargetPortExpression: fmt.Sprintf("{{ targetPortOrDefault %d }}", tCtx.Ingress.TargetPort),
}
if tCtx.Ingress.TargetPort != 0 && !tCtx.Ingress.UsingDefaultPort {
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
// not using default port makes this to be a non-changing value
tmplCtx.TargetPortExpression = fmt.Sprintf("%d", tCtx.Ingress.TargetPort)
}

err := genTemplates.ExecuteTemplate(&buf, "containerApp.tmpl.yaml", tmplCtx)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cli/azd/pkg/apphost/generate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type genContainerAppIngress struct {
genContainerAppIngressPort
Transport string
AllowInsecure bool
UsingDefaultPort bool
AdditionalPortMappings []genContainerAppIngressAdditionalPortMappings
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ properties:
autoConfigureDataProtection: true
ingress:
external: false
targetPort: {{ targetPortOrDefault 9092 }}
targetPort: 9092
exposedPort: 6000
transport: tcp
allowInsecure: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ properties:
autoConfigureDataProtection: true
ingress:
external: false
targetPort: {{ targetPortOrDefault 3306 }}
targetPort: 3306
transport: tcp
allowInsecure: false
registries:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ properties:
autoConfigureDataProtection: true
ingress:
external: false
targetPort: {{ targetPortOrDefault 3306 }}
targetPort: 3306
transport: tcp
allowInsecure: false
registries:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ properties:
autoConfigureDataProtection: true
ingress:
external: true
targetPort: {{ targetPortOrDefault 3000 }}
targetPort: 3000
transport: http
allowInsecure: false
registries:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ properties:
{{- end}}
{{- end}}
external: {{ .Ingress.External }}
targetPort: {{ "{{ targetPortOrDefault " }}{{ .Ingress.TargetPort }}{{ " }}" }}
targetPort: {{ .TargetPortExpression }}
{{- if gt .Ingress.ExposedPort 0 }}
exposedPort: {{ .Ingress.ExposedPort }}
{{- end}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ properties:
autoConfigureDataProtection: true
ingress:
external: false
targetPort: {{ targetPortOrDefault 6379 }}
targetPort: 6379
transport: tcp
allowInsecure: false
registries:
Expand Down
Loading