Skip to content

Commit

Permalink
keep port when exists (#4018)
Browse files Browse the repository at this point in the history
* use negative target port as the way to know the target port should not be changed

* update generation instead of the quick hack

* test
  • Loading branch information
vhvb1989 committed Jun 18, 2024
1 parent 8eddbc5 commit 4da74ab
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 7 deletions.
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 {
// 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

0 comments on commit 4da74ab

Please sign in to comment.