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

[ACA] Persist current custom domain #3955

Merged
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
42 changes: 32 additions & 10 deletions cli/azd/pkg/containerapps/container_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3"
azdinternal "github.com/azure/azure-dev/cli/azd/internal"
"github.com/azure/azure-dev/cli/azd/pkg/account"
"github.com/azure/azure-dev/cli/azd/pkg/alpha"
"github.com/azure/azure-dev/cli/azd/pkg/config"
"github.com/azure/azure-dev/cli/azd/pkg/convert"
"github.com/azure/azure-dev/cli/azd/pkg/httputil"
"github.com/benbjohnson/clock"
Expand Down Expand Up @@ -59,22 +61,25 @@ func NewContainerAppService(
httpClient httputil.HttpClient,
clock clock.Clock,
armClientOptions *arm.ClientOptions,
alphaFeatureManager *alpha.FeatureManager,
) ContainerAppService {
return &containerAppService{
credentialProvider: credentialProvider,
httpClient: httpClient,
userAgent: azdinternal.UserAgent(),
clock: clock,
armClientOptions: armClientOptions,
credentialProvider: credentialProvider,
httpClient: httpClient,
userAgent: azdinternal.UserAgent(),
clock: clock,
armClientOptions: armClientOptions,
alphaFeatureManager: alphaFeatureManager,
}
}

type containerAppService struct {
credentialProvider account.SubscriptionCredentialProvider
httpClient httputil.HttpClient
userAgent string
clock clock.Clock
armClientOptions *arm.ClientOptions
credentialProvider account.SubscriptionCredentialProvider
httpClient httputil.HttpClient
userAgent string
clock clock.Clock
armClientOptions *arm.ClientOptions
alphaFeatureManager *alpha.FeatureManager
}

type ContainerAppIngressConfiguration struct {
Expand Down Expand Up @@ -112,6 +117,8 @@ func (cas *containerAppService) GetIngressConfiguration(
// or updating the container app. When unset, we use the default API version of the armappcontainers.ContainerAppsClient.
const apiVersionKey = "api-version"

var persistCustomDomainsFeature = alpha.MustFeatureKey("aca.persistDomains")

func (cas *containerAppService) DeployYaml(
ctx context.Context,
subscriptionId string,
Expand All @@ -124,6 +131,21 @@ func (cas *containerAppService) DeployYaml(
return fmt.Errorf("decoding yaml: %w", err)
}

if shouldPersist := cas.alphaFeatureManager.IsEnabled(persistCustomDomainsFeature); shouldPersist {
aca, err := cas.getContainerApp(ctx, subscriptionId, resourceGroupName, appName)
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
if err == nil {
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
acaAsConfig := config.NewConfig(obj)
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
err := acaAsConfig.Set(
"properties.configuration.ingress.customDomains", aca.Properties.Configuration.Ingress.CustomDomains)

if err == nil {
obj = acaAsConfig.Raw()
} else {
log.Printf("failed to set custom domains: %v. Domains will be ignored.", err)
}
}
}

var poller *runtime.Poller[armappcontainers.ContainerAppsClientCreateOrUpdateResponse]

// The way we make the initial request depends on whether the apiVersion is specified in the YAML.
Expand Down
2 changes: 2 additions & 0 deletions cli/azd/pkg/containerapps/container_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func Test_ContainerApp_GetIngressConfiguration(t *testing.T) {
mockContext.HttpClient,
clock.NewMock(),
mockContext.ArmClientOptions,
mockContext.AlphaFeaturesManager,
)
ingressConfig, err := cas.GetIngressConfiguration(*mockContext.Context, subscriptionId, resourceGroup, appName)
require.NoError(t, err)
Expand Down Expand Up @@ -137,6 +138,7 @@ func Test_ContainerApp_AddRevision(t *testing.T) {
mockContext.HttpClient,
clock.NewMock(),
mockContext.ArmClientOptions,
mockContext.AlphaFeaturesManager,
)
err := cas.AddRevision(*mockContext.Context, subscriptionId, resourceGroup, appName, updatedImageName)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions cli/azd/pkg/project/service_target_containerapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func createContainerAppServiceTarget(
mockContext.HttpClient,
clock.NewMock(),
mockContext.ArmClientOptions,
mockContext.AlphaFeaturesManager,
)
containerRegistryService := azcli.NewContainerRegistryService(
credentialProvider,
Expand Down
2 changes: 2 additions & 0 deletions cli/azd/resources/alpha_features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
description: "Enable Helm support for AKS deployments."
- id: aks.kustomize
description: "Enable Kustomize support for AKS deployments."
- id: aca.persistDomains
description: "Do not change custom domains when deploying Azure Container Apps."
Loading