@@ -624,63 +624,73 @@ pub async fn reconcile_compute(
624624 . and_then ( |s| s. service_account_annotations . as_ref ( ) )
625625 . and_then ( |a| a. get ( "iam.gke.io/gcp-service-account" ) ) ;
626626
627- if let Some ( gcp_sa_email) = gcp_sa_email {
628- let gcp_project = match parse_gcp_project_from_sa_email ( gcp_sa_email) {
629- Some ( project) => project,
630- None => {
631- return Err ( Error :: InvalidRestateConfig ( format ! (
632- "Cannot parse GCP project from service account email '{gcp_sa_email}'; expected format: name@PROJECT.iam.gserviceaccount.com"
633- ) ) ) ;
634- }
635- } ;
636-
637- let ipm = match apply_iam_policy_member (
638- name,
639- & ipm_api,
640- restate_iam_policy_member ( name, base_metadata, gcp_project, gcp_sa_email) ,
641- )
642- . await
643- {
644- Ok ( ipm) => ipm,
645- Err ( Error :: KubeError ( kube:: Error :: Api ( kube:: error:: ErrorResponse {
646- code : 404 ,
647- ..
648- } ) ) ) => {
627+ match ( ctx. gcp_workload_identity , gcp_sa_email) {
628+ ( true , Some ( gcp_sa_email) ) => {
629+ let gcp_project = match parse_gcp_project_from_sa_email ( gcp_sa_email) {
630+ Some ( project) => project,
631+ None => {
632+ return Err ( Error :: InvalidRestateConfig ( format ! (
633+ "Cannot parse GCP project from service account email '{gcp_sa_email}'; expected format: name@PROJECT.iam.gserviceaccount.com"
634+ ) ) ) ;
635+ }
636+ } ;
637+
638+ let ipm = match apply_iam_policy_member (
639+ name,
640+ & ipm_api,
641+ restate_iam_policy_member ( name, base_metadata, gcp_project, gcp_sa_email) ,
642+ )
643+ . await
644+ {
645+ Ok ( ipm) => ipm,
646+ Err ( Error :: KubeError ( kube:: Error :: Api ( kube:: error:: ErrorResponse {
647+ code : 404 ,
648+ ..
649+ } ) ) ) => {
650+ return Err ( Error :: NotReady {
651+ reason : "IAMPolicyMemberCRDNotFound" . into ( ) ,
652+ message : "IAMPolicyMember CRD not found - is Config Connector installed?"
653+ . into ( ) ,
654+ requeue_after : Some ( Duration :: from_secs ( 60 ) ) ,
655+ } ) ;
656+ }
657+ Err ( err) => return Err ( err) ,
658+ } ;
659+
660+ if !is_iam_policy_member_ready ( & ipm) {
649661 return Err ( Error :: NotReady {
650- reason : "IAMPolicyMemberCRDNotFound" . into ( ) ,
651- message : "IAMPolicyMember CRD not found - is Config Connector installed?"
652- . into ( ) ,
653- requeue_after : Some ( Duration :: from_secs ( 60 ) ) ,
662+ reason : "IAMPolicyMemberNotReady" . into ( ) ,
663+ message :
664+ "Waiting for Config Connector to provision the IAM policy member binding"
665+ . into ( ) ,
666+ requeue_after : None ,
654667 } ) ;
655668 }
656- Err ( err) => return Err ( err) ,
657- } ;
658669
659- if !is_iam_policy_member_ready ( & ipm) {
660- return Err ( Error :: NotReady {
661- reason : "IAMPolicyMemberNotReady" . into ( ) ,
662- message : "Waiting for Config Connector to provision the IAM policy member binding"
663- . into ( ) ,
664- requeue_after : None ,
665- } ) ;
666- }
667-
668- check_workload_identity (
669- name,
670- base_metadata,
671- spec. compute . tolerations . as_ref ( ) ,
672- & job_api,
673- )
674- . await ?;
670+ check_workload_identity (
671+ name,
672+ base_metadata,
673+ spec. compute . tolerations . as_ref ( ) ,
674+ & job_api,
675+ )
676+ . await ?;
675677
676- let pod_annotations = pod_annotations. get_or_insert_with ( Default :: default) ;
677- pod_annotations. insert (
678- "restate.dev/gcp-service-account" . into ( ) ,
679- gcp_sa_email. to_owned ( ) ,
680- ) ;
681- } else {
682- delete_iam_policy_member ( name, & ipm_api, "restate-workload-identity" ) . await ?;
683- delete_job ( name, & job_api, "restate-wi-canary" ) . await ?;
678+ let pod_annotations = pod_annotations. get_or_insert_with ( Default :: default) ;
679+ pod_annotations. insert (
680+ "restate.dev/gcp-service-account" . into ( ) ,
681+ gcp_sa_email. to_owned ( ) ,
682+ ) ;
683+ }
684+ ( true , None ) => {
685+ delete_iam_policy_member ( name, & ipm_api, "restate-workload-identity" ) . await ?;
686+ delete_job ( name, & job_api, "restate-wi-canary" ) . await ?;
687+ }
688+ ( false , Some ( gcp_sa_email) ) => {
689+ warn ! (
690+ "Ignoring iam.gke.io/gcp-service-account annotation {gcp_sa_email} as the operator is not configured with --gcp-workload-identity"
691+ ) ;
692+ }
693+ ( false , None ) => { }
684694 }
685695
686696 let restate_service = restate_service (
0 commit comments