Skip to content
Permalink
Browse files

installation controller: remove migration scaffolding

In #183, we made changes to the InstallationTarget CRD that required a
small data migration. As promised, now that v0.6.0 is out, we can
clean that up as it's no longer needed. We also dutifully notify our
users that they should upgrade to v0.6.0 first in our changelog.
  • Loading branch information...
juliogreff authored and parhamdoustdar committed Sep 23, 2019
1 parent 7a4927b commit 9967c55ca22bf013dfe9de25846a297ecd3ad7fe
@@ -0,0 +1,11 @@
## Changelog since v0.6.0

### Breaking Changes

* Due to changes in the InstallationTarget CRD
([#183](https://github.com/bookingcom/shipper/pull/183)), Shipper v0.6.0 had
a small piece of code that would perform a data migration automatically the
first time it ran. In Shipper v0.7.0, that code has been removed, so the
migration will no longer happen. If you're upgrading Shipper from an earlier
version, we recommend that you first upgrade to v0.6.0, so your
InstallationTargets can be migrated properly.
@@ -216,54 +216,6 @@ func (c *Controller) enqueueInstallationTarget(obj interface{}) {
// processInstallation attempts to install the related InstallationTarget on
// all target clusters.
func (c *Controller) processInstallation(it *shipper.InstallationTarget) error {
// If an InstallationTarget was created before we introduced
// self-contained InstallationTargets, it will not contain a chart,
// values, nor a reliable CanOverride, so it will need to be migrated.
// We do so by looking at the associated release, and the current
// contender.
// Note that this is temporary. After this code gets released, it can
// safely be dropped in the next version.
if it.Spec.Chart == nil {
relNamespaceLister := c.releaseLister.Releases(it.Namespace)

release, err := relNamespaceLister.ReleaseForInstallationTarget(it)
if err != nil {
return shippererrors.NewUnrecoverableError(fmt.Errorf(
"InstallationTarget %q is missing Chart, and the owning release cannot be found: %s", shippercontroller.MetaKey(it), err))
}

appName, ok := release.GetLabels()[shipper.AppLabel]
if !ok {
return shippererrors.NewUnrecoverableError(fmt.Errorf(
"Release for InstallationTarget %q is missing label %q", shippercontroller.MetaKey(it), shipper.AppLabel))
}

contenderRel, err := relNamespaceLister.ContenderForApplication(appName)
if err != nil {
return err
}

if contenderRel.Name == release.Name {
it.Spec.CanOverride = true
}

it.Spec.Chart = release.Spec.Environment.Chart.DeepCopy()

if release.Spec.Environment.Values != nil {
values := release.Spec.Environment.Values.DeepCopy()
it.Spec.Values = &values
}

_, err = c.shipperclientset.ShipperV1alpha1().InstallationTargets(it.Namespace).Update(it)
if err != nil {
return shippererrors.NewKubeclientUpdateError(it, err).
WithShipperKind("InstallationTarget")
}

return nil

}

if !it.Spec.CanOverride {
klog.V(3).Infof("InstallationTarget %q is not allowed to override, skipping", shippercontroller.MetaKey(it))
return nil
@@ -4,7 +4,6 @@ import (
"testing"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -498,70 +497,3 @@ func TestInstallNoOverride(t *testing.T) {
shippertesting.ShallowCheckActions(expectedActions, clusterPair.fakeDynamicClient.Actions(), t)
shippertesting.ShallowCheckActions(expectedActions, clusterPair.fakeClient.Actions(), t)
}

func TestInstallWithoutChart(t *testing.T) {
cluster := buildCluster("minikube-a")
appName := "reviews-api"
testNs := "test-namespace"
chart := buildChart(appName, "0.0.1", repoUrl)

rel := buildRelease(testNs, appName, chart)
app := &shipper.Application{
ObjectMeta: v1.ObjectMeta{
Name: appName,
Namespace: testNs,
},
Status: shipper.ApplicationStatus{
History: []string{rel.Name},
},
}

it := buildInstallationTarget(testNs, appName, []string{cluster.Name}, nil)
it.ObjectMeta.OwnerReferences = []metav1.OwnerReference{
{
APIVersion: shipper.SchemeGroupVersion.String(),
Kind: "Release",
Name: rel.GetName(),
UID: rel.GetUID(),
},
}

shipperObjects := []runtime.Object{cluster, app, rel, it}
clientsPerCluster, shipperclientset, fakeDynamicClientBuilder, shipperInformerFactory :=
initializeClients(apiResourceList, shipperObjects,
objectsPerClusterMap{cluster.Name: []runtime.Object{}})

fakeClientProvider := &FakeClientProvider{
clientsPerCluster: clientsPerCluster,
restConfig: &rest.Config{},
}

fakeRecorder := record.NewFakeRecorder(42)

c := newController(shipperclientset, shipperInformerFactory,
fakeClientProvider, fakeDynamicClientBuilder, fakeRecorder)

if !c.processNextWorkItem() {
t.Fatal("Could not process work item")
}

var filteredActions []kubetesting.Action
for _, a := range shipperclientset.Actions() {
if a.GetVerb() == "update" {
filteredActions = append(filteredActions, a)
}
}

it = it.DeepCopy()
it.Spec.CanOverride = true
it.Spec.Chart = &chart

expectedActions := []kubetesting.Action{
kubetesting.NewUpdateAction(schema.GroupVersionResource{
Resource: "installationtargets",
Version: shipper.SchemeGroupVersion.Version,
Group: shipper.SchemeGroupVersion.Group,
}, testNs, it),
}
shippertesting.CheckActions(expectedActions, filteredActions, t)
}
@@ -497,16 +497,7 @@ func (i *Installer) installManifests(
labels := existingObj.GetLabels()
owner, ok := labels[shipper.InstallationTargetOwnerLabel]
if !ok {
// If an object was created before we introduced
// self-contained InstallationTargets, it will not
// contain InstallationTargetOwnerLabel, values, so it
// will need to be migrated. We do so by getting the
// older ReleaseLabel.
if relLabel, ok := labels[shipper.ReleaseLabel]; ok {
owner = relLabel
} else {
return shippererrors.NewMissingInstallationTargetOwnerLabelError(existingObj)
}
return shippererrors.NewMissingInstallationTargetOwnerLabelError(existingObj)
}

// If the existing object is owned by the installation target,
@@ -11,7 +11,6 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/discovery"
fakediscovery "k8s.io/client-go/discovery/fake"
@@ -200,25 +199,3 @@ func buildChart(appName, version, repoUrl string) shipper.Chart {
RepoURL: repoUrl,
}
}

func buildRelease(namespace, name string, chart shipper.Chart) *shipper.Release {
return &shipper.Release{
ObjectMeta: v1.ObjectMeta{
Name: name,
Namespace: namespace,
UID: types.UID("foobar"),
Labels: map[string]string{
shipper.AppLabel: name,
shipper.ReleaseLabel: name,
},
Annotations: map[string]string{
shipper.ReleaseGenerationAnnotation: "0",
},
},
Spec: shipper.ReleaseSpec{
Environment: shipper.ReleaseEnvironment{
Chart: chart,
},
},
}
}

0 comments on commit 9967c55

Please sign in to comment.
You can’t perform that action at this time.