Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
baderbuddy committed Mar 25, 2020
1 parent 5769acf commit a5828a2
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 40 deletions.
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
contrib.go.opencensus.io/exporter/ocagent v0.4.12
git.apache.org/thrift.git v0.12.0 // indirect
github.com/Azure/go-autorest v12.4.3+incompatible
github.com/Azure/go-autorest/autorest v0.10.0 // indirect
github.com/appscode/jsonpatch v0.0.0-20190108182946-7c0e3b262f30
github.com/beorn7/perks v1.0.0
github.com/census-instrumentation/opencensus-proto v0.2.0
Expand Down Expand Up @@ -68,7 +69,7 @@ require (
gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2
gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe
go.opencensus.io v0.21.0
go.uber.org/atomic v1.4.0
go.uber.org/atomic v1.6.0
go.uber.org/multierr v1.5.0
go.uber.org/zap v1.14.0
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915
Expand All @@ -78,13 +79,13 @@ require (
golang.org/x/sys v0.0.0-20191218084908-4a24b4065292
golang.org/x/text v0.3.2
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
golang.org/x/tools v0.0.0-20191219212307-145a1e401f50
golang.org/x/tools v0.0.0-20191224055732-dd894d0a8a40
google.golang.org/api v0.5.0
google.golang.org/appengine v1.6.0
google.golang.org/genproto v0.0.0-20190516172635-bb713bdc0e52
google.golang.org/grpc v1.20.1
gopkg.in/inf.v0 v0.9.1
gopkg.in/yaml.v2 v2.2.2
gopkg.in/yaml.v2 v2.2.7
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
k8s.io/api v0.0.0-20181213150558-05914d821849
k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93
Expand Down
23 changes: 21 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@ cloud.google.com/go v0.39.0/go.mod h1:rVLT6fkc8chs9sfPtFc1SBH6em7n+ZoXaG+87tDISt
contrib.go.opencensus.io/exporter/ocagent v0.4.12 h1:jGFvw3l57ViIVEPKKEUXPcLYIXJmQxLUh6ey1eJhwyc=
contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA=
git.apache.org/thrift.git v0.12.0/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/Azure/go-autorest v1.1.1 h1:4G9tVCqooRY3vDTB2bA1Z01PlSALtnUbji0AfzthUSs=
github.com/Azure/go-autorest v12.0.0+incompatible h1:N+VqClcomLGD/sHb3smbSYYtNMgKpVV3Cd5r5i8z6bQ=
github.com/Azure/go-autorest v12.0.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/Azure/go-autorest v12.4.3+incompatible h1:tCkdkgLZqAk+43nZu3wda9n413Q2g+z7xp1wmjiJTPY=
github.com/Azure/go-autorest v12.4.3+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/Azure/go-autorest v14.0.0+incompatible h1:r/ug62X9o8vikt53/nkAPmFmzfSrCCAplPH7wa+mK0U=
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
github.com/Azure/go-autorest/autorest v0.10.0 h1:mvdtztBqcL8se7MdrUweNieTNi4kfNG6GOJuurQJpuY=
github.com/Azure/go-autorest/autorest v0.10.0/go.mod h1:/FALq9T/kS7b5J5qsQ+RSTUdAmGFqi0vUdVNNx8q630=
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
github.com/Azure/go-autorest/autorest/adal v0.8.2 h1:O1X4oexUxnZCaEUGsvMnr8ZGj8HI37tNezwY4npRqA0=
github.com/Azure/go-autorest/autorest/adal v0.8.2/go.mod h1:ZjhuQClTqx435SRJ2iMlOxPYt3d2C/T/7TiQCVZSn3Q=
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSWlm5Ew6bxipnr/tbM=
github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g=
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM=
github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY=
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k=
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
Expand Down Expand Up @@ -360,6 +377,7 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915 h1:aJ0ex187qoXrJHPo8ZasVTASQB7llQP6YeNzgDALPRk=
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -490,10 +508,11 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
27 changes: 20 additions & 7 deletions pkg/kube/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ func TestGetResourcesFromPath(t *testing.T) {

assert.Equal(t, 0, len(resources.Nodes), "Should not have any nodes")

assert.Equal(t, 8, len(resources.Pods), "Should have two pods")
assert.Equal(t, "", resources.Pods[0].ObjectMeta.Namespace, "Should have one pod in default namespace")

assert.Equal(t, "two", resources.Pods[5].ObjectMeta.Namespace, "Should have one pod in namespace 'two'")
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")
namespaceCount := map[string]int{}
for _, controller := range resources.Controllers {
namespaceCount[controller.GetNamespace()]++
}
assert.Equal(t, 7, namespaceCount[""], "Should have seven controller in default namespace")
assert.Equal(t, 1, namespaceCount["two"], "Should have one controller in namespace 'two'")
}

func TestGetMultipleResourceFromSingleFile(t *testing.T) {
Expand All @@ -38,6 +44,10 @@ func TestGetMultipleResourceFromSingleFile(t *testing.T) {

assert.Equal(t, 0, len(resources.Nodes), "Should not have any nodes")

assert.Equal(t, 4, len(resources.Controllers), "Should have four controllers")
assert.Equal(t, "dashboard", resources.Controllers[0].PodSpec.Containers[0].Name)

assert.Equal(t, 2, len(resources.Namespaces), "Should have a namespace")
assert.Equal(t, "polaris", resources.Namespaces[0].ObjectMeta.Name)
assert.Equal(t, "polaris-2", resources.Namespaces[1].ObjectMeta.Name)
}
Expand All @@ -48,16 +58,19 @@ func TestGetMultipleResourceFromBadFile(t *testing.T) {
}

func TestGetResourceFromAPI(t *testing.T) {
k8s := test.SetupTestAPI()
k8s, dynamicInterface := test.SetupTestAPI()
k8s = test.SetupAddControllers(k8s, "test")
resources, err := CreateResourceProviderFromAPI(k8s, "test", nil)
// TODO find a way to mock out the dynamic client
// and create fake pods in order to find all of the controllers.
resources, err := CreateResourceProviderFromAPI(k8s, "test", &dynamicInterface)
assert.Equal(t, nil, err, "Error should be nil")

assert.Equal(t, "Cluster", resources.SourceType, "Should have type Path")
assert.Equal(t, "test", resources.SourceName, "Should have source name")
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.Pods), "Should have a pod")
assert.Equal(t, 1, len(resources.Controllers), "Should have 1 controller")

assert.Equal(t, "", resources.Controllers[0].ObjectMeta.Name)
}
8 changes: 3 additions & 5 deletions pkg/validator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
const exemptionAnnotationKey = "polaris.fairwinds.com/exempt"

// ValidateController validates a single controller, returns a ControllerResult.
func ValidateController(conf *conf.Configuration, controller controller.GenericController, kubeResources *kube.ResourceProvider) (ControllerResult, error) {
func ValidateController(conf *conf.Configuration, controller controller.GenericController) (ControllerResult, error) {
podResult, err := ValidatePod(conf, controller)
if err != nil {
return ControllerResult{}, err
Expand All @@ -46,16 +46,14 @@ func ValidateController(conf *conf.Configuration, controller controller.GenericC
// ValidateControllers validates that each deployment conforms to the Polaris config,
// builds a list of ResourceResults organized by namespace.
func ValidateControllers(config *conf.Configuration, kubeResources *kube.ResourceProvider) ([]ControllerResult, error) {
var controllersToAudit []controller.GenericController
loadedControllers := kubeResources.Controllers
controllersToAudit = append(controllersToAudit, loadedControllers...)
controllersToAudit := kubeResources.Controllers

results := []ControllerResult{}
for _, controller := range controllersToAudit {
if !config.DisallowExemptions && hasExemptionAnnotation(controller) {
continue
}
result, err := ValidateController(config, controller, kubeResources)
result, err := ValidateController(config, controller)
if err != nil {
logrus.Warn("An error occured validating controller:", err)
return nil, err
Expand Down
16 changes: 9 additions & 7 deletions pkg/validator/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestValidateController(t *testing.T) {
"hostPIDSet": {ID: "hostPIDSet", Message: "Host PID is not configured", Success: true, Severity: "error", Category: "Security"},
}

actualResult, err := ValidateController(&c, deployment, &kube.ResourceProvider{})
actualResult, err := ValidateController(&c, deployment)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestSkipHealthChecks(t *testing.T) {
"readinessProbeMissing": {ID: "readinessProbeMissing", Message: "Readiness probe should be configured", Success: false, Severity: "error", Category: "Health Checks"},
"livenessProbeMissing": {ID: "livenessProbeMissing", Message: "Liveness probe should be configured", Success: false, Severity: "warning", Category: "Health Checks"},
}
actualResult, err := ValidateController(&c, deployment, &kube.ResourceProvider{})
actualResult, err := ValidateController(&c, deployment)
if err != nil {
panic(err)
}
Expand All @@ -100,7 +100,7 @@ func TestSkipHealthChecks(t *testing.T) {
Errors: uint(0),
}
expectedResults = ResultSet{}
actualResult, err = ValidateController(&c, job, &kube.ResourceProvider{})
actualResult, err = ValidateController(&c, job)
if err != nil {
panic(err)
}
Expand All @@ -116,7 +116,7 @@ func TestSkipHealthChecks(t *testing.T) {
Errors: uint(0),
}
expectedResults = ResultSet{}
actualResult, err = ValidateController(&c, cronjob, &kube.ResourceProvider{})
actualResult, err = ValidateController(&c, cronjob)
if err != nil {
panic(err)
}
Expand All @@ -136,8 +136,10 @@ func TestControllerExemptions(t *testing.T) {
conf.Deployments,
},
}
newController := test.MockGenericController()
newController.KindString = "Deployment"
resources := &kube.ResourceProvider{
Pods: []corev1.Pod{test.MockNakedPod()},
Controllers: []controller.GenericController{newController},
}

expectedSum := CountSummary{
Expand All @@ -150,10 +152,10 @@ func TestControllerExemptions(t *testing.T) {
panic(err)
}
assert.Equal(t, 1, len(actualResults))
assert.Equal(t, "NakedPod", actualResults[0].Kind)
assert.Equal(t, "Deployment", actualResults[0].Kind)
assert.EqualValues(t, expectedSum, actualResults[0].GetSummary())

resources.Pods[0].ObjectMeta.Annotations = map[string]string{
resources.Controllers[0].ObjectMeta.Annotations = map[string]string{
exemptionAnnotationKey: "true",
}
actualResults, err = ValidateControllers(&c, resources)
Expand Down
3 changes: 3 additions & 0 deletions pkg/validator/controllers/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (g GenericController) GetKind() config.SupportedController {

// GetKindString returns a string representing what kind of object the top level controller is.
func (g GenericController) GetKindString() string {
if g.KindString == "" {
return g.Kind.String()
}
return g.KindString
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/validator/fullaudit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
)

func TestGetTemplateData(t *testing.T) {
k8s := test.SetupTestAPI()
k8s, dynamicClient := test.SetupTestAPI()
k8s = test.SetupAddControllers(k8s, "test")
k8s = test.SetupAddExtraControllerVersions(k8s, "test-extra")
resources, err := kube.CreateResourceProviderFromAPI(k8s, "test", nil)
// TODO figure out how to mock out dynamic client.
// and add in pods for all controllers to fill out tests.
resources, err := kube.CreateResourceProviderFromAPI(k8s, "test", &dynamicClient)
assert.Equal(t, err, nil, "error should be nil")

c := conf.Configuration{
Expand Down Expand Up @@ -48,7 +50,7 @@ func TestGetTemplateData(t *testing.T) {
kind string
results int
}{
{kind: "NakedPod", results: 2},
{kind: "Pod", results: 2},
}

assert.Equal(t, len(expected), len(actualAudit.Results))
Expand Down
10 changes: 5 additions & 5 deletions pkg/validator/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestValidatePod(t *testing.T) {
},
}

k8s := test.SetupTestAPI()
k8s, _ := test.SetupTestAPI()
k8s = test.SetupAddControllers(k8s, "test")
p := test.MockPod()
deployment := controllers.NewDeploymentController(appsv1.Deployment{Spec: appsv1.DeploymentSpec{Template: p}})
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestInvalidIPCPod(t *testing.T) {
},
}

k8s := test.SetupTestAPI()
k8s, _ := test.SetupTestAPI()
k8s = test.SetupAddControllers(k8s, "test")
p := test.MockPod()
p.Spec.HostIPC = true
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestInvalidNeworkPod(t *testing.T) {
},
}

k8s := test.SetupTestAPI()
k8s, _ := test.SetupTestAPI()
k8s = test.SetupAddControllers(k8s, "test")
p := test.MockPod()
p.Spec.HostNetwork = true
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestInvalidPIDPod(t *testing.T) {
},
}

k8s := test.SetupTestAPI()
k8s, _ := test.SetupTestAPI()
k8s = test.SetupAddControllers(k8s, "test")
p := test.MockPod()
p.Spec.HostPID = true
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestExemption(t *testing.T) {
},
}

k8s := test.SetupTestAPI()
k8s, _ := test.SetupTestAPI()
k8s = test.SetupAddControllers(k8s, "test")
p := test.MockPod()
p.Spec.HostIPC = true
Expand Down
4 changes: 1 addition & 3 deletions pkg/validator/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ func applyPodSchemaChecks(conf *config.Configuration, controller controllers.Gen
continue
}
check, err := resolveCheck(conf, checkID, controller, config.TargetPod, false)
if err != nil {
return nil, err
}

if err != nil {
return nil, err
} else if check == nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/webhook/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"net/http"

"github.com/fairwindsops/polaris/pkg/config"
"github.com/fairwindsops/polaris/pkg/kube"
validator "github.com/fairwindsops/polaris/pkg/validator"
"github.com/fairwindsops/polaris/pkg/validator/controllers"

Expand Down Expand Up @@ -143,7 +142,7 @@ func (v *Validator) Handle(ctx context.Context, req types.Request) types.Respons
}
if err == nil {
var controllerResult validator.ControllerResult
controllerResult, err = validator.ValidateController(&v.Config, controller, &kube.ResourceProvider{})
controllerResult, err = validator.ValidateController(&v.Config, controller)
podResult = controllerResult.PodResult
}
}
Expand Down
19 changes: 16 additions & 3 deletions test/fixtures.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package test

import (
"github.com/fairwindsops/polaris/pkg/validator/controllers"
appsv1 "k8s.io/api/apps/v1"
appsv1beta1 "k8s.io/api/apps/v1beta1"
appsv1beta2 "k8s.io/api/apps/v1beta2"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
dynamicFake "k8s.io/client-go/dynamic/fake"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
)
Expand All @@ -32,7 +36,14 @@ func MockPod() corev1.PodTemplateSpec {
return p
}

// MockNakedPod created a pod object.
// MockGenericController creates a generic controller object for testing.
func MockGenericController() controllers.GenericController {
return controllers.GenericController{
PodSpec: MockPod().Spec,
}
}

// MockNakedPod creates a pod object.
func MockNakedPod() corev1.Pod {
return corev1.Pod{
Spec: MockPod().Spec,
Expand Down Expand Up @@ -103,8 +114,10 @@ func MockReplicationController() corev1.ReplicationController {
}

// SetupTestAPI creates a test kube API struct.
func SetupTestAPI() kubernetes.Interface {
return fake.NewSimpleClientset()
func SetupTestAPI() (kubernetes.Interface, dynamic.Interface) {
scheme := runtime.NewScheme()

return fake.NewSimpleClientset(), dynamicFake.NewSimpleDynamicClient(scheme)
}

// SetupAddControllers creates mock controllers and adds them to the test clientset.
Expand Down

0 comments on commit a5828a2

Please sign in to comment.