From 6ebf8b00cd364449e31e5d098897a0f9e046d017 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 18:50:02 +0000 Subject: [PATCH 1/9] first pass at fixing test fixtures --- pkg/kube/resources_test.go | 7 +- pkg/kube/test_files/test_1/deployment2.yaml | 20 +++++ pkg/validator/controller_test.go | 86 ++++++++++++------- pkg/validator/fullaudit_test.go | 5 +- pkg/validator/schema.go | 12 +++ test/fixtures.go | 44 ++++++++-- .../passing_test.deployment.yaml | 4 +- 7 files changed, 135 insertions(+), 43 deletions(-) create mode 100644 pkg/kube/test_files/test_1/deployment2.yaml diff --git a/pkg/kube/resources_test.go b/pkg/kube/resources_test.go index b6b4caf14..71ea1543f 100644 --- a/pkg/kube/resources_test.go +++ b/pkg/kube/resources_test.go @@ -27,12 +27,12 @@ func TestGetResourcesFromPath(t *testing.T) { assert.Equal(t, 1, len(resources.Namespaces), "Should have a namespace") assert.Equal(t, "two", resources.Namespaces[0].ObjectMeta.Name) - assert.Equal(t, 8, len(resources.Controllers), "Should have eight controllers") + assert.Equal(t, 9, len(resources.Controllers), "Should have eight controllers") namespaceCount := map[string]int{} for _, controller := range resources.Controllers { namespaceCount[controller.ObjectMeta.GetNamespace()]++ } - assert.Equal(t, 7, namespaceCount[""], "Should have seven controller in default namespace") + assert.Equal(t, 8, namespaceCount[""], "Should have seven controller in default namespace") assert.Equal(t, 1, namespaceCount["two"], "Should have one controller in namespace 'two'") } @@ -99,7 +99,8 @@ func TestGetResourceFromAPI(t *testing.T) { assert.IsType(t, time.Now(), resources.CreationTime, "Creation time should be set") assert.Equal(t, 0, len(resources.Nodes), "Should not have any nodes") - assert.Equal(t, 1, len(resources.Controllers), "Should have 1 controller") + assert.Equal(t, 2, len(resources.Controllers), "Should have 1 controller") assert.Equal(t, "", resources.Controllers[0].ObjectMeta.GetName()) + assert.Equal(t, "foo", resources.Controllers[1].ObjectMeta.GetName()) } diff --git a/pkg/kube/test_files/test_1/deployment2.yaml b/pkg/kube/test_files/test_1/deployment2.yaml new file mode 100644 index 000000000..a705174d1 --- /dev/null +++ b/pkg/kube/test_files/test_1/deployment2.yaml @@ -0,0 +1,20 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: test-deployment-2 +spec: + replicas: 2 + selector: + matchLabels: + app: test-deployment + template: + metadata: + labels: + app: test-deployment + spec: + containers: + - name: ubuntu + image: ubuntu + ports: + - containerPort: 3000 + diff --git a/pkg/validator/controller_test.go b/pkg/validator/controller_test.go index 8bfed5051..4fec9dcd7 100644 --- a/pkg/validator/controller_test.go +++ b/pkg/validator/controller_test.go @@ -20,6 +20,7 @@ import ( "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" conf "github.com/fairwindsops/polaris/pkg/config" "github.com/fairwindsops/polaris/pkg/kube" @@ -59,41 +60,66 @@ func TestValidateController(t *testing.T) { } func TestControllerLevelChecks(t *testing.T) { - c := conf.Configuration{ - Checks: map[string]conf.Severity{ - "multipleReplicasForDeployment": conf.SeverityDanger, - }, + testResources := func(res *kube.ResourceProvider) { + c := conf.Configuration{ + Checks: map[string]conf.Severity{ + "multipleReplicasForDeployment": conf.SeverityDanger, + }, + } + expectedResult := ResultMessage{ + ID: "multipleReplicasForDeployment", + Severity: "danger", + Category: "Reliability", + } + for _, controller := range res.Controllers { + if controller.Kind == "Deployment" { + actualResult, err := ValidateController(context.Background(), &c, controller) + if err != nil { + panic(err) + } + if controller.ObjectMeta.GetName() == "test-deployment-2" { + expectedResult.Success = true + expectedResult.Message = "Multiple replicas are scheduled" + } else if controller.ObjectMeta.GetName() == "test-deployment" { + expectedResult.Success = false + expectedResult.Message = "Only one replica is scheduled" + } + expectedResults := ResultSet{ + "multipleReplicasForDeployment": expectedResult, + } + + assert.Equal(t, "Deployment", actualResult.Kind) + assert.Equal(t, 1, len(actualResult.Results), "should be equal") + assert.EqualValues(t, expectedResults, actualResult.Results, controller.ObjectMeta.GetName()) + } + } } - resources, err := kube.CreateResourceProviderFromPath("../kube/test_files/test_1") + res, err := kube.CreateResourceProviderFromPath("../kube/test_files/test_1") assert.Equal(t, nil, err, "Error should be nil") - - assert.Equal(t, 8, len(resources.Controllers), "Should have eight controllers") - - expectedSum := CountSummary{ - Successes: uint(0), - Warnings: uint(0), - Dangers: uint(1), - } - - expectedResults := ResultSet{ - "multipleReplicasForDeployment": {ID: "multipleReplicasForDeployment", Message: "Only one replica is scheduled", Success: false, Severity: "danger", Category: "Reliability"}, + assert.Equal(t, 9, len(res.Controllers), "Should have eight controllers") + testResources(res) + + k8s, dynamicClient := test.SetupTestAPI() + k8s = test.SetupAddControllers(context.Background(), k8s, "test") + dWithoutReplicas, _ := test.MockDeploy("test", "test") + dWithoutReplicas.ObjectMeta.SetName("test-deployment") + one := int32(1) + two := int32(2) + dWithoutReplicas.Spec.Replicas = &one + if _, err := k8s.AppsV1().Deployments("test-dep").Create(context.Background(), &dWithoutReplicas, metav1.CreateOptions{}); err != nil { + panic(err) } - - for _, controller := range resources.Controllers { - if controller.Kind == "Deployment" && controller.ObjectMeta.GetName() == "test-deployment" { - actualResult, err := ValidateController(context.Background(), &c, controller) - if err != nil { - panic(err) - } - - assert.Equal(t, "Deployment", actualResult.Kind) - assert.Equal(t, 1, len(actualResult.Results), "should be equal") - assert.EqualValues(t, expectedSum, actualResult.GetSummary()) - assert.EqualValues(t, expectedResults, actualResult.Results) - } + dWithReplicas, _ := test.MockDeploy("test", "test") + dWithReplicas.ObjectMeta.SetName("test-deployment-2") + dWithReplicas.Spec.Replicas = &two + if _, err := k8s.AppsV1().Deployments("test-dep").Create(context.Background(), &dWithReplicas, metav1.CreateOptions{}); err != nil { + panic(err) } - + res, err = kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient) + assert.Equal(t, err, nil, "error should be nil") + assert.Equal(t, 2, len(res.Controllers), "Should have two controllers") + testResources(res) } func TestSkipHealthChecks(t *testing.T) { diff --git a/pkg/validator/fullaudit_test.go b/pkg/validator/fullaudit_test.go index 63690da84..677a369e0 100644 --- a/pkg/validator/fullaudit_test.go +++ b/pkg/validator/fullaudit_test.go @@ -2,6 +2,7 @@ package validator import ( "context" + "fmt" "testing" conf "github.com/fairwindsops/polaris/pkg/config" @@ -14,10 +15,10 @@ func TestGetTemplateData(t *testing.T) { k8s, dynamicClient := test.SetupTestAPI() k8s = test.SetupAddControllers(context.Background(), k8s, "test") k8s = test.SetupAddExtraControllerVersions(context.Background(), k8s, "test-extra") - // TODO figure out how to mock out dynamic client. - // and add in pods for all controllers to fill out tests. resources, err := kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient) assert.Equal(t, err, nil, "error should be nil") + fmt.Println(resources.Controllers[0]) + assert.Equal(t, 5, len(resources.Controllers)) c := conf.Configuration{ Checks: map[string]conf.Severity{ diff --git a/pkg/validator/schema.go b/pkg/validator/schema.go index 17c38e466..cd5b0d6eb 100644 --- a/pkg/validator/schema.go +++ b/pkg/validator/schema.go @@ -3,6 +3,7 @@ package validator import ( "bytes" "context" + "encoding/json" "fmt" "io" "sort" @@ -155,6 +156,17 @@ func applyControllerSchemaChecks(ctx context.Context, conf *config.Configuration } else if check == nil { continue } + if controller.ObjectMeta.GetNamespace() == "check-test" { + fmt.Println("check conroller\n", string(controller.OriginalObjectJSON)) + parsed := map[string]interface{}{} + err := json.Unmarshal(controller.OriginalObjectJSON, &parsed) + if err != nil { + panic(err) + } + parsed = parsed["Object"].(map[string]interface{}) + fmt.Println(parsed["spec"].(map[string]interface{})["template"]) + fmt.Println(parsed["spec"].(map[string]interface{})["template"].(map[string]interface{})["metadata"]) + } passes, err := check.CheckController(controller.OriginalObjectJSON) if err != nil { return nil, err diff --git a/test/fixtures.go b/test/fixtures.go index 2de46e980..4ad7fdf50 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -11,6 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" dynamicFake "k8s.io/client-go/dynamic/fake" "k8s.io/client-go/kubernetes" @@ -46,14 +47,35 @@ func MockNakedPod() corev1.Pod { } // MockDeploy creates a Deployment object. -func MockDeploy() appsv1.Deployment { +func MockDeploy(name, namespace string) (appsv1.Deployment, corev1.Pod) { p := MockPod() d := appsv1.Deployment{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "apps/v1", + Kind: "Deployment", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + UID: "1111", + }, Spec: appsv1.DeploymentSpec{ Template: corev1.PodTemplateSpec{Spec: p.Spec}, }, } - return d + pod := corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: name + "-12345", + Namespace: namespace, + OwnerReferences: []metav1.OwnerReference{{ + APIVersion: "apps/v1", + Kind: "Deployment", + Name: d.ObjectMeta.Name, + UID: d.ObjectMeta.UID, + }}, + }, + } + return d, pod } // MockStatefulSet creates a StatefulSet object. @@ -113,15 +135,23 @@ func MockReplicationController() corev1.ReplicationController { // SetupTestAPI creates a test kube API struct. func SetupTestAPI() (kubernetes.Interface, dynamic.Interface) { - scheme := runtime.NewScheme() - - return fake.NewSimpleClientset(), dynamicFake.NewSimpleDynamicClient(scheme) + gvk := schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} + sch := runtime.NewScheme() + d, p := MockDeploy("beeb", "beeb") + sch.AddKnownTypeWithName(gvk, &d) + dynamicClient := dynamicFake.NewSimpleDynamicClient(sch) + dynamicClient.Resource(schema.GroupVersionResource{ + Group: "apps", + Version: "v1", + Resource: "Deployment", + }) + return fake.NewSimpleClientset(&d, &p), dynamicClient } // SetupAddControllers creates mock controllers and adds them to the test clientset. func SetupAddControllers(ctx context.Context, k kubernetes.Interface, namespace string) kubernetes.Interface { - d1 := MockDeploy() - if _, err := k.AppsV1().Deployments(namespace).Create(ctx, &d1, metav1.CreateOptions{}); err != nil { + d, _ := MockDeploy("foo", namespace) + if _, err := k.AppsV1().Deployments(namespace).Create(ctx, &d, metav1.CreateOptions{}); err != nil { panic(err) } diff --git a/test/webhook_cases/passing_test.deployment.yaml b/test/webhook_cases/passing_test.deployment.yaml index d6d66f754..54e947c87 100644 --- a/test/webhook_cases/passing_test.deployment.yaml +++ b/test/webhook_cases/passing_test.deployment.yaml @@ -13,6 +13,8 @@ spec: metadata: labels: app: nginx + sre: foo + maintainer_team: bar spec: containers: - name: nginx @@ -26,4 +28,4 @@ spec: runAsNonRoot: true capabilities: drop: - - ALL \ No newline at end of file + - ALL From d7e24ca88206501e5c2334df3545308b9157c6e9 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 21:30:30 +0000 Subject: [PATCH 2/9] tests mostly working --- pkg/kube/resources_test.go | 24 ++-- pkg/validator/controller_test.go | 43 +++--- pkg/validator/fullaudit_test.go | 38 +++-- pkg/validator/pod_test.go | 10 -- pkg/validator/schema.go | 1 + test/fixtures.go | 236 +++++++++++++++++-------------- 6 files changed, 194 insertions(+), 158 deletions(-) diff --git a/pkg/kube/resources_test.go b/pkg/kube/resources_test.go index 71ea1543f..49a7b0be9 100644 --- a/pkg/kube/resources_test.go +++ b/pkg/kube/resources_test.go @@ -87,10 +87,7 @@ func TestAddResourcesFromReader(t *testing.T) { } func TestGetResourceFromAPI(t *testing.T) { - k8s, dynamicInterface := test.SetupTestAPI() - k8s = test.SetupAddControllers(context.Background(), k8s, "test") - // TODO find a way to mock out the dynamic client - // and create fake pods in order to find all of the controllers. + k8s, dynamicInterface := test.SetupTestAPI(test.GetMockControllers("test")...) resources, err := CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicInterface) assert.Equal(t, nil, err, "Error should be nil") @@ -99,8 +96,19 @@ func TestGetResourceFromAPI(t *testing.T) { assert.IsType(t, time.Now(), resources.CreationTime, "Creation time should be set") assert.Equal(t, 0, len(resources.Nodes), "Should not have any nodes") - assert.Equal(t, 2, len(resources.Controllers), "Should have 1 controller") - - assert.Equal(t, "", resources.Controllers[0].ObjectMeta.GetName()) - assert.Equal(t, "foo", resources.Controllers[1].ObjectMeta.GetName()) + assert.Equal(t, 5, len(resources.Controllers), "Should have 5 controllers") + + expectedNames := map[string]bool{ + "deploy": false, + "job": false, + "cronjob": false, + "statefulset": false, + "daemonset": false, + } + for _, ctrl := range resources.Controllers { + expectedNames[ctrl.ObjectMeta.GetName()] = true + } + for name, val := range expectedNames { + assert.Equal(t, true, val, name) + } } diff --git a/pkg/validator/controller_test.go b/pkg/validator/controller_test.go index 4fec9dcd7..78230e5d8 100644 --- a/pkg/validator/controller_test.go +++ b/pkg/validator/controller_test.go @@ -20,7 +20,7 @@ import ( "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + //metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" conf "github.com/fairwindsops/polaris/pkg/config" "github.com/fairwindsops/polaris/pkg/kube" @@ -100,26 +100,27 @@ func TestControllerLevelChecks(t *testing.T) { assert.Equal(t, 9, len(res.Controllers), "Should have eight controllers") testResources(res) - k8s, dynamicClient := test.SetupTestAPI() - k8s = test.SetupAddControllers(context.Background(), k8s, "test") - dWithoutReplicas, _ := test.MockDeploy("test", "test") - dWithoutReplicas.ObjectMeta.SetName("test-deployment") - one := int32(1) - two := int32(2) - dWithoutReplicas.Spec.Replicas = &one - if _, err := k8s.AppsV1().Deployments("test-dep").Create(context.Background(), &dWithoutReplicas, metav1.CreateOptions{}); err != nil { - panic(err) - } - dWithReplicas, _ := test.MockDeploy("test", "test") - dWithReplicas.ObjectMeta.SetName("test-deployment-2") - dWithReplicas.Spec.Replicas = &two - if _, err := k8s.AppsV1().Deployments("test-dep").Create(context.Background(), &dWithReplicas, metav1.CreateOptions{}); err != nil { - panic(err) - } - res, err = kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient) - assert.Equal(t, err, nil, "error should be nil") - assert.Equal(t, 2, len(res.Controllers), "Should have two controllers") - testResources(res) + /* + k8s, dynamicClient := test.SetupTestAPI(test.GetMockControllers()...) + dWithoutReplicas, _ := test.MockDeploy("test", "test") + dWithoutReplicas.ObjectMeta.SetName("test-deployment") + one := int32(1) + two := int32(2) + dWithoutReplicas.Spec.Replicas = &one + if _, err := k8s.AppsV1().Deployments("test-dep").Create(context.Background(), &dWithoutReplicas, metav1.CreateOptions{}); err != nil { + panic(err) + } + dWithReplicas, _ := test.MockDeploy("test", "test") + dWithReplicas.ObjectMeta.SetName("test-deployment-2") + dWithReplicas.Spec.Replicas = &two + if _, err := k8s.AppsV1().Deployments("test-dep").Create(context.Background(), &dWithReplicas, metav1.CreateOptions{}); err != nil { + panic(err) + } + res, err = kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient) + assert.Equal(t, err, nil, "error should be nil") + assert.Equal(t, 2, len(res.Controllers), "Should have two controllers") + testResources(res) + */ } func TestSkipHealthChecks(t *testing.T) { diff --git a/pkg/validator/fullaudit_test.go b/pkg/validator/fullaudit_test.go index 677a369e0..d99508184 100644 --- a/pkg/validator/fullaudit_test.go +++ b/pkg/validator/fullaudit_test.go @@ -12,12 +12,10 @@ import ( ) func TestGetTemplateData(t *testing.T) { - k8s, dynamicClient := test.SetupTestAPI() - k8s = test.SetupAddControllers(context.Background(), k8s, "test") - k8s = test.SetupAddExtraControllerVersions(context.Background(), k8s, "test-extra") + k8s, dynamicClient := test.SetupTestAPI(test.GetMockControllers("test")...) + //k8s = test.SetupAddExtraControllerVersions(context.Background(), k8s, "test-extra") resources, err := kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient) assert.Equal(t, err, nil, "error should be nil") - fmt.Println(resources.Controllers[0]) assert.Equal(t, 5, len(resources.Controllers)) c := conf.Configuration{ @@ -29,29 +27,39 @@ func TestGetTemplateData(t *testing.T) { sum := CountSummary{ Successes: uint(0), - Warnings: uint(1), - Dangers: uint(1), + Warnings: uint(3), + Dangers: uint(3), } actualAudit, err := RunAudit(context.Background(), c, resources) - assert.Equal(t, err, nil, "error should be nil") - assert.EqualValues(t, sum, actualAudit.GetSummary()) assert.Equal(t, actualAudit.SourceType, "Cluster", "should be from a cluster") assert.Equal(t, actualAudit.SourceName, "test", "should be from a cluster") - expected := []struct { + expectedResults := []struct { kind string results int }{ - {kind: "Pod", results: 2}, + {kind: "StatefulSet", results: 2}, + {kind: "DaemonSet", results: 2}, + {kind: "Deployment", results: 2}, + {kind: "Job", results: 0}, + {kind: "CronJob", results: 0}, } + fmt.Println("res", actualAudit.Results) - assert.Equal(t, len(expected), len(actualAudit.Results)) - for idx, result := range actualAudit.Results { - assert.Equal(t, expected[idx].kind, result.Kind) - assert.Equal(t, 1, len(result.PodResult.ContainerResults)) - assert.Equal(t, expected[idx].results, len(result.PodResult.ContainerResults[0].Results)) + assert.Equal(t, len(expectedResults), len(actualAudit.Results)) + for _, result := range actualAudit.Results { + found := false + for _, expected := range expectedResults { + if expected.kind != result.Kind { + continue + } + found = true + assert.Equal(t, 1, len(result.PodResult.ContainerResults)) + assert.Equal(t, expected.results, len(result.PodResult.ContainerResults[0].Results)) + } + assert.Equal(t, found, true) } } diff --git a/pkg/validator/pod_test.go b/pkg/validator/pod_test.go index bfbc22abb..4e5a7b4b3 100644 --- a/pkg/validator/pod_test.go +++ b/pkg/validator/pod_test.go @@ -36,8 +36,6 @@ func TestValidatePod(t *testing.T) { }, } - k8s, _ := test.SetupTestAPI() - k8s = test.SetupAddControllers(context.Background(), k8s, "test") p := test.MockPod() deployment, err := kube.NewGenericWorkloadFromPod(p, nil) assert.NoError(t, err) @@ -73,8 +71,6 @@ func TestInvalidIPCPod(t *testing.T) { }, } - k8s, _ := test.SetupTestAPI() - k8s = test.SetupAddControllers(context.Background(), k8s, "test") p := test.MockPod() p.Spec.HostIPC = true workload, err := kube.NewGenericWorkloadFromPod(p, nil) @@ -110,8 +106,6 @@ func TestInvalidNeworkPod(t *testing.T) { }, } - k8s, _ := test.SetupTestAPI() - k8s = test.SetupAddControllers(context.Background(), k8s, "test") p := test.MockPod() p.Spec.HostNetwork = true workload, err := kube.NewGenericWorkloadFromPod(p, nil) @@ -148,8 +142,6 @@ func TestInvalidPIDPod(t *testing.T) { }, } - k8s, _ := test.SetupTestAPI() - k8s = test.SetupAddControllers(context.Background(), k8s, "test") p := test.MockPod() p.Spec.HostPID = true workload, err := kube.NewGenericWorkloadFromPod(p, nil) @@ -192,8 +184,6 @@ func TestExemption(t *testing.T) { }, } - k8s, _ := test.SetupTestAPI() - k8s = test.SetupAddControllers(context.Background(), k8s, "test") p := test.MockPod() p.Spec.HostIPC = true p.ObjectMeta = metav1.ObjectMeta{ diff --git a/pkg/validator/schema.go b/pkg/validator/schema.go index cd5b0d6eb..d8be5cc9d 100644 --- a/pkg/validator/schema.go +++ b/pkg/validator/schema.go @@ -199,6 +199,7 @@ func applyContainerSchemaChecks(ctx context.Context, conf *config.Configuration, passes, err = check.CheckPod(&podCopy) } else { passes, err = check.CheckContainer(container) + fmt.Println("check container", check.ID, passes, err, container) } if err != nil { return nil, err diff --git a/test/fixtures.go b/test/fixtures.go index 4ad7fdf50..a737f4b93 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -2,6 +2,7 @@ package test import ( "context" + "encoding/json" appsv1 "k8s.io/api/apps/v1" appsv1beta1 "k8s.io/api/apps/v1beta1" @@ -10,14 +11,28 @@ import ( batchv1beta1 "k8s.io/api/batch/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" dynamicFake "k8s.io/client-go/dynamic/fake" "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/fake" ) +func newUnstructured(apiVersion, kind, namespace, name string, spec interface{}) unstructured.Unstructured { + return unstructured.Unstructured{ + Object: map[string]interface{}{ + "apiVersion": apiVersion, + "kind": kind, + "metadata": map[string]interface{}{ + "namespace": namespace, + "name": name, + }, + "spec": spec, + }, + } +} + // MockContainer creates a container object func MockContainer(name string) corev1.Container { c := corev1.Container{ @@ -46,146 +61,159 @@ func MockNakedPod() corev1.Pod { } } -// MockDeploy creates a Deployment object. -func MockDeploy(name, namespace string) (appsv1.Deployment, corev1.Pod) { - p := MockPod() - d := appsv1.Deployment{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "apps/v1", - Kind: "Deployment", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - UID: "1111", - }, - Spec: appsv1.DeploymentSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } +// MockController creates a mock controller and pod +func MockController(apiVersion, kind, namespace, name string, spec interface{}, podSpec corev1.PodSpec) (unstructured.Unstructured, corev1.Pod) { + d := newUnstructured(apiVersion, kind, namespace, name, spec) pod := corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: name + "-12345", Namespace: namespace, OwnerReferences: []metav1.OwnerReference{{ - APIVersion: "apps/v1", - Kind: "Deployment", - Name: d.ObjectMeta.Name, - UID: d.ObjectMeta.UID, + APIVersion: apiVersion, + Kind: kind, + Name: name, }}, }, + Spec: podSpec, } return d, pod } -// MockStatefulSet creates a StatefulSet object. -func MockStatefulSet() appsv1.StatefulSet { +// MockControllerWithNormalSpec mocks a controller with podspec at spec.template.spec +func MockControllerWithNormalSpec(apiVersion, kind, namespace, name string) (unstructured.Unstructured, corev1.Pod) { p := MockPod() - s := appsv1.StatefulSet{ - Spec: appsv1.StatefulSetSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, + b, err := json.Marshal(p.Spec) + if err != nil { + panic(err) + } + pSpec := map[string]interface{}{} + err = json.Unmarshal(b, &pSpec) + if err != nil { + panic(err) + } + spec := map[string]interface{}{ + "template": map[string]interface{}{ + "spec": pSpec, }, } - return s + return MockController(apiVersion, kind, namespace, name, spec, p.Spec) +} + +func MockDeploy(namespace, name string) (unstructured.Unstructured, corev1.Pod) { + return MockControllerWithNormalSpec("apps/v1", "Deployment", namespace, name) +} + +// MockStatefulSet creates a StatefulSet object. +func MockStatefulSet(namespace, name string) (unstructured.Unstructured, corev1.Pod) { + return MockControllerWithNormalSpec("apps/v1", "StatefulSet", namespace, name) } // MockDaemonSet creates a DaemonSet object. -func MockDaemonSet() appsv1.DaemonSet { - p := MockPod() - return appsv1.DaemonSet{ - Spec: appsv1.DaemonSetSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } +func MockDaemonSet(namespace, name string) (unstructured.Unstructured, corev1.Pod) { + return MockControllerWithNormalSpec("apps/v1", "DaemonSet", namespace, name) } // MockJob creates a Job object. -func MockJob() batchv1.Job { - p := MockPod() - return batchv1.Job{ - Spec: batchv1.JobSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } +func MockJob(namespace, name string) (unstructured.Unstructured, corev1.Pod) { + return MockControllerWithNormalSpec("batch/v1", "Job", namespace, name) } // MockCronJob creates a CronJob object. -func MockCronJob() batchv1beta1.CronJob { +func MockCronJob(namespace, name string) (unstructured.Unstructured, corev1.Pod) { p := MockPod() - return batchv1beta1.CronJob{ - Spec: batchv1beta1.CronJobSpec{ - JobTemplate: batchv1beta1.JobTemplateSpec{ - Spec: batchv1.JobSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, + b, err := json.Marshal(p.Spec) + if err != nil { + panic(err) + } + pSpec := map[string]interface{}{} + err = json.Unmarshal(b, &pSpec) + if err != nil { + panic(err) + } + spec := map[string]interface{}{ + "job_template": map[string]interface{}{ + "spec": map[string]interface{}{ + "template": map[string]interface{}{ + "spec": pSpec, }, }, }, } + return MockController("batch/v1beta1", "CronJob", namespace, name, spec, p.Spec) } // MockReplicationController creates a ReplicationController object. -func MockReplicationController() corev1.ReplicationController { - p := MockPod() - return corev1.ReplicationController{ - Spec: corev1.ReplicationControllerSpec{ - Template: &corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } +func MockReplicationController(namespace, name string) (unstructured.Unstructured, corev1.Pod) { + return MockControllerWithNormalSpec("core/v1", "ReplicationController", namespace, name) } // SetupTestAPI creates a test kube API struct. -func SetupTestAPI() (kubernetes.Interface, dynamic.Interface) { - gvk := schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} - sch := runtime.NewScheme() - d, p := MockDeploy("beeb", "beeb") - sch.AddKnownTypeWithName(gvk, &d) - dynamicClient := dynamicFake.NewSimpleDynamicClient(sch) - dynamicClient.Resource(schema.GroupVersionResource{ - Group: "apps", - Version: "v1", - Resource: "Deployment", - }) - return fake.NewSimpleClientset(&d, &p), dynamicClient -} - -// SetupAddControllers creates mock controllers and adds them to the test clientset. -func SetupAddControllers(ctx context.Context, k kubernetes.Interface, namespace string) kubernetes.Interface { - d, _ := MockDeploy("foo", namespace) - if _, err := k.AppsV1().Deployments(namespace).Create(ctx, &d, metav1.CreateOptions{}); err != nil { - panic(err) - } - - s1 := MockStatefulSet() - if _, err := k.AppsV1().StatefulSets(namespace).Create(ctx, &s1, metav1.CreateOptions{}); err != nil { - panic(err) - } - - ds1 := MockDaemonSet() - if _, err := k.AppsV1().DaemonSets(namespace).Create(ctx, &ds1, metav1.CreateOptions{}); err != nil { - panic(err) - } - - j1 := MockJob() - if _, err := k.BatchV1().Jobs(namespace).Create(ctx, &j1, metav1.CreateOptions{}); err != nil { - panic(err) - } - - cj1 := MockCronJob() - if _, err := k.BatchV1beta1().CronJobs(namespace).Create(ctx, &cj1, metav1.CreateOptions{}); err != nil { - panic(err) - } - - rc1 := MockReplicationController() - if _, err := k.CoreV1().ReplicationControllers(namespace).Create(ctx, &rc1, metav1.CreateOptions{}); err != nil { - panic(err) +func SetupTestAPI(objects ...runtime.Object) (kubernetes.Interface, dynamic.Interface) { + scheme := runtime.NewScheme() + appsv1.AddToScheme(scheme) + corev1.AddToScheme(scheme) + fake.AddToScheme(scheme) + dynamicClient := dynamicFake.NewSimpleDynamicClient(scheme, objects...) + k := fake.NewSimpleClientset(objects...) + k.Resources = []*metav1.APIResourceList{ + { + GroupVersion: corev1.SchemeGroupVersion.String(), + APIResources: []metav1.APIResource{ + {Name: "pods", Namespaced: true, Kind: "Pod"}, + {Name: "replicationcontrollers", Namespaced: true, Kind: "ReplicationController"}, + }, + }, + { + GroupVersion: appsv1.SchemeGroupVersion.String(), + APIResources: []metav1.APIResource{ + {Name: "deployments", Namespaced: true, Kind: "Deployment"}, + {Name: "daemonsets", Namespaced: true, Kind: "DaemonSet"}, + {Name: "statefulsets", Namespaced: true, Kind: "StatefulSet"}, + }, + }, + { + GroupVersion: batchv1.SchemeGroupVersion.String(), + APIResources: []metav1.APIResource{ + {Name: "jobs", Namespaced: true, Kind: "Job"}, + }, + }, + { + GroupVersion: batchv1beta1.SchemeGroupVersion.String(), + APIResources: []metav1.APIResource{ + {Name: "cronjobs", Namespaced: true, Kind: "CronJob"}, + }, + }, + { + GroupVersion: appsv1beta2.SchemeGroupVersion.String(), + APIResources: []metav1.APIResource{ + {Name: "deployments", Namespaced: true, Kind: "Deployment"}, + {Name: "deployments/scale", Namespaced: true, Kind: "Scale", Group: "apps", Version: "v1beta2"}, + }, + }, + { + GroupVersion: appsv1beta1.SchemeGroupVersion.String(), + APIResources: []metav1.APIResource{ + {Name: "statefulsets", Namespaced: true, Kind: "StatefulSet"}, + {Name: "statefulsets/scale", Namespaced: true, Kind: "Scale", Group: "apps", Version: "v1beta1"}, + }, + }, } + return k, dynamicClient +} - p1 := MockNakedPod() - if _, err := k.CoreV1().Pods(namespace).Create(ctx, &p1, metav1.CreateOptions{}); err != nil { - panic(err) +func GetMockControllers(namespace string) []runtime.Object { + deploy, deployPod := MockDeploy(namespace, "deploy") + statefulset, statefulsetPod := MockStatefulSet(namespace, "statefulset") + daemonset, daemonsetPod := MockDaemonSet(namespace, "daemonset") + job, jobPod := MockJob(namespace, "job") + cronjob, cronjobPod := MockCronJob(namespace, "cronjob") + return []runtime.Object{ + &deploy, &deployPod, + &daemonset, &daemonsetPod, + &statefulset, &statefulsetPod, + &cronjob, &cronjobPod, + &job, &jobPod, } - - return k } // SetupAddExtraControllerVersions creates mock controllers and adds them to the test clientset. From a06f99b137c68cad145a0199ddc4d9f7fb5e80ab Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 21:48:57 +0000 Subject: [PATCH 3/9] add controller test --- pkg/validator/controller_test.go | 36 +++++++++++++------------------- pkg/validator/fullaudit_test.go | 2 -- pkg/validator/schema.go | 4 ---- test/fixtures.go | 17 +++++++++++++++ 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/pkg/validator/controller_test.go b/pkg/validator/controller_test.go index 78230e5d8..bdb70482c 100644 --- a/pkg/validator/controller_test.go +++ b/pkg/validator/controller_test.go @@ -16,11 +16,11 @@ package validator import ( "context" + "encoding/json" "testing" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" - //metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" conf "github.com/fairwindsops/polaris/pkg/config" "github.com/fairwindsops/polaris/pkg/kube" @@ -100,27 +100,19 @@ func TestControllerLevelChecks(t *testing.T) { assert.Equal(t, 9, len(res.Controllers), "Should have eight controllers") testResources(res) - /* - k8s, dynamicClient := test.SetupTestAPI(test.GetMockControllers()...) - dWithoutReplicas, _ := test.MockDeploy("test", "test") - dWithoutReplicas.ObjectMeta.SetName("test-deployment") - one := int32(1) - two := int32(2) - dWithoutReplicas.Spec.Replicas = &one - if _, err := k8s.AppsV1().Deployments("test-dep").Create(context.Background(), &dWithoutReplicas, metav1.CreateOptions{}); err != nil { - panic(err) - } - dWithReplicas, _ := test.MockDeploy("test", "test") - dWithReplicas.ObjectMeta.SetName("test-deployment-2") - dWithReplicas.Spec.Replicas = &two - if _, err := k8s.AppsV1().Deployments("test-dep").Create(context.Background(), &dWithReplicas, metav1.CreateOptions{}); err != nil { - panic(err) - } - res, err = kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient) - assert.Equal(t, err, nil, "error should be nil") - assert.Equal(t, 2, len(res.Controllers), "Should have two controllers") - testResources(res) - */ + replicaSpec := map[string]interface{}{"replicas": 2} + b, err := json.Marshal(replicaSpec) + assert.NoError(t, err) + err = json.Unmarshal(b, &replicaSpec) + + d1, p1 := test.MockDeploy("test", "test-deployment") + d2, p2 := test.MockDeploy("test", "test-deployment-2") + d2.Object["spec"] = replicaSpec + k8s, dynamicClient := test.SetupTestAPI(&d1, &p1, &d2, &p2) + res, err = kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient) + assert.Equal(t, err, nil, "error should be nil") + assert.Equal(t, 2, len(res.Controllers), "Should have two controllers") + testResources(res) } func TestSkipHealthChecks(t *testing.T) { diff --git a/pkg/validator/fullaudit_test.go b/pkg/validator/fullaudit_test.go index d99508184..7cd4c4fba 100644 --- a/pkg/validator/fullaudit_test.go +++ b/pkg/validator/fullaudit_test.go @@ -2,7 +2,6 @@ package validator import ( "context" - "fmt" "testing" conf "github.com/fairwindsops/polaris/pkg/config" @@ -47,7 +46,6 @@ func TestGetTemplateData(t *testing.T) { {kind: "Job", results: 0}, {kind: "CronJob", results: 0}, } - fmt.Println("res", actualAudit.Results) assert.Equal(t, len(expectedResults), len(actualAudit.Results)) for _, result := range actualAudit.Results { diff --git a/pkg/validator/schema.go b/pkg/validator/schema.go index d8be5cc9d..dd1cc656d 100644 --- a/pkg/validator/schema.go +++ b/pkg/validator/schema.go @@ -157,15 +157,12 @@ func applyControllerSchemaChecks(ctx context.Context, conf *config.Configuration continue } if controller.ObjectMeta.GetNamespace() == "check-test" { - fmt.Println("check conroller\n", string(controller.OriginalObjectJSON)) parsed := map[string]interface{}{} err := json.Unmarshal(controller.OriginalObjectJSON, &parsed) if err != nil { panic(err) } parsed = parsed["Object"].(map[string]interface{}) - fmt.Println(parsed["spec"].(map[string]interface{})["template"]) - fmt.Println(parsed["spec"].(map[string]interface{})["template"].(map[string]interface{})["metadata"]) } passes, err := check.CheckController(controller.OriginalObjectJSON) if err != nil { @@ -199,7 +196,6 @@ func applyContainerSchemaChecks(ctx context.Context, conf *config.Configuration, passes, err = check.CheckPod(&podCopy) } else { passes, err = check.CheckContainer(container) - fmt.Println("check container", check.ID, passes, err, container) } if err != nil { return nil, err diff --git a/test/fixtures.go b/test/fixtures.go index a737f4b93..9ad41115a 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -99,6 +99,23 @@ func MockControllerWithNormalSpec(apiVersion, kind, namespace, name string) (uns return MockController(apiVersion, kind, namespace, name, spec, p.Spec) } +func MockDeployWithSpec(namespace, name string, spec map[string]interface{}) (unstructured.Unstructured, corev1.Pod) { + p := MockPod() + b, err := json.Marshal(p.Spec) + if err != nil { + panic(err) + } + pSpec := map[string]interface{}{} + err = json.Unmarshal(b, &pSpec) + if err != nil { + panic(err) + } + spec["template"] = map[string]interface{}{ + "spec": pSpec, + } + return MockController("apps/v1", "Deploymnet", namespace, name, spec, p.Spec) +} + func MockDeploy(namespace, name string) (unstructured.Unstructured, corev1.Pod) { return MockControllerWithNormalSpec("apps/v1", "Deployment", namespace, name) } From 7fe240f05dc0b8b88a3c2732a681af324ae351e1 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 21:50:42 +0000 Subject: [PATCH 4/9] remove debug stuff --- pkg/validator/schema.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pkg/validator/schema.go b/pkg/validator/schema.go index dd1cc656d..d4689b3b0 100644 --- a/pkg/validator/schema.go +++ b/pkg/validator/schema.go @@ -156,14 +156,6 @@ func applyControllerSchemaChecks(ctx context.Context, conf *config.Configuration } else if check == nil { continue } - if controller.ObjectMeta.GetNamespace() == "check-test" { - parsed := map[string]interface{}{} - err := json.Unmarshal(controller.OriginalObjectJSON, &parsed) - if err != nil { - panic(err) - } - parsed = parsed["Object"].(map[string]interface{}) - } passes, err := check.CheckController(controller.OriginalObjectJSON) if err != nil { return nil, err From bf80437e488b6c7ee9715abd1d23a1d7305100ba Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 21:56:21 +0000 Subject: [PATCH 5/9] delint --- pkg/validator/schema.go | 1 - test/fixtures.go | 19 ++----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/pkg/validator/schema.go b/pkg/validator/schema.go index d4689b3b0..17c38e466 100644 --- a/pkg/validator/schema.go +++ b/pkg/validator/schema.go @@ -3,7 +3,6 @@ package validator import ( "bytes" "context" - "encoding/json" "fmt" "io" "sort" diff --git a/test/fixtures.go b/test/fixtures.go index 9ad41115a..769a4f32a 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -99,23 +99,7 @@ func MockControllerWithNormalSpec(apiVersion, kind, namespace, name string) (uns return MockController(apiVersion, kind, namespace, name, spec, p.Spec) } -func MockDeployWithSpec(namespace, name string, spec map[string]interface{}) (unstructured.Unstructured, corev1.Pod) { - p := MockPod() - b, err := json.Marshal(p.Spec) - if err != nil { - panic(err) - } - pSpec := map[string]interface{}{} - err = json.Unmarshal(b, &pSpec) - if err != nil { - panic(err) - } - spec["template"] = map[string]interface{}{ - "spec": pSpec, - } - return MockController("apps/v1", "Deploymnet", namespace, name, spec, p.Spec) -} - +// MockDeploy creates a Deployment object. func MockDeploy(namespace, name string) (unstructured.Unstructured, corev1.Pod) { return MockControllerWithNormalSpec("apps/v1", "Deployment", namespace, name) } @@ -218,6 +202,7 @@ func SetupTestAPI(objects ...runtime.Object) (kubernetes.Interface, dynamic.Inte return k, dynamicClient } +// GetMockControllers returns mocked controllers for 5 major controller types func GetMockControllers(namespace string) []runtime.Object { deploy, deployPod := MockDeploy(namespace, "deploy") statefulset, statefulsetPod := MockStatefulSet(namespace, "statefulset") From 5ab0e59fb833c0283f898feb08dcdb71100b8c6a Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 21:57:23 +0000 Subject: [PATCH 6/9] revert test file --- test/webhook_cases/passing_test.deployment.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/webhook_cases/passing_test.deployment.yaml b/test/webhook_cases/passing_test.deployment.yaml index 54e947c87..d6d66f754 100644 --- a/test/webhook_cases/passing_test.deployment.yaml +++ b/test/webhook_cases/passing_test.deployment.yaml @@ -13,8 +13,6 @@ spec: metadata: labels: app: nginx - sre: foo - maintainer_team: bar spec: containers: - name: nginx @@ -28,4 +26,4 @@ spec: runAsNonRoot: true capabilities: drop: - - ALL + - ALL \ No newline at end of file From 03610d391d167eb6fd72a093d8414978613b6658 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 22:00:28 +0000 Subject: [PATCH 7/9] remove extra controllers from fixtures --- pkg/validator/fullaudit_test.go | 1 - test/fixtures.go | 51 --------------------------------- 2 files changed, 52 deletions(-) diff --git a/pkg/validator/fullaudit_test.go b/pkg/validator/fullaudit_test.go index 7cd4c4fba..5eb193259 100644 --- a/pkg/validator/fullaudit_test.go +++ b/pkg/validator/fullaudit_test.go @@ -12,7 +12,6 @@ import ( func TestGetTemplateData(t *testing.T) { k8s, dynamicClient := test.SetupTestAPI(test.GetMockControllers("test")...) - //k8s = test.SetupAddExtraControllerVersions(context.Background(), k8s, "test-extra") resources, err := kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient) assert.Equal(t, err, nil, "error should be nil") assert.Equal(t, 5, len(resources.Controllers)) diff --git a/test/fixtures.go b/test/fixtures.go index 769a4f32a..218e7537f 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -217,54 +217,3 @@ func GetMockControllers(namespace string) []runtime.Object { &job, &jobPod, } } - -// SetupAddExtraControllerVersions creates mock controllers and adds them to the test clientset. -func SetupAddExtraControllerVersions(ctx context.Context, k kubernetes.Interface, namespace string) kubernetes.Interface { - p := MockPod() - - dv1b1 := appsv1beta1.Deployment{ - Spec: appsv1beta1.DeploymentSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } - if _, err := k.AppsV1beta1().Deployments(namespace).Create(ctx, &dv1b1, metav1.CreateOptions{}); err != nil { - panic(err) - } - - dv1b2 := appsv1beta2.Deployment{ - Spec: appsv1beta2.DeploymentSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } - if _, err := k.AppsV1beta2().Deployments(namespace).Create(ctx, &dv1b2, metav1.CreateOptions{}); err != nil { - panic(err) - } - - ssv1b1 := appsv1beta1.StatefulSet{ - Spec: appsv1beta1.StatefulSetSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } - if _, err := k.AppsV1beta1().StatefulSets(namespace).Create(ctx, &ssv1b1, metav1.CreateOptions{}); err != nil { - panic(err) - } - - ssv1b2 := appsv1beta2.StatefulSet{ - Spec: appsv1beta2.StatefulSetSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } - if _, err := k.AppsV1beta2().StatefulSets(namespace).Create(ctx, &ssv1b2, metav1.CreateOptions{}); err != nil { - panic(err) - } - - dsv1b2 := appsv1beta2.DaemonSet{ - Spec: appsv1beta2.DaemonSetSpec{ - Template: corev1.PodTemplateSpec{Spec: p.Spec}, - }, - } - if _, err := k.AppsV1beta2().DaemonSets(namespace).Create(ctx, &dsv1b2, metav1.CreateOptions{}); err != nil { - panic(err) - } - return k -} From ce6041190303337a92a98d2f25041a3c17711a01 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 22:11:55 +0000 Subject: [PATCH 8/9] delint --- test/fixtures.go | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fixtures.go b/test/fixtures.go index 218e7537f..13163c82c 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -1,7 +1,6 @@ package test import ( - "context" "encoding/json" appsv1 "k8s.io/api/apps/v1" From ad56cc64794d4621907e9e8209e2733b5c6aacfc Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 17 Dec 2020 22:15:50 +0000 Subject: [PATCH 9/9] fix messages --- pkg/kube/resources_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/kube/resources_test.go b/pkg/kube/resources_test.go index 49a7b0be9..dda9e7b62 100644 --- a/pkg/kube/resources_test.go +++ b/pkg/kube/resources_test.go @@ -32,8 +32,8 @@ func TestGetResourcesFromPath(t *testing.T) { for _, controller := range resources.Controllers { namespaceCount[controller.ObjectMeta.GetNamespace()]++ } - assert.Equal(t, 8, namespaceCount[""], "Should have seven controller in default namespace") - assert.Equal(t, 1, namespaceCount["two"], "Should have one controller in namespace 'two'") + assert.Equal(t, 8, namespaceCount[""]) + assert.Equal(t, 1, namespaceCount["two"]) } func TestGetMultipleResourceFromSingleFile(t *testing.T) {