ensure ClusterIssuer is as expected
@@ -201,16 +201,8 @@ func (r *HttpsCertIssuerReconciler) ReconcileACMECloudFlare(ctx context.Context,
r.Log.Info("secret created")
}
- // todo update
-
// ref: https://cert-manager.io/docs/configuration/acme/dns01/cloudflare/
- clusterIssuer := cmv1alpha2.ClusterIssuer{}
- if err := r.Get(ctx, client.ObjectKey{Name: issuer.Name}, &clusterIssuer); err != nil {
- if !errors.IsNotFound(err) {
- return ctrl.Result{}, err
- }
-
- clusterIssuer := cmv1alpha2.ClusterIssuer{
+ expectedClusterIssuer := cmv1alpha2.ClusterIssuer{
ObjectMeta: v1.ObjectMeta{
Name: issuer.Name,
},
@@ -245,6 +237,18 @@ func (r *HttpsCertIssuerReconciler) ReconcileACMECloudFlare(ctx context.Context,
},
}
+ clusterIssuer := cmv1alpha2.ClusterIssuer{}
+ var isNew bool
+ if err := r.Get(ctx, client.ObjectKey{Name: issuer.Name}, &clusterIssuer); err != nil {
+ if !errors.IsNotFound(err) {
+ return ctrl.Result{}, err
+ }
+
+ clusterIssuer = expectedClusterIssuer
+ isNew = true
+ }
+
+ if isNew {
if err := ctrl.SetControllerReference(&issuer, &clusterIssuer, r.Scheme); err != nil {
return ctrl.Result{}, err
}
@@ -254,6 +258,13 @@ func (r *HttpsCertIssuerReconciler) ReconcileACMECloudFlare(ctx context.Context,
r.Log.Error(err, "fail create clusterIssuer")
return ctrl.Result{}, err
}
+ } else {
+ clusterIssuer.Spec = expectedClusterIssuer.Spec
+
+ if err := r.Update(ctx, &clusterIssuer); err != nil {
+ r.Log.Error(err, "fail update clusterIssuer")
+ return ctrl.Result{}, err
+ }
}
return ctrl.Result{}, nil
