first functional test

This commit is contained in:
2023-03-18 12:20:10 -05:00
parent 9dd4366e73
commit 3f60d34155
6 changed files with 98 additions and 33 deletions

View File

@@ -1,5 +1,30 @@
package operations
import (
"strings"
admission "k8s.io/api/admission/v1"
)
func PodsValidation() Hook {
return Hook{}
return Hook{
Create: podValidationCreate(),
}
}
func podValidationCreate() AdmitFunc {
return func(r *admission.AdmissionRequest) (*Result, error) {
pod, err := parsePod(r.Object.Raw)
if err != nil {
return &Result{Msg: err.Error()}, nil
}
for _, c := range pod.Spec.Containers {
if strings.HasSuffix(c.Image, ":latest") {
return &Result{Msg: "You cannot use the tag 'latest' in a container."}, nil
}
}
return &Result{Allowed: true}, nil
}
}