Skip to content

Commit

Permalink
first (#930)
Browse files Browse the repository at this point in the history
Co-authored-by: William Mortl <wmortl@Williams-MacBook-Pro.local>
  • Loading branch information
WilliamMortlMicrosoft and William Mortl authored Apr 13, 2020
1 parent 3bc5e7a commit 8ce7e09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
5 changes: 5 additions & 0 deletions pkg/resourcemanager/apim/apimgmt/apimgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (m *Manager) Ensure(ctx context.Context, obj runtime.Object, opts ...resour
if err != nil {
instance.Status.Message = err.Error()
// If there is no parent APIM service, we cannot proceed
instance.Status.Provisioning = false
return false, nil
}

Expand Down Expand Up @@ -160,10 +161,14 @@ func (m *Manager) Ensure(ctx context.Context, obj runtime.Object, opts ...resour
}

if contract.StatusCode == 200 {
instance.Status.Provisioning = false
instance.Status.Provisioned = true
instance.Status.FailedProvisioning = false
instance.Status.Message = resourcemanager.SuccessMsg
} else {
instance.Status.Provisioning = false
instance.Status.Provisioned = false
instance.Status.FailedProvisioning = true
}

return true, nil
Expand Down
32 changes: 11 additions & 21 deletions pkg/resourcemanager/apim/apimservice/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func (g *AzureAPIMgmtServiceManager) Ensure(ctx context.Context, obj runtime.Obj
errhelp.InvalidParameters,
}

instance.Status.Provisioned = false
instance.Status.Provisioning = true

// STEP 1:
// does it already exist? if not, then provision
exists, activated, resourceID, _ := g.APIMgmtSvcStatus(ctx, resourceGroupName, resourceName)
Expand All @@ -70,17 +73,14 @@ func (g *AzureAPIMgmtServiceManager) Ensure(ctx context.Context, obj runtime.Obj

// if available, create the service
if available {
g.Telemetry.LogTrace("APIM reconcile", "Step 1: creating APIM service")
location := instance.Spec.Location
publisherName := instance.Spec.PublisherName
publisherEmail := instance.Spec.PublisherEmail
_, err := g.CreateAPIMgmtSvc(ctx, tier, location, resourceGroupName, resourceName, publisherName, publisherEmail)
instance.Status.Provisioned = false
instance.Status.Provisioning = true
if err != nil {
instance.Status.Provisioning = false
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
g.Telemetry.LogError("API Mgmt Svc creation error, requeueing", err)
instance.Status.Message = "API Mgmt Svc encountered a caught error, requeueing..."
return false, nil
}
Expand All @@ -92,20 +92,17 @@ func (g *AzureAPIMgmtServiceManager) Ensure(ctx context.Context, obj runtime.Obj
}

// name wasnt available, log error and stop reconciling
g.Telemetry.LogError("could not create API Mgmt Service due to bad resource name", fmt.Errorf("bad API Mgmt Service name"))
instance.Status.Message = "API Mgmt Svc is ending reconciliation due to bad name"
instance.Status.Provisioned = false
instance.Status.Provisioning = false
instance.Status.FailedProvisioning = true
return true, nil
}

// STEP 2:
// still in the proccess of provisioning
if !activated {
g.Telemetry.LogTrace("APIM reconcile", "Step 2: waiting on activation of APIM service")
instance.Status.Message = "API Mgmt Svc is waiting for activation / updating to complete, requeueing..."
instance.Status.Provisioned = false
instance.Status.Provisioning = true
return false, nil
}

Expand All @@ -114,27 +111,23 @@ func (g *AzureAPIMgmtServiceManager) Ensure(ctx context.Context, obj runtime.Obj
appInsightsResourceGroup := instance.Spec.AppInsightsResourceGroup
appInsightsName := instance.Spec.AppInsightsName
if appInsightsResourceGroup != "" && appInsightsName != "" {
g.Telemetry.LogTrace("APIM reconcile", "Step 3: assigning App Insights for APIM service")
err = g.SetAppInsightsForAPIMgmtSvc(
ctx,
resourceGroupName,
resourceName,
appInsightsResourceGroup,
appInsightsName,
)
instance.Status.Provisioned = false
instance.Status.Provisioning = true
if err != nil {
azerr := errhelp.NewAzureErrorAzureError(err)
if helpers.ContainsString(catch, azerr.Type) {
g.Telemetry.LogError("App Insights error, requeueing", err)
instance.Status.Message = "API Mgmt Svc encountered a caught error, requeueing..."
return false, nil
} else if helpers.ContainsString(fatalErr, azerr.Type) {
g.Telemetry.LogError("Fatal error assigning App Insights", err)
instance.Status.Message = "API Mgmt Svc encountered a trapped error, ending reconciliation"
instance.Status.Message = fmt.Sprintf("API Mgmt Svc encountered a trapped error, ending reconciliation: %s", err.Error())
instance.Status.Provisioned = false
instance.Status.Provisioning = false
instance.Status.FailedProvisioning = true
return true, nil
}
instance.Status.Message = "API Mgmt Svc encountered an unknown error, requeueing..."
Expand All @@ -145,7 +138,6 @@ func (g *AzureAPIMgmtServiceManager) Ensure(ctx context.Context, obj runtime.Obj
// STEP 4:
// need to update with a vnet?
if vnetType != "" && !strings.EqualFold(vnetType, "none") {
g.Telemetry.LogTrace("APIM reconcile", "Step 4: assignning VNet for APIM service")
vnetResourceGroup := instance.Spec.VnetResourceGroup
vnetName := instance.Spec.VnetName
subnetName := instance.Spec.VnetSubnetName
Expand All @@ -158,19 +150,16 @@ func (g *AzureAPIMgmtServiceManager) Ensure(ctx context.Context, obj runtime.Obj
vnetName,
subnetName,
)
instance.Status.Provisioned = false
instance.Status.Provisioning = true
if err != nil {
azerr := errhelp.NewAzureErrorAzureError(err)
if !helpers.ContainsString(catch, azerr.Type) {
g.Telemetry.LogError("VNet update error, requeueing", err)
instance.Status.Message = "API Mgmt Svc encountered a caught error, requeueing..."
return false, nil
} else if helpers.ContainsString(fatalErr, azerr.Type) {
g.Telemetry.LogError("Fatal error occured with assigning a VNet", err)
instance.Status.Message = "API Mgmt Svc encountered a trapped error, ending reconciliation"
instance.Status.Message = fmt.Sprintf("API Mgmt Svc encountered a trapped error, ending reconciliation: %s", err.Error())
instance.Status.Provisioned = false
instance.Status.Provisioning = false
instance.Status.FailedProvisioning = true
return true, nil
}
instance.Status.Message = "API Mgmt Svc encountered an unknown error, requeueing..."
Expand All @@ -184,10 +173,10 @@ func (g *AzureAPIMgmtServiceManager) Ensure(ctx context.Context, obj runtime.Obj

// STEP 5:
// everything is now completed!
g.Telemetry.LogTrace("APIM reconcile", "Step 5: completed reconcilliation successfully")
instance.Status.Message = resourcemanager.SuccessMsg
instance.Status.Provisioned = true
instance.Status.Provisioning = false
instance.Status.FailedProvisioning = false
instance.Status.ResourceId = *resourceID
return true, nil
}
Expand Down Expand Up @@ -253,6 +242,7 @@ func (g *AzureAPIMgmtServiceManager) convert(obj runtime.Object) (*azurev1alpha1
return local, nil
}

// GetStatus retrieves the status object
func (g *AzureAPIMgmtServiceManager) GetStatus(obj runtime.Object) (*v1alpha1.ASOStatus, error) {
instance, err := g.convert(obj)
if err != nil {
Expand Down

0 comments on commit 8ce7e09

Please sign in to comment.