@@ -102,6 +102,7 @@ public class DeployerClient {
102
102
_ = check self .deleteScopeCrsForAPI (existingAPI , < string > apiArtifact? .organization );
103
103
check self .deleteBackends (existingAPI , < string > apiArtifact? .organization );
104
104
check self .deleteRateLimitPolicyCRs (existingAPI , < string > apiArtifact? .organization );
105
+ check self .deleteAIRateLimitPolicyCRs (existingAPI , < string > apiArtifact? .organization );
105
106
check self .deleteAPIPolicyCRs (existingAPI , < string > apiArtifact? .organization );
106
107
check self .deleteInterceptorServiceCRs (existingAPI , < string > apiArtifact? .organization );
107
108
check self .deleteBackendJWTConfig (existingAPI , < string > apiArtifact? .organization );
@@ -121,6 +122,7 @@ public class DeployerClient {
121
122
check self .deployBackendServices (apiArtifact , ownerReference );
122
123
check self .deployAuthenticationCRs (apiArtifact , ownerReference );
123
124
check self .deployRateLimitPolicyCRs (apiArtifact , ownerReference );
125
+ check self .deployAIRateLimitPolicyCRs (apiArtifact , ownerReference );
124
126
check self .deployInterceptorServiceCRs (apiArtifact , ownerReference );
125
127
check self .deployBackendJWTConfigs (apiArtifact , ownerReference );
126
128
check self .deployAPIPolicyCRs (apiArtifact , ownerReference );
@@ -660,6 +662,30 @@ public class DeployerClient {
660
662
}
661
663
}
662
664
665
+ private isolated function deployAIRateLimitPolicyCRs(model : APIArtifact apiArtifact , model : OwnerReference ownerReference ) returns error ? {
666
+ foreach model : AIRateLimitPolicy rateLimitPolicy in apiArtifact .aiRatelimitPolicies {
667
+ rateLimitPolicy .metadata .ownerReferences = [ownerReference ];
668
+ http : Response deployRateLimitPolicyResult = check deployAIRateLimitPolicyCR (rateLimitPolicy , < string > apiArtifact? .namespace );
669
+ if deployRateLimitPolicyResult .statusCode == http : STATUS_CREATED {
670
+ log : printDebug (" Deployed AIRateLimitPolicy Successfully" + rateLimitPolicy .toString ());
671
+ } else if deployRateLimitPolicyResult .statusCode == http : STATUS_CONFLICT {
672
+ log : printDebug (" AIRateLimitPolicy already exists" + rateLimitPolicy .toString ());
673
+ model : AIRateLimitPolicy rateLimitPolicyFromK8s = check getAIRateLimitPolicyCR (rateLimitPolicy .metadata .name , < string > apiArtifact? .namespace );
674
+ rateLimitPolicy .metadata .resourceVersion = rateLimitPolicyFromK8s .metadata .resourceVersion ;
675
+ http : Response rateLimitPolicyCR = check updateAIRateLimitPolicyCR (rateLimitPolicy , < string > apiArtifact? .namespace );
676
+ if rateLimitPolicyCR .statusCode != http : STATUS_OK {
677
+ json responsePayLoad = check rateLimitPolicyCR .getJsonPayload ();
678
+ model : Status statusResponse = check responsePayLoad .cloneWithType (model : Status );
679
+ check self .handleK8sTimeout (statusResponse );
680
+ }
681
+ } else {
682
+ json responsePayLoad = check deployRateLimitPolicyResult .getJsonPayload ();
683
+ model : Status statusResponse = check responsePayLoad .cloneWithType (model : Status );
684
+ check self .handleK8sTimeout (statusResponse );
685
+ }
686
+ }
687
+ }
688
+
663
689
private isolated function deleteRateLimitPolicyCRs(model : API api , string organization ) returns commons : APKError ? {
664
690
do {
665
691
model : RateLimitPolicyList | http :ClientError rateLimitPolicyCrListResponse = check getRateLimitPolicyCRsForAPI (api .spec .apiName , api .spec .apiVersion , < string > api .metadata ?.namespace , organization );
@@ -684,6 +710,29 @@ public class DeployerClient {
684
710
}
685
711
}
686
712
713
+ private isolated function deleteAIRateLimitPolicyCRs(model : API api , string organization ) returns commons : APKError ? {
714
+ do {
715
+ model : AIRateLimitPolicyList | http :ClientError aiRateLimitPolicyCrListResponse = check getAIRateLimitPolicyCRsForAPI (api .spec .apiName , api .spec .apiVersion , < string > api .metadata ?.namespace , organization );
716
+ if aiRateLimitPolicyCrListResponse is model : AIRateLimitPolicyList {
717
+ foreach model : AIRateLimitPolicy item in aiRateLimitPolicyCrListResponse .items {
718
+ http : Response | http :ClientError rateLimitPolicyCRDeletionResponse = deleteAIRateLimitPolicyCR (item .metadata .name , < string > item .metadata ?.namespace );
719
+ if rateLimitPolicyCRDeletionResponse is http : Response {
720
+ if rateLimitPolicyCRDeletionResponse .statusCode != http : STATUS_OK {
721
+ json responsePayLoad = check rateLimitPolicyCRDeletionResponse .getJsonPayload ();
722
+ model : Status statusResponse = check responsePayLoad .cloneWithType (model : Status );
723
+ check self .handleK8sTimeout (statusResponse );
724
+ }
725
+ } else {
726
+ log : printError (" Error occured while deleting AI rate limit policy" );
727
+ }
728
+ }
729
+ return ;
730
+ }
731
+ } on fail var e {
732
+ log : printError (" Error occured deleting AI rate limit policy" , e );
733
+ return e909022 (" Error occured deleting AI rate limit policy" , e );
734
+ }
735
+ }
687
736
private isolated function deleteAPIPolicyCRs(model : API api , string organization ) returns commons : APKError ? {
688
737
do {
689
738
model : APIPolicyList | http :ClientError apiPolicyCrListResponse = check getAPIPolicyCRsForAPI (api .spec .apiName , api .spec .apiVersion , < string > api .metadata ?.namespace , organization );
0 commit comments