Skip to content

Commit

Permalink
Update API version in cc
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Aug 23, 2024
1 parent 4cd52d1 commit 659b1b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
"github.com/wso2/apk/common-controller/internal/utils"
xds "github.com/wso2/apk/common-controller/internal/xds"
dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1"
dpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha2"
dpv1beta1 "github.com/wso2/apk/common-go-libs/apis/dp/v1beta1"
"github.com/wso2/apk/common-go-libs/constants"
)

Expand Down Expand Up @@ -87,7 +87,7 @@ func NewratelimitController(mgr manager.Manager, ratelimitStore *cache.Ratelimit
conf := config.ReadConfigs()
predicates := []predicate.Predicate{predicate.NewPredicateFuncs(utils.FilterByNamespaces(conf.CommonController.Operator.Namespaces))}

if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1alpha2.API{}),
if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1beta1.API{}),
handler.EnqueueRequestsFromMapFunc(ratelimitReconsiler.getRatelimitForAPI), predicates...); err != nil {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2611, logging.BLOCKER,
"Error watching API resources: %v", err))
Expand Down Expand Up @@ -177,7 +177,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) Reconcile(ctx context.Cont
}

func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForAPI(ctx context.Context, obj k8client.Object) []reconcile.Request {
api, ok := obj.(*dpv1alpha2.API)
api, ok := obj.(*dpv1beta1.API)
if !ok {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2622, logging.TRIVIAL,
"Unexpected object type, bypassing reconciliation: %v", api))
Expand Down Expand Up @@ -242,13 +242,13 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) getRatelimitForHTTPRoute(c
return requests
}

func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx context.Context, ratelimitKey types.NamespacedName,
func (ratelimitReconciler *RateLimitPolicyReconciler) marshelRateLimit(ctx context.Context, ratelimitKey types.NamespacedName,
ratelimitPolicy dpv1alpha1.RateLimitPolicy) ([]dpv1alpha1.ResolveRateLimitAPIPolicy, error) {

policyList := []dpv1alpha1.ResolveRateLimitAPIPolicy{}
var api dpv1alpha2.API
var api dpv1beta1.API

if err := ratelimitReconsiler.client.Get(ctx, types.NamespacedName{
if err := ratelimitReconciler.client.Get(ctx, types.NamespacedName{
Namespace: ratelimitKey.Namespace,
Name: string(ratelimitPolicy.Spec.TargetRef.Name)},
&api); err != nil {
Expand Down Expand Up @@ -288,7 +288,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte
resolveRatelimit.Environment = environment

if len(api.Spec.Production) > 0 && api.Spec.APIType == "REST" {
resolveResourceList, err := ratelimitReconsiler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy,
resolveResourceList, err := ratelimitReconciler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy,
api.Spec.Production[0].RouteRefs)
if err != nil {
return nil, err
Expand All @@ -300,7 +300,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte
}

if len(api.Spec.Sandbox) > 0 && api.Spec.APIType == "REST" {
resolveResourceList, err := ratelimitReconsiler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy,
resolveResourceList, err := ratelimitReconciler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy,
api.Spec.Sandbox[0].RouteRefs)
if err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions common-controller/internal/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
cpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/cp/v1alpha2"
dpv1alpha1 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha1"
dpv1alpha2 "github.com/wso2/apk/common-go-libs/apis/dp/v1alpha2"
dpv1beta1 "github.com/wso2/apk/common-go-libs/apis/dp/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -63,6 +64,7 @@ func init() {
utilruntime.Must(dpv1alpha2.AddToScheme(scheme))
utilruntime.Must(cpv1alpha2.AddToScheme(scheme))
utilruntime.Must(cpv1alpha2.AddToScheme(scheme))
utilruntime.Must(dpv1beta1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down Expand Up @@ -132,6 +134,11 @@ func InitOperator(metricsConfig config.Metrics) {
"Unable to create webhook API, error: %v", err))
}

if err = (&dpv1beta1.API{}).SetupWebhookWithManager(mgr); err != nil {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2601, logging.MAJOR,
"Unable to create webhook API, error: %v", err))
}

if err = (&dpv1alpha1.RateLimitPolicy{}).SetupWebhookWithManager(mgr); err != nil {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2637, logging.MAJOR,
"Unable to create webhook for Ratelimit, error: %v", err))
Expand Down

0 comments on commit 659b1b0

Please sign in to comment.