kubeeye/pkg/validator/pod.go

55 lines
1.3 KiB
Go
Raw Normal View History

package validator
import (
"context"
2020-11-25 10:20:55 +08:00
"github.com/pkg/errors"
"kubeye/pkg/config"
"kubeye/pkg/kube"
"time"
)
func ValidatePods(ctx context.Context, conf *config.Configuration, kubeResource *kube.ResourceProvider) ([]PodResult, error) {
podToAudit := kubeResource.Controllers
results := []PodResult{}
2020-11-25 10:20:55 +08:00
for _, pod := range podToAudit {
result, err := ValidatePod(ctx, conf, pod)
2020-11-25 10:20:55 +08:00
if err != nil {
return nil, errors.Wrap(err, "Failed to get result")
}
2020-11-25 10:20:55 +08:00
if len(result.ContainerResults[0].Results) == 0 || result.ContainerResults == nil {
continue
}
results = append(results, result)
}
return results, nil
}
func ValidatePod(ctx context.Context, c *config.Configuration, pod kube.GenericWorkload) (PodResult, error) {
_, err := applyPodSchemaChecks(c, pod)
if err != nil {
return PodResult{}, err
}
pRes := PodResult{
//Results: podResults,
ContainerResults: []ContainerResult{},
}
pRes.ContainerResults, err = ValidateAllContainers(ctx, c, pod)
if err != nil {
return pRes, err
}
result := PodResult{
2020-11-25 10:20:55 +08:00
CreatedTime: time.Now().Format(time.RFC3339),
Kind: pod.Kind,
Name: pod.ObjectMeta.GetName(),
Namespace: pod.ObjectMeta.GetNamespace(),
ContainerResults: pRes.ContainerResults,
}
return result, nil
}