More nil checking/precautions and update test name

Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
This commit is contained in:
JoshVanL 2019-06-11 16:38:10 +01:00
parent e9c9ea2a44
commit f526fbee91
2 changed files with 12 additions and 2 deletions

View File

@ -142,7 +142,9 @@ func (s *Solver) buildPod(ch *v1alpha1.Challenge) *corev1.Pod {
pod := s.buildDefaultPod(ch)
// Override defaults if they have changed in the pod template.
if ch.Spec.Solver != nil {
if ch.Spec.Solver != nil &&
ch.Spec.Solver.HTTP01 != nil &&
ch.Spec.Solver.HTTP01.Ingress != nil {
pod = s.mergePodObjectMetaWithPodTemplate(pod,
ch.Spec.Solver.HTTP01.Ingress.PodTemplate)
}
@ -206,10 +208,18 @@ func (s *Solver) mergePodObjectMetaWithPodTemplate(pod *corev1.Pod, podTempl *v1
return pod
}
if pod.Labels == nil {
pod.Labels = make(map[string]string)
}
for k, v := range podTempl.Labels {
pod.Labels[k] = v
}
if pod.Annotations == nil {
pod.Annotations = make(map[string]string)
}
for k, v := range podTempl.Annotations {
pod.Annotations[k] = v
}

View File

@ -257,7 +257,7 @@ func TestGetPodsForCertificate(t *testing.T) {
func TestMergePodObjectMetaWithPodTemplate(t *testing.T) {
const createdPodKey = "createdPod"
tests := map[string]solverFixture{
"should use labels and owner references from template": {
"should use labels and annotations from template": {
Challenge: &v1alpha1.Challenge{
Spec: v1alpha1.ChallengeSpec{
DNSName: "example.com",