diff --git a/hack/install_kubebuilder.sh b/hack/install_kubebuilder.sh index a7eefcda4..e4cfe50db 100755 --- a/hack/install_kubebuilder.sh +++ b/hack/install_kubebuilder.sh @@ -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 diff --git a/pkg/apis/servicemesh/metrics/v1alpha2/register.go b/pkg/apis/servicemesh/metrics/v1alpha2/register.go index 46c0569cb..32ec3f350 100644 --- a/pkg/apis/servicemesh/metrics/v1alpha2/register.go +++ b/pkg/apis/servicemesh/metrics/v1alpha2/register.go @@ -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). diff --git a/pkg/apiserver/servicemesh/metrics/handlers.go b/pkg/apiserver/servicemesh/metrics/handlers.go index d6b28a8b0..249c22d86 100644 --- a/pkg/apiserver/servicemesh/metrics/handlers.go +++ b/pkg/apiserver/servicemesh/metrics/handlers.go @@ -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) diff --git a/pkg/controller/destinationrule/destinationrule_controller.go b/pkg/controller/destinationrule/destinationrule_controller.go index c5fc6b5fb..d914eaac3 100644 --- a/pkg/controller/destinationrule/destinationrule_controller.go +++ b/pkg/controller/destinationrule/destinationrule_controller.go @@ -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 } diff --git a/pkg/controller/strategy/strategy_controller.go b/pkg/controller/strategy/strategy_controller.go index fd61d6fd9..aa14ddb5d 100644 --- a/pkg/controller/strategy/strategy_controller.go +++ b/pkg/controller/strategy/strategy_controller.go @@ -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)) } diff --git a/pkg/controller/virtualservice/virtualservice_controller.go b/pkg/controller/virtualservice/virtualservice_controller.go index 5efaf020b..ca47b13ba 100644 --- a/pkg/controller/virtualservice/virtualservice_controller.go +++ b/pkg/controller/virtualservice/virtualservice_controller.go @@ -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)) diff --git a/vendor/github.com/kiali/kiali/handlers/health.go b/vendor/github.com/kiali/kiali/handlers/health.go index 4f542ac5e..e455239b4 100644 --- a/vendor/github.com/kiali/kiali/handlers/health.go +++ b/vendor/github.com/kiali/kiali/handlers/health.go @@ -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