[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-22 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r618908706



##
File path: pkg/ingress/status.go
##
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ingress
+
+import (
+   "context"
+
+   "k8s.io/apimachinery/pkg/api/meta"
+   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+   v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+   "github.com/apache/apisix-ingress-controller/pkg/kube"
+   configv2alpha1 
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+)
+
+const (
+   _onditionType = "ResourcesAvailable"
+   _commonSuccessMessage = "Sync Successfully"
+)
+
+// recordRouteStatus record ApisixRoute v2alpha1 status
+func recordRouteStatus(ar *configv2alpha1.ApisixRoute, reason, message string, 
status v1.ConditionStatus) {
+   condition := metav1.Condition{
+   Type: _onditionType,
+   }
+   // build condition
+   condition.Reason = reason
+   condition.Status = status
+   condition.Message = message

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-22 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r618421810



##
File path: pkg/ingress/status.go
##
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ingress
+
+import (
+   "context"
+
+   "k8s.io/apimachinery/pkg/api/meta"
+   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+   v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+   "github.com/apache/apisix-ingress-controller/pkg/kube"
+   configv2alpha1 
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+   
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/client/clientset/versioned/typed/config/v2alpha1"
+)
+
+const (
+   _onditionType = "ResourcesAvailable"
+   _commonSuccessMessage = "Sync Successfully"
+)
+
+// recordRouteStatus record ApisixRoute v2alpha1 status
+func recordRouteStatus(ar *configv2alpha1.ApisixRoute, reason, message string, 
status v1.ConditionStatus) {
+   condition := metav1.Condition{
+   Type: _onditionType,
+   }
+   // build condition
+   condition.Reason = reason
+   condition.Status = status
+   condition.Message = message
+   // set to status
+   if ar.Status.Conditions == nil {
+   conditions := make([]metav1.Condition, 0)
+   ar.Status.Conditions = &conditions
+   }
+   meta.SetStatusCondition(ar.Status.Conditions, condition)
+   _, _ = 
v2alpha1.New(kube.GetApisixClient().ApisixV2alpha1().RESTClient()).ApisixRoutes(ar.Namespace).

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-21 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r61885



##
File path: pkg/ingress/secret.go
##
@@ -184,9 +184,9 @@ func (c *secretController) onAdd(obj interface{}) {
return
}
 
-   log.Debugw("secret add event arrived",
-   zap.Any("object", obj),
-   )
+   //log.Debugw("secret add event arrived",
+   //  zap.Any("object", obj),

Review comment:
   if log "object" with `zap.Any`, got error ` bad access: nil dereference`.
   I changed logging field.

##
File path: pkg/ingress/endpoint.go
##
@@ -181,8 +181,8 @@ func (c *endpointsController) onAdd(obj interface{}) {
if !c.controller.namespaceWatching(key) {
return
}
-   log.Debugw("endpoints add event arrived",
-   zap.Any("object", obj))
+   //log.Debugw("endpoints add event arrived",

Review comment:
   if log "object" with `zap.Any`, got error ` bad access: nil dereference`.
   I changed logging field.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-21 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617438673



##
File path: pkg/ingress/status.go
##
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ingress
+
+import (
+   "context"
+
+   "k8s.io/apimachinery/pkg/api/meta"
+   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+   v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+   "github.com/apache/apisix-ingress-controller/pkg/kube"
+   configv2alpha1 
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+   
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/client/clientset/versioned/typed/config/v2alpha1"
+)
+
+const (
+   _onditionType = "ResourcesAvailable"
+   _commonSuccessMessage = "Sync Successfully"
+)
+
+// RecordRouteStatus record ApisixRoute v2alpha1 status
+func RecordRouteStatus(ar *configv2alpha1.ApisixRoute, reason, message string, 
status v1.ConditionStatus) {

Review comment:
   ok, done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-21 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617263555



##
File path: pkg/ingress/status.go
##
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ingress
+
+import (
+   "context"
+
+   "k8s.io/apimachinery/pkg/api/meta"
+   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+   v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+   "github.com/apache/apisix-ingress-controller/pkg/kube"
+   configv2alpha1 
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
+   
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/client/clientset/versioned/typed/config/v2alpha1"
+)
+
+const (
+   ConditionType= "ResourcesAvailable"

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-21 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617260925



##
File path: pkg/ingress/apisix_route.go
##
@@ -197,15 +208,57 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
return c.controller.syncManifests(ctx, added, updated, deleted)
 }
 
-func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
-   if err == nil {
+func (c *apisixRouteController) handleSyncErr(obj interface{}, errOrigin 
error) {
+   ev := obj.(*types.Event)
+   event := ev.Object.(kube.ApisixRouteEvent)
+   namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
+   if errLocal != nil {
+   log.Errorf("invalid resource key: %s", event.Key)
+   }
+   if errOrigin == nil {
+   if ev.Type != types.EventDelete {
+   var ar kube.ApisixRoute
+   if event.GroupVersion == kube.ApisixRouteV1 {
+   ar, errLocal = 
c.controller.apisixRouteLister.V1(namespace, name)
+   } else {
+   ar, errLocal = 
c.controller.apisixRouteLister.V2alpha1(namespace, name)
+   }
+   if errLocal == nil {
+   message := fmt.Sprintf(_messageResourceSynced, 
_component)
+   if ar.GroupVersion() == kube.ApisixRouteV1 {
+   c.recorder.Event(ar.V1(), 
v1.EventTypeNormal, _resourceSynced, message)
+   } else if ar.GroupVersion() == 
kube.ApisixRouteV2alpha1 {
+   c.recorder.Event(ar.V2alpha1(), 
v1.EventTypeNormal, _resourceSynced, message)
+   RecordRouteStatus(ar.V2alpha1(), 
_resourceSynced, CommonSuccessMessage, metav1.ConditionTrue)
+   }
+   } else {
+   log.Errorf("invalid resource key: %s", 
event.Key)
+   }
+   }
c.workqueue.Forget(obj)
return
}
log.Warnw("sync ApisixRoute failed, will retry",
zap.Any("object", obj),
-   zap.Error(err),
+   zap.Error(errOrigin),
)
+   var ar kube.ApisixRoute
+   if event.GroupVersion == kube.ApisixRouteV1 {

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-21 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617258843



##
File path: pkg/ingress/apisix_route.go
##
@@ -197,15 +208,57 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
return c.controller.syncManifests(ctx, added, updated, deleted)
 }
 
-func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
-   if err == nil {
+func (c *apisixRouteController) handleSyncErr(obj interface{}, errOrigin 
error) {
+   ev := obj.(*types.Event)
+   event := ev.Object.(kube.ApisixRouteEvent)
+   namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
+   if errLocal != nil {
+   log.Errorf("invalid resource key: %s", event.Key)
+   }
+   if errOrigin == nil {
+   if ev.Type != types.EventDelete {
+   var ar kube.ApisixRoute
+   if event.GroupVersion == kube.ApisixRouteV1 {
+   ar, errLocal = 
c.controller.apisixRouteLister.V1(namespace, name)
+   } else {
+   ar, errLocal = 
c.controller.apisixRouteLister.V2alpha1(namespace, name)
+   }
+   if errLocal == nil {
+   message := fmt.Sprintf(_messageResourceSynced, 
_component)
+   if ar.GroupVersion() == kube.ApisixRouteV1 {
+   c.recorder.Event(ar.V1(), 
v1.EventTypeNormal, _resourceSynced, message)
+   } else if ar.GroupVersion() == 
kube.ApisixRouteV2alpha1 {
+   c.recorder.Event(ar.V2alpha1(), 
v1.EventTypeNormal, _resourceSynced, message)
+   RecordRouteStatus(ar.V2alpha1(), 
_resourceSynced, CommonSuccessMessage, metav1.ConditionTrue)
+   }
+   } else {
+   log.Errorf("invalid resource key: %s", 
event.Key)

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-21 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617256053



##
File path: pkg/ingress/apisix_route.go
##
@@ -197,15 +208,57 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
return c.controller.syncManifests(ctx, added, updated, deleted)
 }
 
-func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
-   if err == nil {
+func (c *apisixRouteController) handleSyncErr(obj interface{}, errOrigin 
error) {
+   ev := obj.(*types.Event)
+   event := ev.Object.(kube.ApisixRouteEvent)
+   namespace, name, errLocal := cache.SplitMetaNamespaceKey(event.Key)
+   if errLocal != nil {
+   log.Errorf("invalid resource key: %s", event.Key)

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-20 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617134653



##
File path: pkg/ingress/apisix_upstream.go
##
@@ -122,6 +133,8 @@ func (c *apisixUpstreamController) sync(ctx 
context.Context, ev *types.Event) er
svc, err := c.controller.svcLister.Services(namespace).Get(name)
if err != nil {
log.Errorf("failed to get service %s: %s", key, err)
+   message := fmt.Sprintf(_messageResourceFailed, 
_upstreamController, err.Error())

Review comment:
   Yes, I will refactor it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-20 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617134124



##
File path: pkg/ingress/apisix_route.go
##
@@ -16,30 +16,44 @@ package ingress
 
 import (
"context"
+   "fmt"
"time"
 
"go.uber.org/zap"
+   v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
+   "k8s.io/apimachinery/pkg/api/meta"
+   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+   "k8s.io/client-go/kubernetes/scheme"
+   typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/cache"
+   "k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
 
"github.com/apache/apisix-ingress-controller/pkg/kube"
+   
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/client/clientset/versioned/typed/config/v2alpha1"
"github.com/apache/apisix-ingress-controller/pkg/log"
"github.com/apache/apisix-ingress-controller/pkg/types"
apisixv1 
"github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
 )
 
+const _routeController = "RouteController"

Review comment:
   Do you mean using `ApisixIngress` is better?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-20 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r617132857



##
File path: pkg/ingress/endpoint.go
##
@@ -181,8 +181,8 @@ func (c *endpointsController) onAdd(obj interface{}) {
if !c.controller.namespaceWatching(key) {
return
}
-   log.Debugw("endpoints add event arrived",
-   zap.Any("object", obj))
+   //log.Debugw("endpoints add event arrived",

Review comment:
got error when logging.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-20 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616532189



##
File path: pkg/ingress/apisix_route.go
##
@@ -198,14 +212,50 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
 }
 
 func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
+   event := obj.(*types.Event)
+   route := event.Object.(kube.ApisixRouteEvent).OldObject

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616292538



##
File path: pkg/ingress/apisix_route.go
##
@@ -198,14 +212,50 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
 }
 
 func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
+   event := obj.(*types.Event)
+   route := event.Object.(kube.ApisixRouteEvent).OldObject

Review comment:
   Yes, will modify this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616291735



##
File path: pkg/ingress/secret.go
##
@@ -184,9 +184,9 @@ func (c *secretController) onAdd(obj interface{}) {
return
}
 
-   log.Debugw("secret add event arrived",
-   zap.Any("object", obj),
-   )
+   //log.Debugw("secret add event arrived",
+   //  zap.Any("object", obj),

Review comment:
   Yes, can not print.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616281005



##
File path: pkg/kube/apisix/apis/config/v2alpha1/types.go
##
@@ -61,11 +62,18 @@ const (
 )
 
 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
+// +kubebuilder:subresource:status
 // ApisixRoute is used to define the route rules and upstreams for Apache 
APISIX.
 type ApisixRoute struct {
metav1.TypeMeta   `json:",inline" yaml:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Spec  *ApisixRouteSpec `json:"spec,omitempty" 
yaml:"spec,omitempty"`
+   StatusApisixStatus `json:"status,omitempty" 
yaml:"status,omitempty"`
+}

Review comment:
   `ApisixTls ` and `ApisixUpstream` will be add in next PR, which is in 
version v1.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616280609



##
File path: pkg/ingress/controller.go
##
@@ -44,6 +44,17 @@ import (
apisixv1 
"github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
 )
 
+const (
+   // SuccessSynced is used when a resource is synced successfully
+   SuccessSynced = "SyncSuccessfully"
+   // MessageResourceSynced is used to specify controller
+   MessageResourceSynced = "%s synced successfully"
+   // FailedSynced is used when a resource synced failed
+   FailedSynced = "SyncFailed"

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616278685



##
File path: pkg/ingress/apisix_route.go
##
@@ -198,14 +210,50 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
 }
 
 func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
+   event := obj.(*types.Event)
+   route := event.Object.(kube.ApisixRouteEvent).OldObject
+   // conditions
+   condition := metav1.Condition{
+   Type: "APISIXSynced",

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616278503



##
File path: pkg/ingress/apisix_route.go
##
@@ -198,14 +210,50 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
 }
 
 func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
+   event := obj.(*types.Event)
+   route := event.Object.(kube.ApisixRouteEvent).OldObject
+   // conditions
+   condition := metav1.Condition{
+   Type: "APISIXSynced",
+   }
if err == nil {
+   message := fmt.Sprintf(MessageResourceSynced, RouteController)
+   if route.GroupVersion() == kube.ApisixRouteV1 {
+   c.recorder.Event(route.V1(), v1.EventTypeNormal, 
SuccessSynced, message)
+   } else if route.GroupVersion() == kube.ApisixRouteV2alpha1 {
+   c.recorder.Event(route.V2alpha1(), v1.EventTypeNormal, 
SuccessSynced, message)
+   // build condition
+   condition.Reason = "SyncSuccessfully"
+   condition.Status = "True"
+   condition.Message = "Sync Successfully"
+   // set to status
+   routev2 := route.V2alpha1()
+   meta.SetStatusCondition(routev2.Status.Conditions, 
condition)
+   
v2alpha1.New(kube.GetApisixClient().ApisixV2alpha1().RESTClient()).ApisixRoutes(routev2.Namespace).
+   Update(context.TODO(), routev2, nil)
+   }
c.workqueue.Forget(obj)
return
}
log.Warnw("sync ApisixRoute failed, will retry",
zap.Any("object", obj),
zap.Error(err),
)
+   message := fmt.Sprintf(MessageResourceFailed, RouteController, 
err.Error())
+   if route.GroupVersion() == kube.ApisixRouteV1 {
+   c.recorder.Event(route.V1(), v1.EventTypeWarning, FailedSynced, 
message)
+   } else if route.GroupVersion() == kube.ApisixRouteV2alpha1 {
+   c.recorder.Event(route.V2alpha1(), v1.EventTypeWarning, 
FailedSynced, message)
+   // build condition
+   condition.Reason = "SyncFailed"
+   condition.Status = "False"

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616278314



##
File path: pkg/ingress/controller.go
##
@@ -44,6 +44,17 @@ import (
apisixv1 
"github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
 )
 
+const (
+   // SuccessSynced is used when a resource is synced successfully
+   SuccessSynced = "SyncSuccessfully"

Review comment:
   done

##
File path: pkg/ingress/apisix_route.go
##
@@ -198,14 +210,50 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
 }
 
 func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
+   event := obj.(*types.Event)
+   route := event.Object.(kube.ApisixRouteEvent).OldObject
+   // conditions
+   condition := metav1.Condition{
+   Type: "APISIXSynced",
+   }
if err == nil {
+   message := fmt.Sprintf(MessageResourceSynced, RouteController)
+   if route.GroupVersion() == kube.ApisixRouteV1 {
+   c.recorder.Event(route.V1(), v1.EventTypeNormal, 
SuccessSynced, message)
+   } else if route.GroupVersion() == kube.ApisixRouteV2alpha1 {
+   c.recorder.Event(route.V2alpha1(), v1.EventTypeNormal, 
SuccessSynced, message)
+   // build condition
+   condition.Reason = "SyncSuccessfully"
+   condition.Status = "True"

Review comment:
   done

##
File path: pkg/ingress/apisix_route.go
##
@@ -198,14 +210,50 @@ func (c *apisixRouteController) sync(ctx context.Context, 
ev *types.Event) error
 }
 
 func (c *apisixRouteController) handleSyncErr(obj interface{}, err error) {
+   event := obj.(*types.Event)
+   route := event.Object.(kube.ApisixRouteEvent).OldObject
+   // conditions
+   condition := metav1.Condition{
+   Type: "APISIXSynced",
+   }
if err == nil {
+   message := fmt.Sprintf(MessageResourceSynced, RouteController)
+   if route.GroupVersion() == kube.ApisixRouteV1 {
+   c.recorder.Event(route.V1(), v1.EventTypeNormal, 
SuccessSynced, message)
+   } else if route.GroupVersion() == kube.ApisixRouteV2alpha1 {
+   c.recorder.Event(route.V2alpha1(), v1.EventTypeNormal, 
SuccessSynced, message)
+   // build condition
+   condition.Reason = "SyncSuccessfully"

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616278175



##
File path: pkg/ingress/apisix_route.go
##
@@ -16,23 +16,33 @@ package ingress
 
 import (
"context"
+   "fmt"
"time"
 
"go.uber.org/zap"
+   v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
+   "k8s.io/apimachinery/pkg/api/meta"
+   metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+   "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/cache"
+   "k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
 
"github.com/apache/apisix-ingress-controller/pkg/kube"
+   
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/client/clientset/versioned/typed/config/v2alpha1"
"github.com/apache/apisix-ingress-controller/pkg/log"
"github.com/apache/apisix-ingress-controller/pkg/types"
apisixv1 
"github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
 )
 
+const RouteController = "RouteController"

Review comment:
   done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #386: feat: add event & status for ApisixRoute v2

2021-04-19 Thread GitBox


gxthrj commented on a change in pull request #386:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/386#discussion_r616277264



##
File path: pkg/ingress/apisix_tls.go
##
@@ -117,6 +123,8 @@ func (c *apisixTlsController) sync(ctx context.Context, ev 
*types.Event) error {
zap.Error(err),
zap.Any("ApisixTls", tls),
)
+   message := fmt.Sprintf(MessageResourceFailed, TlsController, 
err.Error())
+   c.recorder.Event(tls, corev1.EventTypeWarning, FailedSynced, 
message)

Review comment:
   Will need to query resource objects repeatedly if in `c.handleSyncErr `, 
which is processed in method sync()

##
File path: pkg/ingress/apisix_upstream.go
##
@@ -122,6 +128,8 @@ func (c *apisixUpstreamController) sync(ctx 
context.Context, ev *types.Event) er
svc, err := c.controller.svcLister.Services(namespace).Get(name)
if err != nil {
log.Errorf("failed to get service %s: %s", key, err)
+   message := fmt.Sprintf(MessageResourceFailed, 
UpstreamController, err.Error())

Review comment:
   Will need to query resource objects repeatedly if in `c.handleSyncErr `, 
which is processed in method sync()




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org