|
|
@@ -37,7 +37,7 @@ func TestKubeModel(t *testing.T) {
|
|
|
require.NotNil(t, err)
|
|
|
|
|
|
require.Len(t, kms.GetErrors(), 1)
|
|
|
- require.Equal(t, "RegisterCluster: uid is nil", kms.GetErrors()[0].Message)
|
|
|
+ require.Equal(t, "UID is missing for Cluster with name ''", kms.GetErrors()[0].Message)
|
|
|
require.Nil(t, kms.Cluster)
|
|
|
})
|
|
|
|
|
|
@@ -47,7 +47,7 @@ func TestKubeModel(t *testing.T) {
|
|
|
|
|
|
kms := NewKubeModelSet(start, end)
|
|
|
|
|
|
- err = kms.RegisterCluster(&Cluster{UID: clusterUID})
|
|
|
+ err = kms.RegisterCluster(&Cluster{UID: clusterUID, Start: start, End: end})
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
require.Len(t, kms.GetErrors(), 0)
|
|
|
@@ -61,7 +61,7 @@ func TestKubeModel(t *testing.T) {
|
|
|
|
|
|
kms := NewKubeModelSet(start, end)
|
|
|
|
|
|
- err = kms.RegisterCluster(&Cluster{UID: clusterUID})
|
|
|
+ err = kms.RegisterCluster(&Cluster{UID: clusterUID, Start: start, End: end})
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
require.Len(t, kms.GetErrors(), 0)
|
|
|
@@ -69,7 +69,7 @@ func TestKubeModel(t *testing.T) {
|
|
|
require.Equal(t, clusterUID, kms.Cluster.UID)
|
|
|
|
|
|
// Register cluster with same UID, expect no-op on second try
|
|
|
- err = kms.RegisterCluster(&Cluster{UID: clusterUID})
|
|
|
+ err = kms.RegisterCluster(&Cluster{UID: clusterUID, Start: start, End: end})
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
require.Len(t, kms.GetErrors(), 0)
|
|
|
@@ -77,7 +77,7 @@ func TestKubeModel(t *testing.T) {
|
|
|
require.Equal(t, clusterUID, kms.Cluster.UID)
|
|
|
|
|
|
// Register cluster with another UID (should not happen), expect no-op
|
|
|
- err = kms.RegisterCluster(&Cluster{UID: "another-uid"})
|
|
|
+ err = kms.RegisterCluster(&Cluster{UID: "another-uid", Start: start, End: end})
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
require.Len(t, kms.GetWarnings(), 1)
|
|
|
@@ -109,13 +109,13 @@ func TestKubeModel(t *testing.T) {
|
|
|
testUID := "uid"
|
|
|
testName := "name"
|
|
|
|
|
|
- err = kms.RegisterNamespace(&Namespace{UID: testUID, Name: testName})
|
|
|
+ err = kms.RegisterNamespace(&Namespace{UID: testUID, Name: testName, Start: start, End: end})
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
require.Len(t, kms.GetWarnings(), 1)
|
|
|
require.Equal(t, "RegisterNamespace: Cluster is nil", kms.GetWarnings()[0].Message)
|
|
|
|
|
|
- testNamespace := &Namespace{UID: testUID, Name: testName}
|
|
|
+ testNamespace := &Namespace{UID: testUID, Name: testName, Start: start, End: end}
|
|
|
|
|
|
require.NotNil(t, kms.Namespaces[testUID])
|
|
|
require.Equal(t, testNamespace, kms.Namespaces[testUID])
|
|
|
@@ -128,7 +128,7 @@ func TestKubeModel(t *testing.T) {
|
|
|
var err error
|
|
|
|
|
|
kms := NewKubeModelSet(start, end)
|
|
|
- err = kms.RegisterCluster(&Cluster{UID: "cluster-uid"})
|
|
|
+ err = kms.RegisterCluster(&Cluster{UID: "cluster-uid", Start: start, End: end})
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
// At this point we have a KMS with a cluster registered
|
|
|
@@ -136,20 +136,20 @@ func TestKubeModel(t *testing.T) {
|
|
|
testUID := "uid"
|
|
|
testName := "name"
|
|
|
|
|
|
- err = kms.RegisterNamespace(&Namespace{UID: testUID, Name: testName})
|
|
|
+ err = kms.RegisterNamespace(&Namespace{UID: testUID, Name: testName, Start: start, End: end})
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
require.Len(t, kms.GetErrors(), 0)
|
|
|
require.NotNil(t, kms.Namespaces[testUID])
|
|
|
|
|
|
- testNamespace := &Namespace{UID: testUID, Name: testName}
|
|
|
+ testNamespace := &Namespace{UID: testUID, Name: testName, Start: start, End: end}
|
|
|
|
|
|
require.Equal(t, testNamespace, kms.Namespaces[testUID])
|
|
|
require.Equal(t, testNamespace, kms.idx.namespaceByName[testName])
|
|
|
require.Equal(t, 1, kms.Metadata.ObjectCount)
|
|
|
|
|
|
// Register same namespace again, expect no-op on second try
|
|
|
- err = kms.RegisterNamespace(&Namespace{UID: testUID, Name: testName})
|
|
|
+ err = kms.RegisterNamespace(&Namespace{UID: testUID, Name: testName, Start: start, End: end})
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
require.Len(t, kms.GetErrors(), 0)
|
|
|
@@ -181,25 +181,27 @@ func TestKubeModel(t *testing.T) {
|
|
|
err = kms.RegisterResourceQuota(&ResourceQuota{UID: "uid", Name: "name", NamespaceUID: ""})
|
|
|
require.NotNil(t, err)
|
|
|
require.Len(t, kms.GetErrors(), 1)
|
|
|
- require.Equal(t, "Namespace is missing for ResourceQuota 'uid'", kms.GetErrors()[0].Message)
|
|
|
+ require.Equal(t, "NamespaceUID is missing for ResourceQuota 'uid'", kms.GetErrors()[0].Message)
|
|
|
require.Len(t, kms.ResourceQuotas, 0)
|
|
|
})
|
|
|
|
|
|
t.Run("register resource quota on KMS w/ namespace", func(t *testing.T) {
|
|
|
kms := NewKubeModelSet(start, end)
|
|
|
- kms.RegisterCluster(&Cluster{UID: "cluster-uid"})
|
|
|
- kms.RegisterNamespace(&Namespace{UID: "namespace-uid", Name: "namespace"})
|
|
|
+ kms.RegisterCluster(&Cluster{UID: "cluster-uid", Start: start, End: end})
|
|
|
+ kms.RegisterNamespace(&Namespace{UID: "namespace-uid", Name: "namespace", Start: start, End: end})
|
|
|
// At this point we have a KMS with a cluster and namespace registered
|
|
|
|
|
|
testUID := "uid"
|
|
|
testName := "name"
|
|
|
|
|
|
- kms.RegisterResourceQuota(&ResourceQuota{UID: testUID, Name: testName, NamespaceUID: "namespace-uid"})
|
|
|
+ kms.RegisterResourceQuota(&ResourceQuota{UID: testUID, Name: testName, NamespaceUID: "namespace-uid", Start: start, End: end})
|
|
|
|
|
|
testRQ := &ResourceQuota{
|
|
|
UID: "uid",
|
|
|
NamespaceUID: "namespace-uid",
|
|
|
Name: "name",
|
|
|
+ Start: start,
|
|
|
+ End: end,
|
|
|
Spec: &ResourceQuotaSpec{Hard: &ResourceQuotaSpecHard{}},
|
|
|
Status: &ResourceQuotaStatus{Used: &ResourceQuotaStatusUsed{}},
|
|
|
}
|
|
|
@@ -210,7 +212,7 @@ func TestKubeModel(t *testing.T) {
|
|
|
require.Equal(t, 2, kms.Metadata.ObjectCount) // 1 namespace and 1 RQ
|
|
|
|
|
|
// Register same RQ again, expect no-op on second try
|
|
|
- kms.RegisterResourceQuota(&ResourceQuota{UID: testUID, Name: testName, NamespaceUID: "namespace-uid"})
|
|
|
+ kms.RegisterResourceQuota(&ResourceQuota{UID: testUID, Name: testName, NamespaceUID: "namespace-uid", Start: start, End: end})
|
|
|
require.Len(t, kms.GetErrors(), 0)
|
|
|
require.NotNil(t, kms.ResourceQuotas[testUID])
|
|
|
require.Equal(t, testRQ, kms.ResourceQuotas[testUID])
|
|
|
@@ -219,12 +221,12 @@ func TestKubeModel(t *testing.T) {
|
|
|
|
|
|
t.Run("register multiple RQs in multiple namespaces", func(t *testing.T) {
|
|
|
kms := NewKubeModelSet(start, end)
|
|
|
- kms.RegisterCluster(&Cluster{UID: "cluster-uid"})
|
|
|
- kms.RegisterNamespace(&Namespace{UID: "namespace-1-uid", Name: "namespace-1"})
|
|
|
- kms.RegisterNamespace(&Namespace{UID: "namespace-2-uid", Name: "namespace-2"})
|
|
|
+ kms.RegisterCluster(&Cluster{UID: "cluster-uid", Start: start, End: end})
|
|
|
+ kms.RegisterNamespace(&Namespace{UID: "namespace-1-uid", Name: "namespace-1", Start: start, End: end})
|
|
|
+ kms.RegisterNamespace(&Namespace{UID: "namespace-2-uid", Name: "namespace-2", Start: start, End: end})
|
|
|
|
|
|
- kms.RegisterResourceQuota(&ResourceQuota{UID: "uid-1", Name: "name-1", NamespaceUID: "namespace-1-uid"})
|
|
|
- kms.RegisterResourceQuota(&ResourceQuota{UID: "uid-2", Name: "name-2", NamespaceUID: "namespace-2-uid"})
|
|
|
+ kms.RegisterResourceQuota(&ResourceQuota{UID: "uid-1", Name: "name-1", NamespaceUID: "namespace-1-uid", Start: start, End: end})
|
|
|
+ kms.RegisterResourceQuota(&ResourceQuota{UID: "uid-2", Name: "name-2", NamespaceUID: "namespace-2-uid", Start: start, End: end})
|
|
|
|
|
|
require.Len(t, kms.GetErrors(), 0)
|
|
|
require.NotNil(t, kms.ResourceQuotas)
|
|
|
@@ -234,6 +236,8 @@ func TestKubeModel(t *testing.T) {
|
|
|
UID: "uid-1",
|
|
|
NamespaceUID: "namespace-1-uid",
|
|
|
Name: "name-1",
|
|
|
+ Start: start,
|
|
|
+ End: end,
|
|
|
Spec: &ResourceQuotaSpec{Hard: &ResourceQuotaSpecHard{}},
|
|
|
Status: &ResourceQuotaStatus{Used: &ResourceQuotaStatusUsed{}},
|
|
|
}
|
|
|
@@ -241,6 +245,8 @@ func TestKubeModel(t *testing.T) {
|
|
|
UID: "uid-2",
|
|
|
NamespaceUID: "namespace-2-uid",
|
|
|
Name: "name-2",
|
|
|
+ Start: start,
|
|
|
+ End: end,
|
|
|
Spec: &ResourceQuotaSpec{Hard: &ResourceQuotaSpecHard{}},
|
|
|
Status: &ResourceQuotaStatus{Used: &ResourceQuotaStatusUsed{}},
|
|
|
}
|
|
|
@@ -253,9 +259,9 @@ func TestKubeModel(t *testing.T) {
|
|
|
err := kms.RegisterResourceQuota(&ResourceQuota{UID: "uid-3", Name: "name-3", NamespaceUID: ""})
|
|
|
require.NotNil(t, err)
|
|
|
require.Len(t, kms.GetErrors(), 1)
|
|
|
- require.Equal(t, "Namespace is missing for ResourceQuota 'uid-3'", kms.GetErrors()[0].Message)
|
|
|
- require.Len(t, kms.ResourceQuotas, 2) // still 2
|
|
|
- require.Equal(t, 4, kms.Metadata.ObjectCount) // unchanged
|
|
|
+ require.Equal(t, "NamespaceUID is missing for ResourceQuota 'uid-3'", kms.GetErrors()[0].Message)
|
|
|
+ require.Len(t, kms.ResourceQuotas, 2) // still 2
|
|
|
+ require.Equal(t, 4, kms.Metadata.ObjectCount) // unchanged
|
|
|
})
|
|
|
})
|
|
|
}
|