@@ -106,6 +106,7 @@ func (r *CdnTenantReconciler) setReconcilingConditionRequeue(ctx context.Context
106106// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch;create;update;patch;delete
107107// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
108108// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete
109+ // +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
109110
110111// Reconcile is part of the main kubernetes reconciliation loop which aims to
111112// move the current state of the cluster closer to the desired state.
@@ -400,6 +401,11 @@ func (r *CdnTenantReconciler) syncSecondaries(req ctrl.Request, ctx context.Cont
400401 return hasUpdates , 0 , err
401402 }
402403 } else {
404+ primaryKeyBytes , ok := secret .Data ["primaryKey" ]
405+ if ! ok {
406+ primaryKeyBytes = []byte ("" )
407+ }
408+ primaryKey := string (primaryKeyBytes )
403409 secondariesJSON , ok := secret .Data ["secondaries.json" ]
404410 if ! ok {
405411 return hasUpdates , 0 , nil
@@ -428,7 +434,7 @@ func (r *CdnTenantReconciler) syncSecondaries(req ctrl.Request, ctx context.Cont
428434 tenant .Annotations [fmt .Sprintf ("%s-%s-status" , secondariesAnnotationKey , name )] = "syncing"
429435 updateTenantAnnotations = true
430436 }
431- requeue , err := r .syncSecondary (ctx , tenant , name , secondaryConfig )
437+ requeue , err := r .syncSecondary (ctx , tenant , name , secondaryConfig , primaryKey )
432438 if err != nil {
433439 return hasUpdates , 0 , err
434440 }
@@ -484,21 +490,34 @@ func (r *CdnTenantReconciler) syncSecondaries(req ctrl.Request, ctx context.Cont
484490 }
485491}
486492
487- func (r * CdnTenantReconciler ) syncSecondary (ctx context.Context , tenant * cdnv1.CdnTenant , name string , config map [string ]string ) (bool , error ) {
493+ func (r * CdnTenantReconciler ) syncSecondary (ctx context.Context , tenant * cdnv1.CdnTenant , name string , config map [string ]string , primaryKey string ) (bool , error ) {
488494 action := "delete"
489495 var body io.Reader
490496 if tenant .DeletionTimestamp .IsZero () {
491497 action = "apply"
498+ m := make (map [string ]interface {})
492499 b , err := json .Marshal (tenant .Spec )
493500 if err != nil {
494501 return false , err
495502 }
503+ if err := json .Unmarshal (b , & m ); err != nil {
504+ return false , err
505+ }
506+ m ["primaryKey" ] = primaryKey
507+ b , err = json .Marshal (m )
508+ if err != nil {
509+ return false , err
510+ }
496511 body = bytes .NewReader (b )
497512 }
513+ url := fmt .Sprintf ("%s/%s?cdn_tenant_name=%s" , config ["url" ], action , tenant .Name )
514+ if action == "delete" {
515+ url += "&primary_key=" + primaryKey
516+ }
498517 req , err := http .NewRequestWithContext (
499518 ctx ,
500519 http .MethodPost ,
501- fmt . Sprintf ( "%s/%s?cdn_tenant_name=%s" , config [ " url" ], action , tenant . Name ) ,
520+ url ,
502521 body ,
503522 )
504523 if err != nil {
0 commit comments