func (s existingService) Status(meta map[string]string) (interfaces.ResourceStatus, error) {
	return serviceStatus(s.Client, s.Name, s.APIClient)
}
Status returns Service Status. It is based on the status of all objects which match the service selector. If all of them are ready, the Service is considered ready.
package resources
import (
	"log"
	"github.com/Mirantis/k8s-AppController/pkg/client"
	"github.com/Mirantis/k8s-AppController/pkg/interfaces"
	"github.com/Mirantis/k8s-AppController/pkg/report"
	corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
	"k8s.io/client-go/pkg/api"
	"k8s.io/client-go/pkg/api/v1"
	"k8s.io/client-go/pkg/apis/apps/v1beta1"
	"k8s.io/client-go/pkg/labels"
)
var serviceParamFields = []string{
	"Spec.Selector",
}
type newService struct {
	Base
	Service   *v1.Service
	Client    corev1.ServiceInterface
	APIClient client.Interface
}
type serviceTemplateFactory struct{}
func (serviceTemplateFactory) ShortName(definition client.ResourceDefinition) string {
	if definition.Service == nil {
		return ""
	}
	return definition.Service.Name
}
func (serviceTemplateFactory) Kind() string {
	return "service"
}
func (serviceTemplateFactory) New(def client.ResourceDefinition, c client.Interface, gc interfaces.GraphContext) interfaces.Resource {
	service := parametrizeResource(def.Service, gc, serviceParamFields).(*v1.Service)
	return report.SimpleReporter{BaseResource: newService{Base: Base{def.Meta}, Service: service, Client: c.Services(), APIClient: c}}
}
func (serviceTemplateFactory) NewExisting(name string, c client.Interface, gc interfaces.GraphContext) interfaces.Resource {
	return report.SimpleReporter{BaseResource: existingService{Name: name, Client: c.Services()}}
}
func serviceStatus(s corev1.ServiceInterface, name string, apiClient client.Interface) (interfaces.ResourceStatus, error) {
	service, err := s.Get(name)
	if err != nil {
		return interfaces.ResourceError, err
	}
	log.Printf("Checking service status for selector %v", service.Spec.Selector)
	selector := labels.SelectorFromSet(service.Spec.Selector)
	options := v1.ListOptions{LabelSelector: selector.String()}
	pods, err := apiClient.Pods().List(options)
	if err != nil {
		return interfaces.ResourceError, err
	}
	jobs, err := apiClient.Jobs().List(options)
	if err != nil {
		return interfaces.ResourceError, err
	}
	replicasets, err := apiClient.ReplicaSets().List(options)
	if err != nil {
		return interfaces.ResourceError, err
	}
	resources := make([]interfaces.BaseResource, 0, len(pods.Items)+len(jobs.Items)+len(replicasets.Items))
	for _, pod := range pods.Items {
		resources = append(resources, createNewPod(&pod, apiClient.Pods(), nil))
	}
	for _, j := range jobs.Items {
		resources = append(resources, createNewJob(&j, apiClient.Jobs(), nil))
	}
	for _, r := range replicasets.Items {
		resources = append(resources, createNewReplicaSet(&r, apiClient.ReplicaSets(), nil))
	}
	if apiClient.IsEnabled(v1beta1.SchemeGroupVersion) {
		statefulsets, err := apiClient.StatefulSets().List(options)
		if err != nil {
			return interfaces.ResourceError, err
		}
		for _, ps := range statefulsets.Items {
			resources = append(resources, newStatefulSet(&ps, apiClient.StatefulSets(), apiClient, nil))
		}
	} else {
		petsets, err := apiClient.PetSets().List(api.ListOptions{LabelSelector: selector})
		if err != nil {
			return interfaces.ResourceError, err
		}
		for _, ps := range petsets.Items {
			resources = append(resources, newPetSet(&ps, apiClient.PetSets(), apiClient, nil))
		}
	}
	status, err := resourceListStatus(resources)
	if status != interfaces.ResourceReady || err != nil {
		return status, err
	}
	return interfaces.ResourceReady, nil
}
func serviceKey(name string) string {
	return "service/" + name
}
func (s newService) Key() string {
	return serviceKey(s.Service.Name)
}
func (s newService) Create() error {
	if err := checkExistence(s); err != nil {
		log.Println("Creating", s.Key())
		s.Service, err = s.Client.Create(s.Service)
		return err
	}
	return nil
}
func (s newService) Delete() error {
	return s.Client.Delete(s.Service.Name, nil)
}
func (s newService) Status(meta map[string]string) (interfaces.ResourceStatus, error) {
	return serviceStatus(s.Client, s.Service.Name, s.APIClient)
}
type existingService struct {
	Base
	Name      string
	Client    corev1.ServiceInterface
	APIClient client.Interface
}
func (s existingService) Key() string {
	return serviceKey(s.Name)
}
func (s existingService) Create() error {
	return createExistingResource(s)
}