Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tenant flow for ai subscription ratelimit policy #1212

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions apim-apk-agent/internal/k8sClient/k8s_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"crypto/sha1"
"encoding/hex"
"fmt"
"strings"

dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1"
Expand Down Expand Up @@ -453,9 +454,10 @@ func UpdateRateLimitPolicyCR(policy eventhubTypes.RateLimitPolicy, k8sClient cli
func DeploySubscriptionRateLimitPolicyCR(policy eventhubTypes.SubscriptionPolicy, k8sClient client.Client) {
conf, _ := config.ReadConfigs()
crRateLimitPolicy := dpv1alpha3.RateLimitPolicy{}
if err := k8sClient.Get(context.Background(), client.ObjectKey{Namespace: conf.DataPlane.Namespace, Name: policy.Name}, &crRateLimitPolicy); err != nil {
if err := k8sClient.Get(context.Background(), client.ObjectKey{Namespace: conf.DataPlane.Namespace, Name: getSha1Value(fmt.Sprintf("%s-%s",policy.Name, policy.TenantDomain))}, &crRateLimitPolicy); err != nil {
crRateLimitPolicy = dpv1alpha3.RateLimitPolicy{
ObjectMeta: metav1.ObjectMeta{Name: getSha1Value(policy.Name),
ObjectMeta: metav1.ObjectMeta{
Name: getSha1Value(fmt.Sprintf("%s-%s",policy.Name, policy.TenantDomain)),
Namespace: conf.DataPlane.Namespace,
},
Spec: dpv1alpha3.RateLimitPolicySpec{
Expand Down Expand Up @@ -519,7 +521,7 @@ func DeployAIRateLimitPolicyFromCPPolicy(policy eventhubTypes.SubscriptionPolicy

crRateLimitPolicies := dpv1alpha3.AIRateLimitPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: getSha1Value(policy.Name),
Name: getSha1Value(fmt.Sprintf("%s-%s",policy.Name, policy.TenantDomain)),
Namespace: conf.DataPlane.Namespace,
},
Spec: dpv1alpha3.AIRateLimitPolicySpec{
Expand Down
4 changes: 2 additions & 2 deletions apim-apk-agent/internal/messaging/notification_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ func handlePolicyEvents(data []byte, eventType string, c client.Client) {
} else if strings.EqualFold(policyEvent.PolicyType, "SUBSCRIPTION") {
logger.LoggerMessaging.Infof("Policy: %s for policy type: %s", policyEvent.PolicyName, policyEvent.PolicyType)
managementserver.DeleteSubscriptionPolicy(policyEvent.PolicyName, policyEvent.TenantDomain)
k8sclient.UnDeploySubscriptionRateLimitPolicyCR(policyEvent.PolicyName, c)
k8sclient.UndeploySubscriptionAIRateLimitPolicyCR(policyEvent.PolicyName, c)
k8sclient.UnDeploySubscriptionRateLimitPolicyCR(fmt.Sprintf("%s-%s", policyEvent.PolicyName, policyEvent.TenantDomain), c)
k8sclient.UndeploySubscriptionAIRateLimitPolicyCR(fmt.Sprintf("%s-%s", policyEvent.PolicyName, policyEvent.TenantDomain), c)
ratelimitPolicies := managementserver.GetAllRateLimitPolicies()
logger.LoggerMessaging.Infof("Rate Limit Policies Internal Map: %v", ratelimitPolicies)
}
Expand Down
Loading