Skip to content

Commit

Permalink
Merge pull request #261 from 3scale/2.7-stable-prod-backport-amprelea…
Browse files Browse the repository at this point in the history
…se-upgrade

[2.7-stable-prod] Upgrade System's AMP_RELEASE on operator upgrade
  • Loading branch information
miguelsorianod authored Oct 23, 2019
2 parents c649b51 + cfdcc3c commit b58d526
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pkg/controller/apimanager/upgrade_26_to_27.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"reflect"

"github.com/3scale/3scale-operator/pkg/3scale/amp/operator"
"github.com/3scale/3scale-operator/pkg/3scale/amp/product"
appsv1 "github.com/openshift/api/apps/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand All @@ -22,6 +24,11 @@ func (u *Upgrade26_to_27) Upgrade() (reconcile.Result, error) {
return res, err
}

res, err = u.upgradeSystemAMPReleaseInSystemEnvironmentConfigMap()
if res.Requeue || err != nil {
return res, err
}

res, err = u.upgradeAMPImageStreams()
if res.Requeue || err != nil {
return res, err
Expand Down Expand Up @@ -77,6 +84,45 @@ func (u *Upgrade26_to_27) upgradeSystemAppPreHookPodCommand() (reconcile.Result,
return reconcile.Result{}, nil
}

func (u *Upgrade26_to_27) upgradeSystemAMPReleaseInSystemEnvironmentConfigMap() (reconcile.Result, error) {
system, err := operator.System(u.cr, u.client)
if err != nil {
return reconcile.Result{}, err
}

desiredSystemEnvironmentConfigMap := system.EnvironmentConfigMap()
desiredAMPReleaseValue := product.ThreescaleRelease

existingSystemEnvironmentConfigMap := &v1.ConfigMap{}
err = u.client.Get(context.TODO(), types.NamespacedName{Name: desiredSystemEnvironmentConfigMap.Name, Namespace: u.cr.Namespace}, existingSystemEnvironmentConfigMap)
if err != nil {
return reconcile.Result{}, err
}

ampReleaseKey := "AMP_RELEASE"
var existingAMPReleaseValue string
var ok bool
if existingAMPReleaseValue, ok = existingSystemEnvironmentConfigMap.Data[ampReleaseKey]; !ok {
return reconcile.Result{}, fmt.Errorf("Key '%s' not found in ConfigMap '%s'", ampReleaseKey, existingSystemEnvironmentConfigMap.Name)
}

var changed bool
if existingAMPReleaseValue != desiredAMPReleaseValue {
existingSystemEnvironmentConfigMap.Data[ampReleaseKey] = desiredAMPReleaseValue
changed = true
}

if changed {
u.logger.Info(fmt.Sprintf("Update object %s", operator.ObjectInfo(existingSystemEnvironmentConfigMap)))
err = u.client.Update(context.TODO(), existingSystemEnvironmentConfigMap)
if err != nil {
return reconcile.Result{}, err
}
}

return reconcile.Result{}, nil
}

func (u *Upgrade26_to_27) upgradeAMPImageStreams() (reconcile.Result, error) {
// implement upgrade procedure by reconcile procedure
baseReconciler := operator.NewBaseReconciler(u.client, u.apiClientReader, u.scheme, u.logger)
Expand Down

0 comments on commit b58d526

Please sign in to comment.