Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
v1 "github.com/openshift/api/config/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand Down Expand Up @@ -217,7 +218,7 @@ func getApplicationProductCR() (CR *capabilitiesv1beta1.Product) {
},
},
Status: capabilitiesv1beta1.ProductStatus{
ID: create(3),
ID: ptr.To(int64(3)),
ProviderAccountHost: "some string",
ObservedGeneration: 1,
Conditions: common.Conditions{common.Condition{
Expand Down Expand Up @@ -265,7 +266,7 @@ func getApplicationProductList() (productList *capabilitiesv1beta1.ProductList)
},
},
Status: capabilitiesv1beta1.ProductStatus{
ID: create(3),
ID: ptr.To(int64(3)),
ProviderAccountHost: "some string",
ObservedGeneration: 1,
Conditions: nil,
Expand Down Expand Up @@ -310,7 +311,7 @@ func getApplicationDeveloperAccount() (CR *capabilitiesv1beta1.DeveloperAccount)
},
},
Status: capabilitiesv1beta1.DeveloperAccountStatus{
ID: create(3),
ID: ptr.To(int64(3)),
ProviderAccountHost: "some string",
Conditions: common.Conditions{
common.Condition{
Expand Down
82 changes: 41 additions & 41 deletions controllers/capabilities/backend_threescale_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,6 @@ func (t *BackendThreescaleReconciler) syncMethods(_ interface{}) error {
existingMap[systemName] = existing.Element
}

//
// Deleted existing and not desired
//
notDesiredExistingKeys := helper.ArrayStringDifference(existingKeys, desiredKeys)
notDesiredMap := map[string]threescaleapi.MethodItem{}
for _, systemName := range notDesiredExistingKeys {
// key is expected to exist
// notDesiredExistingKeys is a subset of the existingMap key set
notDesiredMap[systemName] = existingMap[systemName]
}
err = t.deleteNotDesiredMethodsFrom3scale(notDesiredMap)
if err != nil {
return fmt.Errorf("error sync backend methods [%s]: %w", t.backendResource.Spec.SystemName, err)
}

err = t.deleteExternalMetricReferences(notDesiredExistingKeys)
if err != nil {
return fmt.Errorf("error sync backend methods [%s]: %w", t.backendResource.Spec.SystemName, err)
}

//
// Reconcile existing and changed
//
Expand Down Expand Up @@ -189,6 +169,26 @@ func (t *BackendThreescaleReconciler) syncMethods(_ interface{}) error {
return fmt.Errorf("error sync backend methods [%s]: %w", t.backendResource.Spec.SystemName, err)
}

//
// Deleted existing and not desired
//
notDesiredExistingKeys := helper.ArrayStringDifference(existingKeys, desiredKeys)
notDesiredMap := map[string]threescaleapi.MethodItem{}
for _, systemName := range notDesiredExistingKeys {
// key is expected to exist
// notDesiredExistingKeys is a subset of the existingMap key set
notDesiredMap[systemName] = existingMap[systemName]
}
err = t.deleteNotDesiredMethodsFrom3scale(notDesiredMap)
if err != nil {
return fmt.Errorf("error sync backend methods [%s]: %w", t.backendResource.Spec.SystemName, err)
}

err = t.deleteExternalMetricReferences(notDesiredExistingKeys)
if err != nil {
return fmt.Errorf("error sync backend methods [%s]: %w", t.backendResource.Spec.SystemName, err)
}

return nil
}

Expand Down Expand Up @@ -344,27 +344,6 @@ func (t *BackendThreescaleReconciler) syncMetrics(_ interface{}) error {
existingMap[systemName] = existing.Element
}

//
// Deleted existing and not desired metrics
//

notDesiredExistingKeys := helper.ArrayStringDifference(existingKeys, desiredKeys)
notDesiredMap := map[string]threescaleapi.MetricItem{}
for _, systemName := range notDesiredExistingKeys {
// key is expected to exist
// notDesiredExistingKeys is a subset of the existingMap key set
notDesiredMap[systemName] = existingMap[systemName]
}
err = t.deleteNotDesiredMetricsFrom3scale(notDesiredMap)
if err != nil {
return fmt.Errorf("error sync backend metrics [%s]: %w", t.backendResource.Spec.SystemName, err)
}

err = t.deleteExternalMetricReferences(notDesiredExistingKeys)
if err != nil {
return fmt.Errorf("error sync backend metrics [%s]: %w", t.backendResource.Spec.SystemName, err)
}

//
// Reconcile existing and changed metrics
//
Expand Down Expand Up @@ -399,6 +378,27 @@ func (t *BackendThreescaleReconciler) syncMetrics(_ interface{}) error {
return fmt.Errorf("error sync backend metrics [%s]: %w", t.backendResource.Spec.SystemName, err)
}

//
// Deleted existing and not desired metrics
//

notDesiredExistingKeys := helper.ArrayStringDifference(existingKeys, desiredKeys)
notDesiredMap := map[string]threescaleapi.MetricItem{}
for _, systemName := range notDesiredExistingKeys {
// key is expected to exist
// notDesiredExistingKeys is a subset of the existingMap key set
notDesiredMap[systemName] = existingMap[systemName]
}
err = t.deleteNotDesiredMetricsFrom3scale(notDesiredMap)
if err != nil {
return fmt.Errorf("error sync backend metrics [%s]: %w", t.backendResource.Spec.SystemName, err)
}

err = t.deleteExternalMetricReferences(notDesiredExistingKeys)
if err != nil {
return fmt.Errorf("error sync backend metrics [%s]: %w", t.backendResource.Spec.SystemName, err)
}

return nil
}

Expand Down
32 changes: 16 additions & 16 deletions controllers/capabilities/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ func (t *ProductThreescaleReconciler) syncMethods(_ interface{}) error {
existingMap[systemName] = existing.Element
}

//
// Deleted existing and not desired
//
notDesiredExistingKeys := helper.ArrayStringDifference(existingKeys, desiredKeys)
t.logger.V(1).Info("syncMethods", "notDesiredExistingKeys", notDesiredExistingKeys)
notDesiredMap := map[string]threescaleapi.MethodItem{}
for _, systemName := range notDesiredExistingKeys {
// key is expected to exist
// notDesiredExistingKeys is a subset of the existingMap key set
notDesiredMap[systemName] = existingMap[systemName]
}
err = t.processNotDesiredMethods(notDesiredMap)
if err != nil {
return fmt.Errorf("error sync product methods [%s]: %w", t.resource.Spec.SystemName, err)
}

//
// Reconcile existing and changed
//
Expand Down Expand Up @@ -83,6 +67,22 @@ func (t *ProductThreescaleReconciler) syncMethods(_ interface{}) error {
return fmt.Errorf("error sync product methods [%s]: %w", t.resource.Spec.SystemName, err)
}

//
// Deleted existing and not desired
//
notDesiredExistingKeys := helper.ArrayStringDifference(existingKeys, desiredKeys)
t.logger.V(1).Info("syncMethods", "notDesiredExistingKeys", notDesiredExistingKeys)
notDesiredMap := map[string]threescaleapi.MethodItem{}
for _, systemName := range notDesiredExistingKeys {
// key is expected to exist
// notDesiredExistingKeys is a subset of the existingMap key set
notDesiredMap[systemName] = existingMap[systemName]
}
err = t.processNotDesiredMethods(notDesiredMap)
if err != nil {
return fmt.Errorf("error sync product methods [%s]: %w", t.resource.Spec.SystemName, err)
}

return nil
}

Expand Down
34 changes: 17 additions & 17 deletions controllers/capabilities/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ func (t *ProductThreescaleReconciler) syncMetrics(_ interface{}) error {
existingMap[systemName] = existing.Element
}

//
// Deleted existing and not desired metrics
//

notDesiredExistingKeys := helper.ArrayStringDifference(existingKeys, desiredKeys)
t.logger.V(1).Info("syncMetrics", "notDesiredExistingKeys", notDesiredExistingKeys)
notDesiredMap := map[string]threescaleapi.MetricItem{}
for _, systemName := range notDesiredExistingKeys {
// key is expected to exist
// notDesiredExistingKeys is a subset of the existingMap key set
notDesiredMap[systemName] = existingMap[systemName]
}
err = t.processNotDesiredMetrics(notDesiredMap)
if err != nil {
return fmt.Errorf("error sync product metrics [%s]: %w", t.resource.Spec.SystemName, err)
}

//
// Reconcile existing and changed metrics
//
Expand Down Expand Up @@ -86,6 +69,23 @@ func (t *ProductThreescaleReconciler) syncMetrics(_ interface{}) error {
return fmt.Errorf("error sync product metrics [%s]: %w", t.resource.Spec.SystemName, err)
}

//
// Deleted existing and not desired metrics
//

notDesiredExistingKeys := helper.ArrayStringDifference(existingKeys, desiredKeys)
t.logger.V(1).Info("syncMetrics", "notDesiredExistingKeys", notDesiredExistingKeys)
notDesiredMap := map[string]threescaleapi.MetricItem{}
for _, systemName := range notDesiredExistingKeys {
// key is expected to exist
// notDesiredExistingKeys is a subset of the existingMap key set
notDesiredMap[systemName] = existingMap[systemName]
}
err = t.processNotDesiredMetrics(notDesiredMap)
if err != nil {
return fmt.Errorf("error sync product metrics [%s]: %w", t.resource.Spec.SystemName, err)
}

return nil
}

Expand Down
5 changes: 4 additions & 1 deletion controllers/capabilities/proxyconfigpromote_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ func (r *ProxyConfigPromoteReconciler) proxyConfigPromoteReconciler(proxyConfigP
var currentStagingVersion int

// Only proceed with proxyConfigPromote if status of the product is marked as "Completed"
if product.Status.Conditions.IsTrueFor(capabilitiesv1beta1.ProductSyncedConditionType) {
// OR the status is marked with ErrReferencedMethodIsBeingDeleted
failedCond := product.Status.Conditions.GetCondition(capabilitiesv1beta1.ProductFailedConditionType)
if product.Status.Conditions.IsTrueFor(capabilitiesv1beta1.ProductSyncedConditionType) ||
(failedCond != nil && failedCond.IsTrue() && failedCond.Message == helper.ErrReferencedMethodIsBeingDeleted.Error()) {
productID := product.Status.ID
productIDInt64 := *productID
productIDStr := strconv.Itoa(int(productIDInt64))
Expand Down
Loading