mirror of
https://github.com/FairwindsOps/polaris.git
synced 2026-05-10 19:26:46 +00:00
Add arbitrary validation to fullaudit
This commit is contained in:
committed by
Robert Brennan
parent
560425cf72
commit
026a016b64
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user