pull/2926/merge
Peter Grant 8 years ago committed by GitHub
commit 85dfb1bb11

@ -227,6 +227,8 @@ func (cfgmaps *ConfigMaps) Delete(key string) (rls *rspb.Release, err error) {
// "STATUS" - status of the release (see proto/hapi/release.status.pb.go for variants)
// "OWNER" - owner of the configmap, currently "TILLER".
// "NAME" - name of the release.
// "NAMESPACE" - namespace release was released to.
// "CHART" - name of the chart.
//
func newConfigMapsObject(key string, rls *rspb.Release, lbs labels) (*api.ConfigMap, error) {
const owner = "TILLER"
@ -246,6 +248,8 @@ func newConfigMapsObject(key string, rls *rspb.Release, lbs labels) (*api.Config
lbs.set("OWNER", owner)
lbs.set("STATUS", rspb.Status_Code_name[int32(rls.Info.Status.Code)])
lbs.set("VERSION", strconv.Itoa(int(rls.Version)))
lbs.set("NAMESPACE", rls.Namespace)
lbs.set("CHART", rls.Chart.Metadata.Name)
// create and return configmap object
return &api.ConfigMap{

@ -36,7 +36,8 @@ func TestConfigMapGet(t *testing.T) {
name := "smug-pigeon"
namespace := "default"
key := testKey(name, vers)
rel := releaseStub(name, vers, namespace, rspb.Status_DEPLOYED)
chart := "test"
rel := releaseStub(name, vers, namespace, rspb.Status_DEPLOYED, chart)
cfgmaps := newTestFixtureCfgMaps(t, []*rspb.Release{rel}...)
@ -56,7 +57,8 @@ func TestUNcompressedConfigMapGet(t *testing.T) {
name := "smug-pigeon"
namespace := "default"
key := testKey(name, vers)
rel := releaseStub(name, vers, namespace, rspb.Status_DEPLOYED)
chart := "test"
rel := releaseStub(name, vers, namespace, rspb.Status_DEPLOYED, chart)
// Create a test fixture which contains an uncompressed release
cfgmap, err := newConfigMapsObject(key, rel, nil)
@ -85,12 +87,12 @@ func TestUNcompressedConfigMapGet(t *testing.T) {
func TestConfigMapList(t *testing.T) {
cfgmaps := newTestFixtureCfgMaps(t, []*rspb.Release{
releaseStub("key-1", 1, "default", rspb.Status_DELETED),
releaseStub("key-2", 1, "default", rspb.Status_DELETED),
releaseStub("key-3", 1, "default", rspb.Status_DEPLOYED),
releaseStub("key-4", 1, "default", rspb.Status_DEPLOYED),
releaseStub("key-5", 1, "default", rspb.Status_SUPERSEDED),
releaseStub("key-6", 1, "default", rspb.Status_SUPERSEDED),
releaseStub("key-1", 1, "default", rspb.Status_DELETED, "test"),
releaseStub("key-2", 1, "default", rspb.Status_DELETED, "test"),
releaseStub("key-3", 1, "default", rspb.Status_DEPLOYED, "test"),
releaseStub("key-4", 1, "default", rspb.Status_DEPLOYED, "test"),
releaseStub("key-5", 1, "default", rspb.Status_SUPERSEDED, "test"),
releaseStub("key-6", 1, "default", rspb.Status_SUPERSEDED, "test"),
}...)
// list all deleted releases
@ -137,7 +139,8 @@ func TestConfigMapCreate(t *testing.T) {
name := "smug-pigeon"
namespace := "default"
key := testKey(name, vers)
rel := releaseStub(name, vers, namespace, rspb.Status_DEPLOYED)
chart := "test"
rel := releaseStub(name, vers, namespace, rspb.Status_DEPLOYED, chart)
// store the release in a configmap
if err := cfgmaps.Create(key, rel); err != nil {
@ -161,7 +164,8 @@ func TestConfigMapUpdate(t *testing.T) {
name := "smug-pigeon"
namespace := "default"
key := testKey(name, vers)
rel := releaseStub(name, vers, namespace, rspb.Status_DEPLOYED)
chart := "test"
rel := releaseStub(name, vers, namespace, rspb.Status_DEPLOYED, chart)
cfgmaps := newTestFixtureCfgMaps(t, []*rspb.Release{rel}...)

@ -38,12 +38,12 @@ func TestMemoryCreate(t *testing.T) {
}{
{
"create should success",
releaseStub("rls-c", 1, "default", rspb.Status_DEPLOYED),
releaseStub("rls-c", 1, "default", rspb.Status_DEPLOYED, "test"),
false,
},
{
"create should fail (release already exists)",
releaseStub("rls-a", 1, "default", rspb.Status_DEPLOYED),
releaseStub("rls-a", 1, "default", rspb.Status_DEPLOYED, "test"),
true,
},
}
@ -117,13 +117,13 @@ func TestMemoryUpdate(t *testing.T) {
{
"update release status",
"rls-a.v4",
releaseStub("rls-a", 4, "default", rspb.Status_SUPERSEDED),
releaseStub("rls-a", 4, "default", rspb.Status_SUPERSEDED, "test"),
false,
},
{
"update release does not exist",
"rls-z.v1",
releaseStub("rls-z", 1, "default", rspb.Status_DELETED),
releaseStub("rls-z", 1, "default", rspb.Status_DELETED, "test"),
true,
},
}

@ -22,18 +22,19 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
hapi_chart3 "k8s.io/helm/pkg/proto/hapi/chart"
rspb "k8s.io/helm/pkg/proto/hapi/release"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
rspb "k8s.io/helm/pkg/proto/hapi/release"
)
func releaseStub(name string, vers int32, namespace string, code rspb.Status_Code) *rspb.Release {
func releaseStub(name string, vers int32, namespace string, code rspb.Status_Code, chart string) *rspb.Release {
return &rspb.Release{
Name: name,
Version: vers,
Namespace: namespace,
Info: &rspb.Info{Status: &rspb.Status{Code: code}},
Chart: &hapi_chart3.Chart{Metadata: &hapi_chart3.Metadata{Name: chart}},
}
}
@ -44,15 +45,15 @@ func testKey(name string, vers int32) string {
func tsFixtureMemory(t *testing.T) *Memory {
hs := []*rspb.Release{
// rls-a
releaseStub("rls-a", 4, "default", rspb.Status_DEPLOYED),
releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED),
releaseStub("rls-a", 3, "default", rspb.Status_SUPERSEDED),
releaseStub("rls-a", 2, "default", rspb.Status_SUPERSEDED),
releaseStub("rls-a", 4, "default", rspb.Status_DEPLOYED, "chart-a"),
releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED, "chart-a"),
releaseStub("rls-a", 3, "default", rspb.Status_SUPERSEDED, "chart-a"),
releaseStub("rls-a", 2, "default", rspb.Status_SUPERSEDED, "chart-a"),
// rls-b
releaseStub("rls-b", 4, "default", rspb.Status_DEPLOYED),
releaseStub("rls-b", 1, "default", rspb.Status_SUPERSEDED),
releaseStub("rls-b", 3, "default", rspb.Status_SUPERSEDED),
releaseStub("rls-b", 2, "default", rspb.Status_SUPERSEDED),
releaseStub("rls-b", 4, "default", rspb.Status_DEPLOYED, "chart-b"),
releaseStub("rls-b", 1, "default", rspb.Status_SUPERSEDED, "chart-b"),
releaseStub("rls-b", 3, "default", rspb.Status_SUPERSEDED, "chart-b"),
releaseStub("rls-b", 2, "default", rspb.Status_SUPERSEDED, "chart-b"),
}
mem := NewMemory()

@ -24,8 +24,8 @@ import (
func TestRecordsAdd(t *testing.T) {
rs := records([]*record{
newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED)),
newRecord("rls-a.v2", releaseStub("rls-a", 2, "default", rspb.Status_DEPLOYED)),
newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED, "test")),
newRecord("rls-a.v2", releaseStub("rls-a", 2, "default", rspb.Status_DEPLOYED, "test")),
})
var tests = []struct {
@ -38,13 +38,13 @@ func TestRecordsAdd(t *testing.T) {
"add valid key",
"rls-a.v3",
false,
newRecord("rls-a.v3", releaseStub("rls-a", 3, "default", rspb.Status_SUPERSEDED)),
newRecord("rls-a.v3", releaseStub("rls-a", 3, "default", rspb.Status_SUPERSEDED, "test")),
},
{
"add already existing key",
"rls-a.v1",
true,
newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_DEPLOYED)),
newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_DEPLOYED, "test")),
},
}
@ -69,8 +69,8 @@ func TestRecordsRemove(t *testing.T) {
}
rs := records([]*record{
newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED)),
newRecord("rls-a.v2", releaseStub("rls-a", 2, "default", rspb.Status_DEPLOYED)),
newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED, "test")),
newRecord("rls-a.v2", releaseStub("rls-a", 2, "default", rspb.Status_DEPLOYED, "test")),
})
startLen := rs.Len()
@ -97,8 +97,8 @@ func TestRecordsRemove(t *testing.T) {
func TestRecordsRemoveAt(t *testing.T) {
rs := records([]*record{
newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED)),
newRecord("rls-a.v2", releaseStub("rls-a", 2, "default", rspb.Status_DEPLOYED)),
newRecord("rls-a.v1", releaseStub("rls-a", 1, "default", rspb.Status_SUPERSEDED, "test")),
newRecord("rls-a.v2", releaseStub("rls-a", 2, "default", rspb.Status_DEPLOYED, "test")),
})
if len(rs) != 2 {

Loading…
Cancel
Save