|
|
@@ -69,6 +69,31 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard cluster ID",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterClusters": "cluster*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Cluster: "cluster-one",
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Cluster: "cluster-two",
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Cluster: "cluster",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Cluster: "foo",
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Cluster: "cluste",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single cluster name",
|
|
|
qp: map[string]string{
|
|
|
@@ -85,6 +110,22 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard cluster name",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterClusters": "cluster A*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Cluster: "mapped-cluster-ID-ABC",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Cluster: "cluster-one",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single node",
|
|
|
qp: map[string]string{
|
|
|
@@ -101,6 +142,22 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard node",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterNodes": "node-1*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Node: "node-123-abc",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Node: "node-456-def",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single namespace",
|
|
|
qp: map[string]string{
|
|
|
@@ -117,6 +174,25 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard namespace",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterNamespaces": "kube*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Namespace: "kubecost",
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Namespace: "kube-system",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Namespace: "kub",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single controller kind",
|
|
|
qp: map[string]string{
|
|
|
@@ -133,6 +209,22 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard controller kind",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterControllerKinds": "depl*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ ControllerKind: "deployment",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ ControllerKind: "daemonset",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single controller name",
|
|
|
qp: map[string]string{
|
|
|
@@ -149,6 +241,25 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard controller name",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterControllers": "kubecost-*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Controller: "kubecost-cost-analyzer",
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Controller: "kubecost-frontend",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Controller: "kube-proxy",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single controller kind:name combo",
|
|
|
qp: map[string]string{
|
|
|
@@ -167,6 +278,28 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard controller kind:name combo",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterControllers": "deployment:kubecost*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ ControllerKind: "deployment",
|
|
|
+ Controller: "kubecost-cost-analyzer",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ ControllerKind: "daemonset",
|
|
|
+ Controller: "kubecost-cost-analyzer",
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ ControllerKind: "deployment",
|
|
|
+ Controller: "kube-system",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single pod",
|
|
|
qp: map[string]string{
|
|
|
@@ -183,6 +316,22 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard pod",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterPods": "pod-1*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Pod: "pod-123-abc",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Pod: "pod-456-def",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single container",
|
|
|
qp: map[string]string{
|
|
|
@@ -199,6 +348,22 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard container",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterContainers": "container-1*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Container: "container-123-abc",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Container: "container-456-def",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single department",
|
|
|
qp: map[string]string{
|
|
|
@@ -219,6 +384,26 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard department",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterDepartments": "pa*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Labels: map[string]string{
|
|
|
+ "internal-product-umbrella": "pa-1",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Labels: map[string]string{
|
|
|
+ "internal-product-umbrella": "ps-N",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single label",
|
|
|
qp: map[string]string{
|
|
|
@@ -244,6 +429,31 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard label",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterLabels": "app:cost-*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Labels: map[string]string{
|
|
|
+ "app": "cost-analyzer",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Labels: map[string]string{
|
|
|
+ "app": "foo",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Labels: map[string]string{
|
|
|
+ "foo": "bar",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single annotation",
|
|
|
qp: map[string]string{
|
|
|
@@ -269,6 +479,31 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard annotation",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterAnnotations": "app:cost-*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Annotations: map[string]string{
|
|
|
+ "app": "cost-analyzer",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Annotations: map[string]string{
|
|
|
+ "app": "foo",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Annotations: map[string]string{
|
|
|
+ "foo": "bar",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "single service",
|
|
|
qp: map[string]string{
|
|
|
@@ -306,6 +541,26 @@ func TestFiltersFromParamsV1(t *testing.T) {
|
|
|
}),
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "wildcard service",
|
|
|
+ qp: map[string]string{
|
|
|
+ "filterServices": "serv*",
|
|
|
+ },
|
|
|
+ shouldMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Services: []string{"serv1"},
|
|
|
+ }),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Services: []string{"serv2"},
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ shouldNotMatch: []kubecost.Allocation{
|
|
|
+ allocGenerator(kubecost.AllocationProperties{}),
|
|
|
+ allocGenerator(kubecost.AllocationProperties{
|
|
|
+ Services: []string{"foo"},
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
name: "multi: namespaces, labels",
|
|
|
qp: map[string]string{
|