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

AKS Service Target & template #1543

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions .vscode/cspell.global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ignoreWords:
- armauthorization
- armappcontainers
- armappservice
- armcontainerservice
- armkeyvault
- armresources
- armruntime
Expand All @@ -34,6 +35,7 @@ ignoreWords:
- Azdo
- aztfmod
- azurecaf
- azurecr
- azuredevops
- azurerm
- armcontainerregistry
Expand All @@ -48,6 +50,7 @@ ignoreWords:
- configlist
- conjunction
- containerregistry
- containerservice
- databricks
- dedb
- devcontainer
Expand All @@ -73,6 +76,9 @@ ignoreWords:
- JOBOBJECT
- kubernetes
- kusto
- kubeconfig
- kubeconfigs
- kustomize
- magefile
- mainfic
- menuid
Expand Down Expand Up @@ -156,6 +162,7 @@ ignoreWords:
- menuid
- PLACEHOLDERIACTOOLS
- LOGANALYTICS
- webapprouting
- zipdeploy
- appinsights
useGitignore: true
Expand Down
28 changes: 14 additions & 14 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": "${command:pickGoProcess}"
}
]
}
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": "${command:pickGoProcess}"
}
]
}
4 changes: 3 additions & 1 deletion cli/azd/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
credProvider auth.MultiTenantCredentialProvider) (azcore.TokenCredential, error) {
if env == nil {
//nolint:lll
panic("command asked for azcore.TokenCredential, but prerequisite dependency environment.Environment was not registered.")
panic(
"command asked for azcore.TokenCredential, but prerequisite dependency environment. Environment was not registered.",
)
}

subscriptionId := env.GetSubscriptionId()
Expand Down
6 changes: 5 additions & 1 deletion cli/azd/pkg/account/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ func Test_GetAccountDefaults(t *testing.T) {
require.NoError(t, err)

accountDefaults, err := manager.GetAccountDefaults(context.Background())
require.Equal(t, &Account{DefaultSubscription: (*Subscription)(nil), DefaultLocation: (&defaultLocation)}, accountDefaults)
require.Equal(
t,
&Account{DefaultSubscription: (*Subscription)(nil), DefaultLocation: (&defaultLocation)},
accountDefaults,
)
require.NoError(t, err)
})

Expand Down
18 changes: 18 additions & 0 deletions cli/azd/pkg/azure/resource_ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ func WebsiteRID(subscriptionId, resourceGroupName, websiteName string) string {
return returnValue
}

func AksRID(subscriptionId, resourceGroupName, clusterName string) string {
returnValue := fmt.Sprintf(
"%s/providers/Microsoft.ContainerService/managedClusters/%s",
ResourceGroupRID(subscriptionId, resourceGroupName),
clusterName,
)
return returnValue
}

func ContainerAppRID(subscriptionId, resourceGroupName, containerAppName string) string {
returnValue := fmt.Sprintf(
"%s/providers/Microsoft.App/containerApps/%s",
Expand All @@ -60,6 +69,15 @@ func ContainerAppRID(subscriptionId, resourceGroupName, containerAppName string)
return returnValue
}

func KubernetesServiceRID(subscriptionId, resourceGroupName, clusterName string) string {
returnValue := fmt.Sprintf(
"%s/providers/Microsoft.ContainerService/managedClusters/%s",
ResourceGroupRID(subscriptionId, resourceGroupName),
clusterName,
)
return returnValue
}

func StaticWebAppRID(subscriptionId, resourceGroupName, staticSiteName string) string {
returnValue := fmt.Sprintf(
"%s/providers/Microsoft.Web/staticSites/%s",
Expand Down
3 changes: 3 additions & 0 deletions cli/azd/pkg/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const TenantIdEnvVarName = "AZURE_TENANT_ID"
// to.
const ContainerRegistryEndpointEnvVarName = "AZURE_CONTAINER_REGISTRY_ENDPOINT"

// AksClusterEnvVarName is the name of they key used to store the endpoint of the AKS cluster to push to.
const AksClusterEnvVarName = "AZURE_AKS_CLUSTER_NAME"
wbreza marked this conversation as resolved.
Show resolved Hide resolved

// ResourceGroupEnvVarName is the name of the azure resource group that should be used for deployments
const ResourceGroupEnvVarName = "AZURE_RESOURCE_GROUP"

Expand Down
11 changes: 9 additions & 2 deletions cli/azd/pkg/exec/command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ func (r *commandRunner) Run(ctx context.Context, args RunArgs) (RunResult, error

cmd.Dir = args.Cwd

var stdin, stdout, stderr bytes.Buffer
var stdin io.Reader
if args.StdIn != nil {
stdin = args.StdIn
} else {
stdin = new(bytes.Buffer)
}

var stdout, stderr bytes.Buffer

cmd.Env = appendEnv(args.Env)

Expand All @@ -67,7 +74,7 @@ func (r *commandRunner) Run(ctx context.Context, args RunArgs) (RunResult, error
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
} else {
cmd.Stdin = &stdin
cmd.Stdin = stdin
cmd.Stdout = &stdout
cmd.Stderr = &stderr

Expand Down
8 changes: 8 additions & 0 deletions cli/azd/pkg/exec/runargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type RunArgs struct {

// When set will attach commands to std input/output
Interactive bool

// When set will call the command with the specified StdIn
StdIn io.Reader
}

// NewRunArgs creates a new instance with the specified cmd and args
Expand Down Expand Up @@ -81,3 +84,8 @@ func (b RunArgs) WithDebug(debug bool) RunArgs {
b.Debug = debug
return b
}

func (b RunArgs) WithStdIn(stdIn io.Reader) RunArgs {
b.StdIn = stdIn
return b
}
9 changes: 9 additions & 0 deletions cli/azd/pkg/infra/azure_resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const (
AzureResourceTypeResourceGroup AzureResourceType = "Microsoft.Resources/resourceGroups"
AzureResourceTypeStorageAccount AzureResourceType = "Microsoft.Storage/storageAccounts"
AzureResourceTypeStaticWebSite AzureResourceType = "Microsoft.Web/staticSites"
AzureResourceTypeContainerRegistry AzureResourceType = "Microsoft.ContainerRegistry/registries"
AzureResourceTypeManagedCluster AzureResourceType = "Microsoft.ContainerService/managedClusters"
AzureResourceTypeServicePlan AzureResourceType = "Microsoft.Web/serverfarms"
AzureResourceTypeAgentPool AzureResourceType = "Microsoft.ContainerService/managedClusters/agentPools"
AzureResourceTypeSqlServer AzureResourceType = "Microsoft.Sql/servers"
AzureResourceTypeVirtualNetwork AzureResourceType = "Microsoft.Network/virtualNetworks"
AzureResourceTypeWebSite AzureResourceType = "Microsoft.Web/sites"
Expand Down Expand Up @@ -78,6 +81,12 @@ func GetResourceTypeDisplayName(resourceType AzureResourceType) string {
return "Load Tests"
case AzureResourceTypeVirtualNetwork:
return "Virtual Network"
case AzureResourceTypeContainerRegistry:
return "Container Registry"
case AzureResourceTypeManagedCluster:
return "AKS Managed Cluster"
case AzureResourceTypeAgentPool:
return "AKS Agent Pool"
}

return ""
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/pkg/project/framework_service_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DockerProjectOptions struct {
type dockerProject struct {
config *ServiceConfig
env *environment.Environment
docker *docker.Docker
docker docker.Docker
framework FrameworkService
}

Expand Down Expand Up @@ -66,7 +66,7 @@ func (p *dockerProject) Initialize(ctx context.Context) error {
func NewDockerProject(
config *ServiceConfig,
env *environment.Environment,
docker *docker.Docker,
docker docker.Docker,
framework FrameworkService,
) FrameworkService {
return &dockerProject{
Expand Down
19 changes: 18 additions & 1 deletion cli/azd/pkg/project/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/tools"
"github.com/azure/azure-dev/cli/azd/pkg/tools/azcli"
"github.com/azure/azure-dev/cli/azd/pkg/tools/docker"
"github.com/azure/azure-dev/cli/azd/pkg/tools/kubectl"
"github.com/azure/azure-dev/cli/azd/pkg/tools/swa"
)

Expand All @@ -39,6 +40,8 @@ type ServiceConfig struct {
Module string `yaml:"module"`
// The optional docker options
Docker DockerProjectOptions `yaml:"docker"`
// The optional K8S / AKS options
K8s AksOptions `yaml:"k8s"`
// The infrastructure provisioning configuration
Infra provisioning.Options `yaml:"infra"`
// Hook configuration for service
Expand Down Expand Up @@ -124,6 +127,20 @@ func (sc *ServiceConfig) GetServiceTarget(
target, err = NewFunctionAppTarget(sc, env, resource, azCli)
case string(StaticWebAppTarget):
target, err = NewStaticWebAppTarget(sc, env, resource, azCli, swa.NewSwaCli(commandRunner))
case string(AksTarget):
containerService, err := azCli.ContainerService(ctx, env.GetSubscriptionId())
if err != nil {
return nil, err
}
target = NewAksTarget(
sc,
env,
resource,
azCli,
containerService,
kubectl.NewKubectl(commandRunner),
docker.NewDocker(commandRunner),
)
default:
return nil, fmt.Errorf("unsupported host '%s' for service '%s'", sc.Host, sc.Name)
}
Expand Down Expand Up @@ -154,7 +171,7 @@ func (sc *ServiceConfig) GetFrameworkService(
}

// For containerized applications we use a nested framework service
if sc.Host == string(ContainerAppTarget) {
if sc.Host == string(ContainerAppTarget) || sc.Host == string(AksTarget) {
sourceFramework := frameworkService
frameworkService = NewDockerProject(sc, env, docker.NewDocker(commandRunner), sourceFramework)
}
Expand Down
8 changes: 2 additions & 6 deletions cli/azd/pkg/project/service_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
ContainerAppTarget ServiceTargetKind = "containerapp"
AzureFunctionTarget ServiceTargetKind = "function"
StaticWebAppTarget ServiceTargetKind = "staticwebapp"
AksTarget ServiceTargetKind = "aks"
)

type ServiceDeploymentResult struct {
Expand Down Expand Up @@ -89,10 +90,5 @@ func resourceTypeMismatchError(
// As an example, ContainerAppTarget is able to provision the container app as part of deployment,
// and thus returns true.
func (st ServiceTargetKind) SupportsDelayedProvisioning() bool {
return st == ContainerAppTarget
return st == ContainerAppTarget || st == AksTarget
}

var _ ServiceTarget = &appServiceTarget{}
var _ ServiceTarget = &containerAppTarget{}
var _ ServiceTarget = &functionAppTarget{}
var _ ServiceTarget = &staticWebAppTarget{}
Loading