Skip to content

Commit

Permalink
update generation instead of the quick hack
Browse files Browse the repository at this point in the history
  • Loading branch information
vhvb1989 committed Jun 18, 2024
1 parent 9fa2019 commit 5e94e0a
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 16 deletions.
6 changes: 1 addition & 5 deletions cli/azd/pkg/apphost/aca_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ func pickIngress(endpointByTargetPortProperties map[string]*acaPort, httpIngress
finalIngress.TargetPort = props.port
if finalIngress.TargetPort == 0 {
finalIngress.TargetPort = defaultPort
} else {
// negative target port means the target port is defined in the manifest and is not using a default value
// azd won't change the value of the target port after building a dotnet project. azd will just use the
// value defined in the manifest (will remove the negative).
finalIngress.TargetPort *= -1
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
5 changes: 0 additions & 5 deletions cli/azd/pkg/project/service_target_dotnet_containerapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,6 @@ func (at *dotnetContainerAppTarget) Deploy(
"securedParameter": fns.Parameter,
"secretOutput": fns.kvSecret,
"targetPortOrDefault": func(targetPortFromManifest int) int {
if targetPortFromManifest < 0 {
// a negative target port means the target port was defined in the manifest and should not
// be changed.
return targetPortFromManifest * -1
}
// portNumber is 0 for dockerfile.v0, so we use the targetPort from the manifest
if portNumber == 0 {
return targetPortFromManifest
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

0 comments on commit 5e94e0a

Please sign in to comment.