func (r existingReplicaSet) Status(meta map[string]string) (interfaces.ResourceStatus, error) {
	return replicaSetStatus(r.Client, r.Name, meta)
}
Status returns ReplicaSet status based on provided meta.
package resources
import (
	"fmt"
	"log"
	"github.com/Mirantis/k8s-AppController/pkg/client"
	"github.com/Mirantis/k8s-AppController/pkg/interfaces"
	"github.com/Mirantis/k8s-AppController/pkg/report"
	"k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
	extbeta1 "k8s.io/client-go/pkg/apis/extensions/v1beta1"
)
var replicaSetParamFields = []string{
	"Spec.Template.Spec.Containers.Name",
	"Spec.Template.Spec.Containers.Env",
	"Spec.Template.Spec.InitContainers.Name",
	"Spec.Template.Spec.InitContainers.Env",
	"Spec.Template.ObjectMeta",
}
const successFactorKey = "success_factor"
type newReplicaSet struct {
	Base
	ReplicaSet *extbeta1.ReplicaSet
	Client     v1beta1.ReplicaSetInterface
}
type replicaSetTemplateFactory struct{}
func (replicaSetTemplateFactory) ShortName(definition client.ResourceDefinition) string {
	if definition.ReplicaSet == nil {
		return ""
	}
	return definition.ReplicaSet.Name
}
func (replicaSetTemplateFactory) Kind() string {
	return "replicaset"
}
func (replicaSetTemplateFactory) New(def client.ResourceDefinition, c client.Interface, gc interfaces.GraphContext) interfaces.Resource {
	replicaSet := parametrizeResource(def.ReplicaSet, gc, replicaSetParamFields).(*extbeta1.ReplicaSet)
	return createNewReplicaSet(replicaSet, c.ReplicaSets(), def.Meta)
}
func (replicaSetTemplateFactory) NewExisting(name string, c client.Interface, gc interfaces.GraphContext) interfaces.Resource {
	return existingReplicaSet{Name: name, Client: c.ReplicaSets()}
}
func replicaSetStatus(r v1beta1.ReplicaSetInterface, name string, meta map[string]string) (interfaces.ResourceStatus, error) {
	rs, err := r.Get(name)
	if err != nil {
		return interfaces.ResourceError, err
	}
	successFactor, err := getPercentage(successFactorKey, meta)
	if err != nil {
		return interfaces.ResourceError, err
	}
	if rs.Status.Replicas*100 < *rs.Spec.Replicas*successFactor {
		return interfaces.ResourceNotReady, nil
	}
	return interfaces.ResourceReady, nil
}
func replicaSetReport(r v1beta1.ReplicaSetInterface, name string, meta map[string]string) interfaces.DependencyReport {
	rs, err := r.Get(name)
	if err != nil {
		return report.ErrorReport(name, err)
	}
	successFactor, err := getPercentage(successFactorKey, meta)
	if err != nil {
		return report.ErrorReport(name, err)
	}
	percentage := (*rs.Spec.Replicas * 100 / rs.Status.Replicas)
	message := fmt.Sprintf(
		"%d of %d replicas up (%d %%, needed %d%%)",
		rs.Status.Replicas,
		rs.Spec.Replicas,
		percentage,
		successFactor,
	)
	if percentage >= successFactor {
		return interfaces.DependencyReport{
			Dependency: name,
			Blocks:     false,
			Percentage: int(percentage),
			Needed:     int(successFactor),
			Message:    message,
		}
	}
	return interfaces.DependencyReport{
		Dependency: name,
		Blocks:     false,
		Percentage: int(percentage),
		Needed:     int(successFactor),
		Message:    message,
	}
}
func replicaSetKey(name string) string {
	return "replicaset/" + name
}
func (r newReplicaSet) Key() string {
	return replicaSetKey(r.ReplicaSet.Name)
}
func (r newReplicaSet) Create() error {
	if err := checkExistence(r); err != nil {
		log.Println("Creating", r.Key())
		r.ReplicaSet, err = r.Client.Create(r.ReplicaSet)
		return err
	}
	return nil
}
func (r newReplicaSet) Delete() error {
	return r.Client.Delete(r.ReplicaSet.Name, nil)
}
func (r newReplicaSet) Status(meta map[string]string) (interfaces.ResourceStatus, error) {
	return replicaSetStatus(r.Client, r.ReplicaSet.Name, meta)
}
func (r newReplicaSet) GetDependencyReport(meta map[string]string) interfaces.DependencyReport {
	return replicaSetReport(r.Client, r.ReplicaSet.Name, meta)
}
func createNewReplicaSet(replicaSet *extbeta1.ReplicaSet, client v1beta1.ReplicaSetInterface, meta map[string]interface{}) newReplicaSet {
	return newReplicaSet{Base: Base{meta}, ReplicaSet: replicaSet, Client: client}
}
type existingReplicaSet struct {
	Base
	Name   string
	Client v1beta1.ReplicaSetInterface
}
func (r existingReplicaSet) Key() string {
	return replicaSetKey(r.Name)
}
func (r existingReplicaSet) Create() error {
	return createExistingResource(r)
}