提交 f1899fe0 编写于 作者: J Jeff 提交者: zryfish

fix health api bug

fix kubebuilder version
上级 8191264b
......@@ -45,15 +45,7 @@ esac
command_exists curl
command_exists tar
if [ "x${KUBEBUILDER_VERSION}" = "x" ] ; then
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=v1.0.8
KUBEBUILDER_VERSION=${KUBEBUILDER_VERSION#"v"}
KUBEBUILDER_VERSION_NAME="kubebuilder_${KUBEBUILDER_VERSION}"
KUBEBUILDER_DIR=/usr/local/kubebuilder
......
......@@ -126,6 +126,17 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("namespaces", "names of namespaces")).
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
webservice.Route(webservice.GET("/namespaces/{namespace}/workloads/{workload}/health").
To(metrics.GetWorkloadHealth).
......
......@@ -49,6 +49,11 @@ func GetNamespacesGraph(request *restful.Request, response *restful.Response) {
handlers.GraphNamespaces(request, response)
}
// Get namespace health
func GetNamespaceHealth(request *restful.Request, response *restful.Response) {
handlers.NamespaceHealth(request, response)
}
// Get workload health
func GetWorkloadHealth(request *restful.Request, response *restful.Response) {
handlers.WorkloadHealth(request, response)
......
......@@ -74,7 +74,9 @@ func NewDestinationRuleController(deploymentInformer informersv1.DeploymentInfor
destinationRuleClient istioclientset.Interface) *DestinationRuleController {
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("")})
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "destinationrule-controller"})
......@@ -95,6 +97,9 @@ func NewDestinationRuleController(deploymentInformer informersv1.DeploymentInfor
deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: v.addDeployment,
DeleteFunc: v.deleteDeployment,
UpdateFunc: func(old, cur interface{}) {
v.addDeployment(cur)
},
})
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) &&
reflect.DeepEqual(currentDestinationRule.Labels, service.Labels) {
......@@ -288,10 +293,23 @@ func (v *DestinationRuleController) syncService(key string) error {
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
// and enqueue it. obj must have *appsv1.Deployment type
func (v *DestinationRuleController) addDeployment(obj interface{}) {
deploy := obj.(*appsv1.Deployment)
// not a application component
if !v.isApplicationComponent(&deploy.ObjectMeta) {
return
}
services, err := v.getDeploymentServiceMemberShip(deploy)
if err != nil {
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 {
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.
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)
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))
}
......
......@@ -77,7 +77,9 @@ func NewVirtualServiceController(serviceInformer coreinformers.ServiceInformer,
virtualServiceClient istioclient.Interface) *VirtualServiceController {
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("")})
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "virtualservice-controller"})
......@@ -115,6 +117,9 @@ func NewVirtualServiceController(serviceInformer coreinformers.ServiceInformer,
destinationRuleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: v.addDestinationRule,
UpdateFunc: func(old, cur interface{}) {
v.addDestinationRule(cur)
},
})
v.virtualServiceLister = virtualServiceInformer.Lister()
......@@ -128,7 +133,7 @@ func NewVirtualServiceController(serviceInformer coreinformers.ServiceInformer,
}
func (v *VirtualServiceController) Start(stopCh <-chan struct{}) error {
v.Run(1, stopCh)
v.Run(5, stopCh)
return nil
}
......@@ -194,8 +199,9 @@ func (v *VirtualServiceController) syncService(key string) error {
service, err := v.serviceLister.Services(namespace).Get(name)
if err != nil {
// 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) {
log.Error(err, "delete orphan virtualservice failed", "namespace", service.Namespace, "name", service.Name)
return err
}
return nil
......@@ -230,7 +236,7 @@ func (v *VirtualServiceController) syncService(key string) error {
if len(subsets) == 0 {
// destination rule with no subsets, not possibly
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
} else {
vs = &v1alpha3.VirtualService{
......@@ -293,7 +299,7 @@ func (v *VirtualServiceController) addDestinationRule(obj interface{}) {
service, err := v.serviceLister.Services(dr.Namespace).Get(dr.Name)
if err != nil {
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
}
utilruntime.HandleError(fmt.Errorf("unable to get service with name %s/%s", dr.Namespace, dr.Name))
......
......@@ -154,10 +154,13 @@ type baseHealthParams struct {
func (p *baseHealthParams) baseExtract(request *restful.Request) {
p.RateInterval = defaultHealthRateInterval
p.QueryTime = util.Clock.Now()
p.QueryTime = time.Now()
p.RateInterval = request.QueryParameter("rateInterval")
p.Namespace = request.PathParameters()["namespace"]
if len(request.QueryParameter("rateInterval")) > 0 {
p.RateInterval = request.QueryParameter("rateInterval")
}
p.Namespace = request.PathParameter("namespace")
}
// namespaceHealthParams holds the path and query parameters for NamespaceHealth
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册