@@ -15,45 +15,59 @@ package controller
1515import (
1616 "context"
1717
18+ "github.com/go-logr/logr"
19+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1820 "k8s.io/apimachinery/pkg/runtime"
1921 ctrl "sigs.k8s.io/controller-runtime"
2022 "sigs.k8s.io/controller-runtime/pkg/client"
21- "sigs.k8s.io/controller-runtime/pkg/log "
23+ gatewayv1 "sigs.k8s.io/gateway-api/apis/v1 "
2224
23- apisixapacheorgv2 "github.com/apache/apisix-ingress-controller/api/v2"
25+ apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
2426)
2527
2628// ApisixGlobalRuleReconciler reconciles a ApisixGlobalRule object
2729type ApisixGlobalRuleReconciler struct {
2830 client.Client
2931 Scheme * runtime.Scheme
32+ Log logr.Logger
3033}
3134
3235// +kubebuilder:rbac:groups=apisix.apache.org.github.com,resources=apisixglobalrules,verbs=get;list;watch;create;update;patch;delete
3336// +kubebuilder:rbac:groups=apisix.apache.org.github.com,resources=apisixglobalrules/status,verbs=get;update;patch
3437// +kubebuilder:rbac:groups=apisix.apache.org.github.com,resources=apisixglobalrules/finalizers,verbs=update
3538
36- // Reconcile is part of the main kubernetes reconciliation loop which aims to
37- // move the current state of the cluster closer to the desired state.
38- // TODO(user): Modify the Reconcile function to compare the state specified by
39- // the ApisixGlobalRule object against the actual cluster state, and then
40- // perform operations to make the cluster state reflect the state specified by
41- // the user.
42- //
43- // For more details, check Reconcile and its Result here:
44- // - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/reconcile 39+ // Reconcile FIXME: implement the reconcile logic (For now, it dose nothing other than directly accepting)
4540func (r * ApisixGlobalRuleReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
46- _ = log .FromContext (ctx )
41+ r .Log .Info ("reconcile" , "request" , req .NamespacedName )
42+
43+ var obj apiv2.ApisixGlobalRule
44+ if err := r .Get (ctx , req .NamespacedName , & obj ); err != nil {
45+ r .Log .Error (err , "failed to get ApisixConsumer" , "request" , req .NamespacedName )
46+ return ctrl.Result {}, err
47+ }
48+
49+ obj .Status .Conditions = []metav1.Condition {
50+ {
51+ Type : string (gatewayv1 .RouteConditionAccepted ),
52+ Status : metav1 .ConditionTrue ,
53+ ObservedGeneration : obj .GetGeneration (),
54+ LastTransitionTime : metav1 .Now (),
55+ Reason : string (gatewayv1 .RouteReasonAccepted ),
56+ },
57+ }
4758
48- // TODO(user): your logic here
59+ if err := r .Status ().Update (ctx , & obj ); err != nil {
60+ r .Log .Error (err , "failed to update status" , "request" , req .NamespacedName )
61+ return ctrl.Result {}, err
62+ }
4963
5064 return ctrl.Result {}, nil
5165}
5266
5367// SetupWithManager sets up the controller with the Manager.
5468func (r * ApisixGlobalRuleReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
5569 return ctrl .NewControllerManagedBy (mgr ).
56- For (& apisixapacheorgv2 .ApisixGlobalRule {}).
70+ For (& apiv2 .ApisixGlobalRule {}).
5771 Named ("apisixglobalrule" ).
5872 Complete (r )
5973}
0 commit comments