Skip to content

Commit

Permalink
capabilitiesV2: promote proxy config to staging env
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Jun 19, 2020
1 parent 275516b commit c5b3550
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
11 changes: 5 additions & 6 deletions pkg/controller/product/3scale_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ func (t *ThreescaleReconciler) Reconcile() (*helper.ProductEntity, error) {
taskRunner.AddTask("SyncMetrics", t.syncMetrics)
taskRunner.AddTask("SyncMappingRules", t.syncMappingRules)
taskRunner.AddTask("SyncApplicationPlans", t.syncApplicationPlans)
// TODO Implement policies reconciliation
// taskRunner.AddTask("SyncPolicies", t.syncPolicies)
// This should be the last step
taskRunner.AddTask("BumbProxyVersion", t.bumpProxyVersion)
taskRunner.AddTask("PromoteProxyToStaging", t.promoteProxyToStaging)

err = taskRunner.Run()
if err != nil {
Expand All @@ -62,9 +60,10 @@ func (t *ThreescaleReconciler) Reconcile() (*helper.ProductEntity, error) {
return t.productEntity, nil
}

func (t *ThreescaleReconciler) bumpProxyVersion(_ interface{}) error {
// POST /admin/api/services/{service_id}/proxy/deploy.json ????
return nil
func (t *ThreescaleReconciler) promoteProxyToStaging(_ interface{}) error {
// 3scale API does not expose a way to check if promotion is necessary
// PromoteProxyToStaging operation is idempotent and not expensive, though.
return t.productEntity.PromoteProxyToStaging()
}

func (t *ThreescaleReconciler) reconcile3scaleProduct() (*helper.ProductEntity, error) {
Expand Down
20 changes: 14 additions & 6 deletions pkg/helper/product_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,12 @@ func (b *ProductEntity) Proxy() (*threescaleapi.ProxyJSON, error) {

func (b *ProductEntity) UpdateProxy(params threescaleapi.Params) error {
b.logger.V(1).Info("UpdateProxy", "params", params)
_, err := b.client.UpdateProductProxy(b.productObj.Element.ID, params)
updated, err := b.client.UpdateProductProxy(b.productObj.Element.ID, params)
if err != nil {
return fmt.Errorf("product [%s] update proxy: %w", b.productObj.Element.SystemName, err)
}
b.resetProxy()

b.proxy = updated
return nil
}

Expand Down Expand Up @@ -335,15 +336,22 @@ func (b *ProductEntity) CreateApplicationPlan(params threescaleapi.Params) (*thr
return obj, nil
}

func (b *ProductEntity) PromoteProxyToStaging() error {
b.logger.V(1).Info("PromoteProxyToStaging")
proxyObj, err := b.client.DeployProductProxy(b.productObj.Element.ID)
if err != nil {
return fmt.Errorf("product [%s] promote proxy to staging: %w", b.productObj.Element.SystemName, err)
}

b.proxy = proxyObj
return nil
}

//
// PRIVATE
//
//

func (b *ProductEntity) resetProxy() {
b.proxy = nil
}

func (b *ProductEntity) resetBackendUsages() {
b.backendUsages = nil
}
Expand Down

0 comments on commit c5b3550

Please sign in to comment.