Skip to content

Commit

Permalink
less failure on unexpected reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed Jul 16, 2020
1 parent 432354d commit dd74ab7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions amp.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func (a *Api) mutatePod(ar admissionv1.AdmissionReview) *admissionv1.AdmissionRe
zap.String("annotation", a.EpAnnotation),
}

reviewResponse := admissionv1.AdmissionResponse{}
// always allow (amp is only for pod mutation)
reviewResponse.Allowed = true

podResource := metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
if ar.Request.Resource != podResource {
a.Log.Error("unexpected resource",
Expand All @@ -157,7 +161,7 @@ func (a *Api) mutatePod(ar admissionv1.AdmissionReview) *admissionv1.AdmissionRe
pod := corev1.Pod{}
deserializer := codecs.UniversalDeserializer()
if _, _, err := deserializer.Decode(raw, nil, &pod); err != nil {
a.Log.Warn("deserializer failure", zap.Error(err))
a.Log.Error("deserializer failure", zap.Error(err))
return &reviewResponse
}
logInfo = append(logInfo, zap.String("Pod", pod.Name))
Expand All @@ -170,13 +174,10 @@ func (a *Api) mutatePod(ar admissionv1.AdmissionReview) *admissionv1.AdmissionRe
)...,
)

reviewResponse := admissionv1.AdmissionResponse{}
// always allow (amp is only for pod mutation)
reviewResponse.Allowed = true

ns, err := a.Cs.CoreV1().Namespaces().Get(pod.Namespace, metav1.GetOptions{})
if err != nil {
a.Log.Warn("unable to get namespace",
a.Log.Error("unable to get namespace",
append(logInfo, zap.Error(err))...,
)
return &reviewResponse
Expand Down

0 comments on commit dd74ab7

Please sign in to comment.