Skip to content

Commit

Permalink
Merge branch 'master' into cosmosdb-secret-connstr
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Pflueger authored May 19, 2020
2 parents 471f257 + 28c4358 commit 357577c
Show file tree
Hide file tree
Showing 27 changed files with 377 additions and 191 deletions.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,69 @@ For more details on the control flow of the Azure Service operator, refer to the
- [Virtual Machine](/docs/services/virtualmachine/virtualmachine.md)
- [Virtual Machine Scale Set](/docs/services/vmscaleset/vmscaleset.md)

## Quick start

![Deploying ASO](/docs/images/asodeploy.gif)

Do you want to quickly deploy the latest version of Azure Service Operator on your Kubernetes cluster and get exploring? Follow these steps.

1. Make sure `kubectl` is configured to connect to the Kubernetes cluster you want to deploy Azure Service Operators to.
For an AKS cluster, you can use the below command:

```
az aks get-credentials -g <AKSClusterResourceGroup> -n <AKSClusterName>
```

2. Install cert-manager on the cluster using the following commands.

```
kubectl create namespace cert-manager
kubectl label namespace cert-manager cert-manager.io/disable-validation=true
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.12.0/cert-manager.yaml
```

Wait for the cert-manager deployment to be complete. Use the below command to check for this.

```
kubectl rollout status -n cert-manager deploy/cert-manager-webhook
```

3. Download the latest Helm chart for Azure Service Operators locally to your machine. Run the following commands.

```
mkdir install-aso
cd install-aso
export HELM_EXPERIMENTAL_OCI=1
```

Pull and export the helm chart.

```
helm chart pull mcr.microsoft.com/k8s/asohelmchart:latest
```

```
helm chart export mcr.microsoft.com/k8s/asohelmchart:latest --destination .
```

4. Install the Azure Service Operator on your cluster using the following helm install command.

The ServicePrincipal you pass to the command below should have access to create resources in your subscription.

```
helm install aso ./azure-service-operator \
--set azureSubscriptionID=<AzureSubscriptionID> \
--set azureTenantID=<AzureTenantID> \
--set azureClientID=<ServicePrincipalClientId> \
--set azureClientSecret=<ServicePrincipalClientSecret> \
--set createNamespace=true \
--set image.repository="mcr.microsoft.com/k8s/azure-service-operator:latest"
```

Now you can see the Azure service operator pods running in your cluster.

`kubectl get pods -n azureoperator-system`

## Getting started

This project maintains [releases of the Azure Service Operator](https://github.com/Azure/azure-service-operator/releases) that you can deploy via a [configurable Helm chart](/charts/azure-service-operator).
Expand Down
Binary file added docs/images/asodeploy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 0 additions & 35 deletions pkg/errhelp/errhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,6 @@ import (
"strings"
)

// IsParentNotFound checks if the error is about a parent resrouce not existing
func IsParentNotFound(err error) bool {
return strings.Contains(err.Error(), "ParentResourceNotFound")
}

// IsGroupNotFound checks if error is about resource group not existing
func IsGroupNotFound(err error) bool {
return strings.Contains(err.Error(), "ResourceGroupNotFound")
}

// IsNotActive checks if error is mentioning a non active resource
func IsNotActive(err error) bool {
return strings.Contains(err.Error(), "not active")
}

// IsAsynchronousOperationNotComplete checks if error reports an asynchronous operation not completed
func IsAsynchronousOperationNotComplete(err error) bool {
return strings.Contains(err.Error(), "asynchronous operation has not completed")
}

// IsStatusCode204 checks if the error reports a status code 204 failure to respond to request
func IsStatusCode204(err error) bool {
return strings.Contains(err.Error(), "StatusCode=204")
}

// IsStatusCode404 checks if the error reports a status code 404 resource not found
func IsStatusCode404(err error) bool {
return strings.Contains(err.Error(), "StatusCode=404")
}

// IsResourceNotFound checks if error reports that a referenced resource is not found
func IsResourceNotFound(err error) bool {
return strings.Contains(err.Error(), "ResourceNotFound")
}

// StripErrorIDs takes an error and returns its string representation after filtering some common ID patterns
func StripErrorIDs(err error) string {
patterns := []string{
Expand Down
13 changes: 11 additions & 2 deletions pkg/resourcemanager/apim/apimgmt/apimgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2019-01-01/apimanagement"
"github.com/Azure/azure-service-operator/api/v1alpha1"
"github.com/Azure/azure-service-operator/pkg/errhelp"
"github.com/Azure/azure-service-operator/pkg/helpers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -69,7 +70,11 @@ var _ = Describe("API Management", func() {
APIETag)
if err != nil {
fmt.Println(err.Error())
if !errhelp.IsAsynchronousOperationNotComplete(err) {
ignore := []string{
errhelp.AsyncOpIncompleteError,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(ignore, azerr.Type) {
fmt.Println("error occured")
return false
}
Expand All @@ -90,7 +95,11 @@ var _ = Describe("API Management", func() {
_, err = APIManager.DeleteAPI(ctx, tc.ResourceGroupName, APIServiceName, *contract.ID, *contract.APIRevision, true)
if err != nil {
fmt.Println(err.Error())
if !errhelp.IsAsynchronousOperationNotComplete(err) {
ignore := []string{
errhelp.AsyncOpIncompleteError,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(ignore, azerr.Type) {
fmt.Println("error occured")
return false
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/resourcemanager/appinsights/appinsights.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,22 @@ func (m *Manager) Delete(ctx context.Context, obj runtime.Object, opts ...resour

response, err := m.DeleteAppInsights(ctx, i.Spec.ResourceGroup, i.Name)
if err != nil {
if !errhelp.IsAsynchronousOperationNotComplete(err) {
return true, err
catch := []string{
errhelp.AsyncOpIncompleteError,
}
gone := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.ParentNotFoundErrorCode,
errhelp.NotFoundErrorCode,
errhelp.ResourceNotFound,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
return true, nil
} else if helpers.ContainsString(gone, azerr.Type) {
return false, nil
}
return true, err
}
i.Status.State = response.Status

Expand Down
12 changes: 10 additions & 2 deletions pkg/resourcemanager/appinsights/appinsights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ var _ = Describe("App Insights", func() {
_, err = AppInsightsManager.CreateAppInsights(ctx, rgName, "web", "other", location, appinsightsInstance)
if err != nil {
fmt.Println(err.Error())
if !errhelp.IsAsynchronousOperationNotComplete(err) {
ignore := []string{
errhelp.AsyncOpIncompleteError,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(ignore, azerr.Type) {
fmt.Println("error occured")
return false
}
Expand All @@ -64,7 +68,11 @@ var _ = Describe("App Insights", func() {
_, err = AppInsightsManager.DeleteAppInsights(ctx, psqlServer, appinsightsInstance)
if err != nil {
fmt.Println(err.Error())
if !errhelp.IsAsynchronousOperationNotComplete(err) {
ignore := []string{
errhelp.AsyncOpIncompleteError,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(ignore, azerr.Type) {
fmt.Println("error occured")
return false
}
Expand Down
16 changes: 12 additions & 4 deletions pkg/resourcemanager/appinsights/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ var _ = BeforeSuite(func() {
var _ = AfterSuite(func() {
By("tearing down the test environment")
_, err := tc.ResourceGroupManager.DeleteGroup(ctx, tc.ResourceGroupName)
if !errhelp.IsAsynchronousOperationNotComplete(err) {
ignore := []string{
errhelp.AsyncOpIncompleteError,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(ignore, azerr.Type) {
log.Println("Delete RG failed")
return
}
Expand All @@ -88,9 +92,13 @@ var _ = AfterSuite(func() {
if err == nil {
log.Println("waiting for resource group to be deleted")
} else {
if errhelp.IsGroupNotFound(err) {
log.Println("resource group deleted")
break
catch := []string{
errhelp.ResourceGroupNotFoundErrorCode,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
log.Println("Delete RG failed")
return
} else {
log.Println(fmt.Sprintf("cannot delete resource group: %v", err))
return
Expand Down
16 changes: 13 additions & 3 deletions pkg/resourcemanager/azuresql/azuresqldb/azuresqldb_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,21 @@ func (db *AzureSqlDbManager) Delete(ctx context.Context, obj runtime.Object, opt

_, err = db.DeleteDB(ctx, groupName, server, dbName)
if err != nil {
if errhelp.IsStatusCode204(err) {
// Database does not exist
catch := []string{
errhelp.AsyncOpIncompleteError,
}
gone := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.ParentNotFoundErrorCode,
errhelp.NotFoundErrorCode,
errhelp.ResourceNotFound,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
return true, nil
} else if helpers.ContainsString(gone, azerr.Type) {
return false, nil
}

return true, fmt.Errorf("AzureSqlDb delete error %v", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,23 @@ func (fw *AzureSqlFirewallRuleManager) Delete(ctx context.Context, obj runtime.O

err = fw.DeleteSQLFirewallRule(ctx, groupName, server, ruleName)
if err != nil {
if errhelp.IsStatusCode204(err) {
// firewall does not exist
return true, nil
catch := []string{
errhelp.AsyncOpIncompleteError,
}
if errhelp.IsStatusCode404(err) {
gone := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.ParentNotFoundErrorCode,
errhelp.NotFoundErrorCode,
errhelp.ResourceNotFound,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
return true, nil
} else if helpers.ContainsString(gone, azerr.Type) {
return false, nil
}
instance.Status.Message = fmt.Sprintf("AzureSqlFirewallRule Delete failed with %s", err.Error())
return false, err
return true, err
}
instance.Status.Message = fmt.Sprintf("Delete AzureSqlFirewallRule succeeded")
return false, nil
Expand Down
17 changes: 15 additions & 2 deletions pkg/resourcemanager/keyvaults/keyvault.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,22 @@ func (k *azureKeyVaultManager) Delete(ctx context.Context, obj runtime.Object, o
if err == nil {
_, err := k.DeleteVault(ctx, instance.Spec.ResourceGroup, instance.Name)
if err != nil {
if !errhelp.IsAsynchronousOperationNotComplete(err) {
return true, err
catch := []string{
errhelp.AsyncOpIncompleteError,
}
gone := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.ParentNotFoundErrorCode,
errhelp.NotFoundErrorCode,
errhelp.ResourceNotFound,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
return true, nil
} else if helpers.ContainsString(gone, azerr.Type) {
return false, nil
}
return true, err
}
return true, nil
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/resourcemanager/keyvaults/keyvault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ var _ = Describe("KeyVault Resource Manager test", func() {
)
if err != nil {
fmt.Println(err.Error())
if !errhelp.IsAsynchronousOperationNotComplete(err) {
ignore := []string{
errhelp.AsyncOpIncompleteError,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(ignore, azerr.Type) {
fmt.Println("error occured")
return false
}
Expand All @@ -97,7 +101,11 @@ var _ = Describe("KeyVault Resource Manager test", func() {
_, err := keyVaultManager.DeleteVault(ctx, rgName, keyvaultName)
if err != nil {
fmt.Println(err.Error())
if !errhelp.IsAsynchronousOperationNotComplete(err) {
ignore := []string{
errhelp.AsyncOpIncompleteError,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(ignore, azerr.Type) {
fmt.Println("error occured")
return false
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/resourcemanager/keyvaults/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ var _ = AfterSuite(func() {
By("tearing down the test environment")
// delete the resource group and contained resources
_, err := tc.ResourceGroupManager.DeleteGroup(ctx, tc.ResourceGroupName)
if !errhelp.IsAsynchronousOperationNotComplete(err) {
ignore := []string{
errhelp.AsyncOpIncompleteError,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(ignore, azerr.Type) {
log.Println("Delete RG failed")
return
}

polling := time.Second * 10
Eventually(func() bool {
_, err := resourcegroupsresourcemanager.GetGroup(ctx, tc.ResourceGroupName)
Expand All @@ -93,7 +98,11 @@ var _ = AfterSuite(func() {
return false
}

if errhelp.IsGroupNotFound(err) {
catch := []string{
errhelp.ResourceGroupNotFoundErrorCode,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
log.Println("resource group deleted")
return true
} else {
Expand Down
17 changes: 15 additions & 2 deletions pkg/resourcemanager/loadbalancer/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,22 @@ func (g *AzureLoadBalancerClient) Delete(ctx context.Context, obj runtime.Object
resourceGroup,
)
if err != nil {
if !errhelp.IsAsynchronousOperationNotComplete(err) {
return true, err
catch := []string{
errhelp.AsyncOpIncompleteError,
}
gone := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.ParentNotFoundErrorCode,
errhelp.NotFoundErrorCode,
errhelp.ResourceNotFound,
}
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
return true, nil
} else if helpers.ContainsString(gone, azerr.Type) {
return false, nil
}
return true, err
}

if err == nil {
Expand Down
Loading

0 comments on commit 357577c

Please sign in to comment.