fix health api bug
fix kubebuilder version
This commit is contained in:
@@ -45,15 +45,7 @@ esac
|
|||||||
command_exists curl
|
command_exists curl
|
||||||
command_exists tar
|
command_exists tar
|
||||||
|
|
||||||
if [ "x${KUBEBUILDER_VERSION}" = "x" ] ; then
|
KUBEBUILDER_VERSION=v1.0.8
|
||||||
KUBEBUILDER_VERSION=$(curl -L -s https://api.github.com/repos/kubernetes-sigs/kubebuilder/releases/latest?access_token=$TOKEN | \
|
|
||||||
grep tag_name | sed "s/ *\"tag_name\": *\"\\(.*\\)\",*/\\1/")
|
|
||||||
if [ -z "$KUBEBUILDER_VERSION" ]; then
|
|
||||||
echo "\nUnable to fetch the latest version tag. This may be due to network access problem"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
KUBEBUILDER_VERSION=${KUBEBUILDER_VERSION#"v"}
|
KUBEBUILDER_VERSION=${KUBEBUILDER_VERSION#"v"}
|
||||||
KUBEBUILDER_VERSION_NAME="kubebuilder_${KUBEBUILDER_VERSION}"
|
KUBEBUILDER_VERSION_NAME="kubebuilder_${KUBEBUILDER_VERSION}"
|
||||||
KUBEBUILDER_DIR=/usr/local/kubebuilder
|
KUBEBUILDER_DIR=/usr/local/kubebuilder
|
||||||
|
|||||||
@@ -126,6 +126,17 @@ func addWebService(c *restful.Container) error {
|
|||||||
Param(webservice.QueryParameter("namespaces", "names of namespaces")).
|
Param(webservice.QueryParameter("namespaces", "names of namespaces")).
|
||||||
Writes(errors.Error{})).Produces(restful.MIME_JSON)
|
Writes(errors.Error{})).Produces(restful.MIME_JSON)
|
||||||
|
|
||||||
|
// Get namespace health
|
||||||
|
webservice.Route(webservice.GET("/namespaces/{namespace}/health").
|
||||||
|
To(metrics.GetNamespaceHealth).
|
||||||
|
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||||
|
Doc("Get workload health").
|
||||||
|
Param(webservice.PathParameter("namespace", "name of a namespace").Required(true)).
|
||||||
|
Param(webservice.PathParameter("type", "the type of health, app/service/workload, default app").DefaultValue("app")).
|
||||||
|
Param(webservice.QueryParameter("rateInterval", "the rate interval used for fetching error rate").DefaultValue("10m").Required(true)).
|
||||||
|
Param(webservice.QueryParameter("queryTime", "the time to use for query")).
|
||||||
|
Writes(errors.Error{})).Produces(restful.MIME_JSON)
|
||||||
|
|
||||||
// Get workloads health
|
// Get workloads health
|
||||||
webservice.Route(webservice.GET("/namespaces/{namespace}/workloads/{workload}/health").
|
webservice.Route(webservice.GET("/namespaces/{namespace}/workloads/{workload}/health").
|
||||||
To(metrics.GetWorkloadHealth).
|
To(metrics.GetWorkloadHealth).
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ func GetNamespacesGraph(request *restful.Request, response *restful.Response) {
|
|||||||
handlers.GraphNamespaces(request, response)
|
handlers.GraphNamespaces(request, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get namespace health
|
||||||
|
func GetNamespaceHealth(request *restful.Request, response *restful.Response) {
|
||||||
|
handlers.NamespaceHealth(request, response)
|
||||||
|
}
|
||||||
|
|
||||||
// Get workload health
|
// Get workload health
|
||||||
func GetWorkloadHealth(request *restful.Request, response *restful.Response) {
|
func GetWorkloadHealth(request *restful.Request, response *restful.Response) {
|
||||||
handlers.WorkloadHealth(request, response)
|
handlers.WorkloadHealth(request, response)
|
||||||
|
|||||||
@@ -74,7 +74,9 @@ func NewDestinationRuleController(deploymentInformer informersv1.DeploymentInfor
|
|||||||
destinationRuleClient istioclientset.Interface) *DestinationRuleController {
|
destinationRuleClient istioclientset.Interface) *DestinationRuleController {
|
||||||
|
|
||||||
broadcaster := record.NewBroadcaster()
|
broadcaster := record.NewBroadcaster()
|
||||||
broadcaster.StartLogging(log.Info)
|
broadcaster.StartLogging(func(format string, args ...interface{}) {
|
||||||
|
log.Info(fmt.Sprintf(format, args))
|
||||||
|
})
|
||||||
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
||||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "destinationrule-controller"})
|
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "destinationrule-controller"})
|
||||||
|
|
||||||
@@ -95,6 +97,9 @@ func NewDestinationRuleController(deploymentInformer informersv1.DeploymentInfor
|
|||||||
deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: v.addDeployment,
|
AddFunc: v.addDeployment,
|
||||||
DeleteFunc: v.deleteDeployment,
|
DeleteFunc: v.deleteDeployment,
|
||||||
|
UpdateFunc: func(old, cur interface{}) {
|
||||||
|
v.addDeployment(cur)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
v.serviceLister = serviceInformer.Lister()
|
v.serviceLister = serviceInformer.Lister()
|
||||||
@@ -246,7 +251,7 @@ func (v *DestinationRuleController) syncService(key string) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createDestinationRule := len(currentDestinationRule.Spec.Subsets) == 0
|
createDestinationRule := len(currentDestinationRule.ResourceVersion) == 0
|
||||||
|
|
||||||
if !createDestinationRule && reflect.DeepEqual(currentDestinationRule.Spec.Subsets, subsets) &&
|
if !createDestinationRule && reflect.DeepEqual(currentDestinationRule.Spec.Subsets, subsets) &&
|
||||||
reflect.DeepEqual(currentDestinationRule.Labels, service.Labels) {
|
reflect.DeepEqual(currentDestinationRule.Labels, service.Labels) {
|
||||||
@@ -288,10 +293,23 @@ func (v *DestinationRuleController) syncService(key string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *DestinationRuleController) isApplicationComponent(meta *metav1.ObjectMeta) bool {
|
||||||
|
if len(meta.Labels) >= len(util.ApplicationLabels) && util.IsApplicationComponent(meta) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// When a destinationrule is added, figure out which service it will be used
|
// When a destinationrule is added, figure out which service it will be used
|
||||||
// and enqueue it. obj must have *appsv1.Deployment type
|
// and enqueue it. obj must have *appsv1.Deployment type
|
||||||
func (v *DestinationRuleController) addDeployment(obj interface{}) {
|
func (v *DestinationRuleController) addDeployment(obj interface{}) {
|
||||||
deploy := obj.(*appsv1.Deployment)
|
deploy := obj.(*appsv1.Deployment)
|
||||||
|
|
||||||
|
// not a application component
|
||||||
|
if !v.isApplicationComponent(&deploy.ObjectMeta) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
services, err := v.getDeploymentServiceMemberShip(deploy)
|
services, err := v.getDeploymentServiceMemberShip(deploy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utilruntime.HandleError(fmt.Errorf("unable to get deployment %s/%s's service memberships", deploy.Namespace, deploy.Name))
|
utilruntime.HandleError(fmt.Errorf("unable to get deployment %s/%s's service memberships", deploy.Namespace, deploy.Name))
|
||||||
@@ -336,7 +354,7 @@ func (v *DestinationRuleController) getDeploymentServiceMemberShip(deployment *a
|
|||||||
|
|
||||||
for i := range allServices {
|
for i := range allServices {
|
||||||
service := allServices[i]
|
service := allServices[i]
|
||||||
if service.Spec.Selector == nil {
|
if service.Spec.Selector == nil || !v.isApplicationComponent(&service.ObjectMeta) {
|
||||||
// services with nil selectors match nothing, not everything.
|
// services with nil selectors match nothing, not everything.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ func (r *ReconcileStrategy) reconcileStrategy(strategy *servicemeshv1alpha2.Stra
|
|||||||
|
|
||||||
err := r.Get(context.TODO(), types.NamespacedName{Namespace: strategy.Namespace, Name: appName}, service)
|
err := r.Get(context.TODO(), types.NamespacedName{Namespace: strategy.Namespace, Name: appName}, service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err, "couldn't find service %s/%s,", strategy.Namespace, appName)
|
log.Error(err, "couldn't find service", "namespace", strategy.Namespace, "name", appName)
|
||||||
return reconcile.Result{}, errors.NewBadRequest(fmt.Sprintf("service %s not found", appName))
|
return reconcile.Result{}, errors.NewBadRequest(fmt.Sprintf("service %s not found", appName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ func NewVirtualServiceController(serviceInformer coreinformers.ServiceInformer,
|
|||||||
virtualServiceClient istioclient.Interface) *VirtualServiceController {
|
virtualServiceClient istioclient.Interface) *VirtualServiceController {
|
||||||
|
|
||||||
broadcaster := record.NewBroadcaster()
|
broadcaster := record.NewBroadcaster()
|
||||||
broadcaster.StartLogging(log.Info)
|
broadcaster.StartLogging(func(format string, args ...interface{}) {
|
||||||
|
log.Info(fmt.Sprintf(format, args))
|
||||||
|
})
|
||||||
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
||||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "virtualservice-controller"})
|
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "virtualservice-controller"})
|
||||||
|
|
||||||
@@ -115,6 +117,9 @@ func NewVirtualServiceController(serviceInformer coreinformers.ServiceInformer,
|
|||||||
|
|
||||||
destinationRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
destinationRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: v.addDestinationRule,
|
AddFunc: v.addDestinationRule,
|
||||||
|
UpdateFunc: func(old, cur interface{}) {
|
||||||
|
v.addDestinationRule(cur)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
v.virtualServiceLister = virtualServiceInformer.Lister()
|
v.virtualServiceLister = virtualServiceInformer.Lister()
|
||||||
@@ -128,7 +133,7 @@ func NewVirtualServiceController(serviceInformer coreinformers.ServiceInformer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *VirtualServiceController) Start(stopCh <-chan struct{}) error {
|
func (v *VirtualServiceController) Start(stopCh <-chan struct{}) error {
|
||||||
v.Run(1, stopCh)
|
v.Run(5, stopCh)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,8 +199,9 @@ func (v *VirtualServiceController) syncService(key string) error {
|
|||||||
service, err := v.serviceLister.Services(namespace).Get(name)
|
service, err := v.serviceLister.Services(namespace).Get(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Delete the corresponding virtualservice, as the service has been deleted.
|
// Delete the corresponding virtualservice, as the service has been deleted.
|
||||||
err = v.virtualServiceClient.NetworkingV1alpha3().VirtualServices(namespace).Delete(service.Name, nil)
|
err = v.virtualServiceClient.NetworkingV1alpha3().VirtualServices(namespace).Delete(name, nil)
|
||||||
if err != nil && !errors.IsNotFound(err) {
|
if err != nil && !errors.IsNotFound(err) {
|
||||||
|
log.Error(err, "delete orphan virtualservice failed", "namespace", service.Namespace, "name", service.Name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -230,7 +236,7 @@ func (v *VirtualServiceController) syncService(key string) error {
|
|||||||
if len(subsets) == 0 {
|
if len(subsets) == 0 {
|
||||||
// destination rule with no subsets, not possibly
|
// destination rule with no subsets, not possibly
|
||||||
err = fmt.Errorf("find destinationrule with no subsets for service %s", name)
|
err = fmt.Errorf("find destinationrule with no subsets for service %s", name)
|
||||||
log.Error(err, "Find destinationrule with no subsets for service", "service", service.String())
|
log.Error(err, "Find destinationrule with no subsets for service", "namespace", service.Namespace, "name", name)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
vs = &v1alpha3.VirtualService{
|
vs = &v1alpha3.VirtualService{
|
||||||
@@ -293,7 +299,7 @@ func (v *VirtualServiceController) addDestinationRule(obj interface{}) {
|
|||||||
service, err := v.serviceLister.Services(dr.Namespace).Get(dr.Name)
|
service, err := v.serviceLister.Services(dr.Namespace).Get(dr.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsNotFound(err) {
|
if errors.IsNotFound(err) {
|
||||||
log.V(0).Info("service not created yet", "key", dr.Name)
|
log.V(0).Info("service not created yet", "namespace", dr.Namespace, "service", dr.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
utilruntime.HandleError(fmt.Errorf("unable to get service with name %s/%s", dr.Namespace, dr.Name))
|
utilruntime.HandleError(fmt.Errorf("unable to get service with name %s/%s", dr.Namespace, dr.Name))
|
||||||
|
|||||||
7
vendor/github.com/kiali/kiali/handlers/health.go
generated
vendored
7
vendor/github.com/kiali/kiali/handlers/health.go
generated
vendored
@@ -154,10 +154,13 @@ type baseHealthParams struct {
|
|||||||
|
|
||||||
func (p *baseHealthParams) baseExtract(request *restful.Request) {
|
func (p *baseHealthParams) baseExtract(request *restful.Request) {
|
||||||
p.RateInterval = defaultHealthRateInterval
|
p.RateInterval = defaultHealthRateInterval
|
||||||
p.QueryTime = util.Clock.Now()
|
p.QueryTime = time.Now()
|
||||||
|
|
||||||
|
if len(request.QueryParameter("rateInterval")) > 0 {
|
||||||
p.RateInterval = request.QueryParameter("rateInterval")
|
p.RateInterval = request.QueryParameter("rateInterval")
|
||||||
p.Namespace = request.PathParameters()["namespace"]
|
}
|
||||||
|
|
||||||
|
p.Namespace = request.PathParameter("namespace")
|
||||||
}
|
}
|
||||||
|
|
||||||
// namespaceHealthParams holds the path and query parameters for NamespaceHealth
|
// namespaceHealthParams holds the path and query parameters for NamespaceHealth
|
||||||
|
|||||||
Reference in New Issue
Block a user