Add arbitrary validation to fullaudit

This commit is contained in:
Jordan Doig
2021-02-23 14:30:24 -07:00
committed by Robert Brennan
parent 560425cf72
commit 026a016b64
4 changed files with 20 additions and 8 deletions

View File

@@ -370,6 +370,9 @@ func addResourceFromString(contents string, resources *ResourceProvider) error {
} else if resource.Kind == "Ingress" {
ingress := v1beta1.Ingress{}
err = decoder.Decode(&ingress)
if err != nil {
return err
}
resources.Ingresses = append(resources.Ingresses, ingress)
} else {
newController, err := GetWorkloadFromBytes(contentBytes)
@@ -377,7 +380,12 @@ func addResourceFromString(contents string, resources *ResourceProvider) error {
return err
}
if newController == nil {
// Handle Arbitrary Kinds Here
unst := unstructured.Unstructured{}
err = decoder.Decode(&unst)
if err != nil {
return err
}
resources.ArbitraryKinds = append(resources.ArbitraryKinds, &unst)
} else {
resources.Controllers = append(resources.Controllers, *newController)
}

View File

@@ -111,7 +111,7 @@ func TestControllerLevelChecks(t *testing.T) {
two := int32(2)
d2.Spec.Replicas = &two
k8s, dynamicClient := test.SetupTestAPI(&d1, &p1, &d2, &p2)
res, err = kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient)
res, err = kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient, conf.Configuration{})
assert.Equal(t, err, nil, "error should be nil")
assert.Equal(t, 2, len(res.Controllers), "Should have two controllers")
testResources(res)

View File

@@ -34,7 +34,11 @@ func RunAudit(config conf.Configuration, kubeResources *kube.ResourceProvider, o
}
results = append(results, ingressResults...)
// Call Arbitrary Kind Validation here
arbitraryResults, err := ValidateArbitraryKinds(&config, kubeResources)
if err != nil {
return AuditData{}, err
}
results = append(results, arbitraryResults...)
auditData := AuditData{
PolarisOutputVersion: PolarisOutputVersion,

View File

@@ -11,11 +11,6 @@ import (
)
func TestGetTemplateData(t *testing.T) {
k8s, dynamicClient := test.SetupTestAPI(test.GetMockControllers("test")...)
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))
c := conf.Configuration{
Checks: map[string]conf.Severity{
"readinessProbeMissing": conf.SeverityDanger,
@@ -23,6 +18,11 @@ func TestGetTemplateData(t *testing.T) {
},
}
k8s, dynamicClient := test.SetupTestAPI(test.GetMockControllers("test")...)
resources, err := kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicClient, c)
assert.Equal(t, err, nil, "error should be nil")
assert.Equal(t, 5, len(resources.Controllers))
sum := CountSummary{
Successes: uint(0),
Warnings: uint(3),