@@ -7,16 +7,12 @@ import (
77 "os"
88 "reflect"
99 "strings"
10- "unsafe"
1110
1211 appsv1 "k8s.io/api/apps/v1"
1312 corev1 "k8s.io/api/core/v1"
1413 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15- metav1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
1614 "k8s.io/apimachinery/pkg/types"
1715 "k8s.io/apimachinery/pkg/util/validation/field"
18- "k8s.io/kubernetes/pkg/apis/core"
19- corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
2016 "sigs.k8s.io/controller-runtime/pkg/client"
2117
2218 certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
@@ -188,7 +184,7 @@ func updateResourceRequirement(deployment *appsv1.Deployment, istiocsr *v1alpha1
188184 if reflect .ValueOf (istiocsr .Spec .IstioCSRConfig .Resources ).IsZero () {
189185 return nil
190186 }
191- if err := validateResourceRequirements (istiocsr .Spec .IstioCSRConfig .Resources ,
187+ if err := common . ValidateResourceRequirements (istiocsr .Spec .IstioCSRConfig .Resources ,
192188 field .NewPath ("spec" , "istioCSRConfig" )); err != nil {
193189 return err
194190 }
@@ -202,7 +198,7 @@ func updateAffinityRules(deployment *appsv1.Deployment, istiocsr *v1alpha1.Istio
202198 if istiocsr .Spec .IstioCSRConfig .Affinity == nil {
203199 return nil
204200 }
205- if err := validateAffinityRules (istiocsr .Spec .IstioCSRConfig .Affinity ,
201+ if err := common . ValidateAffinityRules (istiocsr .Spec .IstioCSRConfig .Affinity ,
206202 field .NewPath ("spec" , "istioCSRConfig" )); err != nil {
207203 return err
208204 }
@@ -214,7 +210,7 @@ func updatePodTolerations(deployment *appsv1.Deployment, istiocsr *v1alpha1.Isti
214210 if istiocsr .Spec .IstioCSRConfig .Tolerations == nil {
215211 return nil
216212 }
217- if err := validateTolerationsConfig (istiocsr .Spec .IstioCSRConfig .Tolerations ,
213+ if err := common . ValidateTolerationsConfig (istiocsr .Spec .IstioCSRConfig .Tolerations ,
218214 field .NewPath ("spec" , "istioCSRConfig" )); err != nil {
219215 return err
220216 }
@@ -226,7 +222,7 @@ func updateNodeSelector(deployment *appsv1.Deployment, istiocsr *v1alpha1.IstioC
226222 if istiocsr .Spec .IstioCSRConfig .NodeSelector == nil {
227223 return nil
228224 }
229- if err := validateNodeSelectorConfig (istiocsr .Spec .IstioCSRConfig .NodeSelector ,
225+ if err := common . ValidateNodeSelectorConfig (istiocsr .Spec .IstioCSRConfig .NodeSelector ,
230226 field .NewPath ("spec" , "istioCSRConfig" )); err != nil {
231227 return err
232228 }
@@ -269,6 +265,10 @@ func (r *Reconciler) assertIssuerRefExists(istiocsr *v1alpha1.IstioCSR) error {
269265 return common .NewIrrecoverableError (errInvalidIssuerRefConfig , "spec.istioCSRConfig.certManager.issuerRef uses unsupported ACME issuer" )
270266 }
271267
268+ if err := r .updateWatchLabel (obj , istiocsr ); err != nil {
269+ return common .FromClientError (err , "failed to update watch label on cert-manager issuer %s" , istiocsr .Spec .IstioCSRConfig .CertManager .IssuerRef .Name )
270+ }
271+
272272 return nil
273273}
274274
@@ -641,26 +641,3 @@ func (r *Reconciler) updateWatchLabel(obj client.Object, istiocsr *v1alpha1.Isti
641641 }
642642 return nil
643643}
644-
645- // validateNodeSelectorConfig validates the NodeSelector configuration.
646- func validateNodeSelectorConfig (nodeSelector map [string ]string , fldPath * field.Path ) error {
647- return metav1validation .ValidateLabels (nodeSelector , fldPath .Child ("nodeSelector" )).ToAggregate ()
648- }
649-
650- func validateTolerationsConfig (tolerations []corev1.Toleration , fldPath * field.Path ) error {
651- // convert corev1.Tolerations to core.Tolerations, required for validation.
652- convTolerations := * (* []core.Toleration )(unsafe .Pointer (& tolerations ))
653- return corevalidation .ValidateTolerations (convTolerations , fldPath .Child ("tolerations" )).ToAggregate ()
654- }
655-
656- func validateResourceRequirements (requirements corev1.ResourceRequirements , fldPath * field.Path ) error {
657- // convert corev1.ResourceRequirements to core.ResourceRequirements, required for validation.
658- convRequirements := * (* core .ResourceRequirements )(unsafe .Pointer (& requirements ))
659- return corevalidation .ValidateContainerResourceRequirements (& convRequirements , nil , fldPath .Child ("resources" ), corevalidation.PodValidationOptions {}).ToAggregate ()
660- }
661-
662- func validateAffinityRules (affinity * corev1.Affinity , fldPath * field.Path ) error {
663- // convert corev1.Affinity to core.Affinity, required for validation.
664- convAffinity := (* core .Affinity )(unsafe .Pointer (affinity ))
665- return validateAffinity (convAffinity , corevalidation.PodValidationOptions {}, fldPath .Child ("affinity" )).ToAggregate ()
666- }
0 commit comments