func (c *Controller) syncHandler(key string) error {
	// Convert the namespace/name string into a distinct namespace and name
	ns, name, err := cache.SplitMetaNamespaceKey(key)

	if err != nil {
		runtime.HandleError(fmt.Errorf("invalid resource key: %s", key))
		return nil
		// return err
	}

	// Get the Foo resource with this namespace/name
	foo, err := c.foosLister.Rabbitmqs(ns).Get(name)

	if err != nil {
		// The Foo resource may no longer exist, in which case we stop
		// processing.
		if errors.IsNotFound(err) {
			runtime.HandleError(fmt.Errorf("foo '%s' in work queue no longer exists", key))
			return nil
		}
		// if util.ResourceNotFoundError(err) {
		// 	 delete(c.redises, name)
		// 	 return c.deleteResources(ns, name)
		// }

		return err
	}

	serviceName := foo.Name
	if foo.Spec.ServiceName != "" {
		serviceName = foo.Spec.ServiceName
	}
	service, err := c.serviceLister.Services(foo.Namespace).Get(serviceName)
	if errors.IsNotFound(err) {
		recipe := svc.NewRabbitmqRecipient(serviceName, foo.Namespace, foo.Name)
		artifact, err := recipe.Generate()
		if err != nil {
			runtime.HandleError(fmt.Errorf("Internel error: %s", err.Error))
			return nil
		}
		artifact.ObjectMeta.OwnerReferences = []metav1.OwnerReference{
			*metav1.NewControllerRef(foo, schema.GroupVersionKind{
				Group:   samplev1alpha1.SchemeGroupVersion.Group,
				Version: samplev1alpha1.SchemeGroupVersion.Version,
				Kind:    samplev1alpha1.CustomResourceKind,
			}),
		}

		service, err = c.kubeclientset.CoreV1().Services(foo.Namespace).Create(artifact)
	}

	if err != nil {
		glog.V(2).Info(err)
		return err
	}

	if !metav1.IsControlledBy(service, foo) {
		msg := fmt.Sprintf(MessageResourceExists, service.Name)
		c.recorder.Event(foo, corev1.EventTypeWarning, ErrResourceExists, msg)
		return fmt.Errorf(msg)
	}

	// deploymentName := foo.Spec.DeploymentName
	statefulSetName := foo.Spec.StatefulSetName
	//if deploymentName == "" {
	if statefulSetName == "" {
		// We choose to absorb the error here as the worker would requeue the
		// resource otherwise. Instead, the next time the resource is updated
		// the resource will be queued again.
		statefulSetName = foo.Name
		//key := foo.Name
		//runtime.HandleError(fmt.Errorf("%s: deployment name must be specified", key))
		//return nil
	}
	count := int32(3)
	if foo.Spec.Count != nil {
		if *foo.Spec.Count < 3 || *foo.Spec.Count > 15 {
			runtime.HandleError(fmt.Errorf("Cluster members must be between 3 and 5"))
			return nil
		}
	}
	count = int32(*foo.Spec.Count)

	//var artifact extensions.Deployment
	var artifact *appsv1beta2.StatefulSet

	// Get the deployment with the name specified in Foo.spec
	//deployment, err := c.deploymentsLister.Deployments(foo.Namespace).Get(deploymentName)
	statefulSet, err := c.statefulSetLister.StatefulSets(foo.Namespace).Get(statefulSetName)
	// If the resource doesn't exist, we'll create it
	if errors.IsNotFound(err) {
		recipe := sts.NewRabbitmqRecipient(statefulSetName, foo.Namespace, foo.Name, serviceName, &count)
		artifact, err = recipe.Generate()
		if err != nil {
			runtime.HandleError(fmt.Errorf("Internel error: %s", err.Error()))
			return nil
		}
		artifact.ObjectMeta.OwnerReferences = []metav1.OwnerReference{
			*metav1.NewControllerRef(foo, schema.GroupVersionKind{
				Group:   samplev1alpha1.SchemeGroupVersion.Group,
				Version: samplev1alpha1.SchemeGroupVersion.Version,
				Kind:    samplev1alpha1.CustomResourceKind,
			}),
		}

		//deployment, err = c.kubeclientset.ExtensionsV1beta1().Deployments(foo.Namespace).Create(newDeployment(foo))
		//deployment, err = c.kubeclientset.AppsV1beta2().Deployments(foo.Namespace).Create(artifact)
		statefulSet, err = c.kubeclientset.AppsV1beta2().StatefulSets(foo.Namespace).Create(artifact)
	}

	// If an error occurs during Get/Create, we'll requeue the item so we can
	// attempt processing again later. This could have been caused by a
	// temporary network failure, or any other transient reason.
	if err != nil {
		glog.V(2).Info(err)
		return err
	}

	// If the Deployment is not controlled by this Foo resource, we should log
	// a warning to the event recorder and ret
	if !metav1.IsControlledBy( /*deployment*/ statefulSet, foo) {
		msg := fmt.Sprintf(MessageResourceExists /*deployment*/, statefulSet.Name)
		c.recorder.Event(foo, corev1.EventTypeWarning, ErrResourceExists, msg)
		return fmt.Errorf(msg)
	}

	// If this number of the replicas on the Foo resource is specified, and the
	// number does not equal the current desired replicas on the Deployment, we
	// should update the Deployment resource.
	if foo.Spec.Count != nil && *foo.Spec.Count != *statefulSet.Spec.Replicas {
		glog.V(4).Infof("Count: %d, Replicas: %d", *foo.Spec.Count, *statefulSet.Spec.Replicas)
		//deployment, err = c.kubeclientset.ExtensionsV1beta1().Deployments(foo.Namespace).Update(newDeployment(foo))
		//deployment, err = c.kubeclientset.AppsV1beta2().Deployments(foo.Namespace).Update(artifact)
		statefulSet, err = c.kubeclientset.AppsV1beta2().StatefulSets(foo.Namespace).Update(artifact)
	}

	// If an error occurs during Update, we'll requeue the item so we can
	// attempt processing again later. THis could have been caused by a
	// temporary network failure, or any other transient reason.
	if err != nil {
		glog.V(2).Info(err)
		return err
	}

	// Finally, we update the status block of the Foo resource to reflect the
	// current state of the world
	//	err = c.updateFooStatus(foo, statefulSet)
	//	if err != nil {
	//		return err
	//	}

	c.recorder.Event(foo, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced)
	return nil
}
// syncHandler compares the actual state with the desired, and attempts to
// converge the two. It then updates the Status block of the Foo resource
// with the current status of the resource.
syncHandler compares the actual state with the desired, and attempts to
converge the two. It then updates the Status block of the Foo resource
with the current status of the resource.
// syncHandler compares the actual state with the desired and attempts to // converge the two . It then updates the Status block of the Foo resource // with the current status of the resource .
func (c *Controller) syncHandler(key string) error {
	ns, name, err := cache.SplitMetaNamespaceKey(key)
	if err != nil {
		runtime.HandleError(fmt.Errorf("invalid resource key: %s", key))
		return nil
	}
	foo, err := c.foosLister.Rabbitmqs(ns).Get(name)
	if err != nil {
		if errors.IsNotFound(err) {
			runtime.HandleError(fmt.Errorf("foo '%s' in work queue no longer exists", key))
			return nil
		}
		return err
	}
	serviceName := foo.Name
	if foo.Spec.ServiceName != "" {
		serviceName = foo.Spec.ServiceName
	}
	service, err := c.serviceLister.Services(foo.Namespace).Get(serviceName)
	if errors.IsNotFound(err) {
		recipe := svc.NewRabbitmqRecipient(serviceName, foo.Namespace, foo.Name)
		artifact, err := recipe.Generate()
		if err != nil {
			runtime.HandleError(fmt.Errorf("Internel error: %s", err.Error))
			return nil
		}
		artifact.ObjectMeta.OwnerReferences = []metav1.OwnerReference{
			*metav1.NewControllerRef(foo, schema.GroupVersionKind{
				Group:   samplev1alpha1.SchemeGroupVersion.Group,
				Version: samplev1alpha1.SchemeGroupVersion.Version,
				Kind:    samplev1alpha1.CustomResourceKind,
			}),
		}
		service, err = c.kubeclientset.CoreV1().Services(foo.Namespace).Create(artifact)
	}
	if err != nil {
		glog.V(2).Info(err)
		return err
	}
	if !metav1.IsControlledBy(service, foo) {
		msg := fmt.Sprintf(MessageResourceExists, service.Name)
		c.recorder.Event(foo, corev1.EventTypeWarning, ErrResourceExists, msg)
		return fmt.Errorf(msg)
	}
	statefulSetName := foo.Spec.StatefulSetName
	if statefulSetName == "" {
		statefulSetName = foo.Name
	}
	count := int32(3)
	if foo.Spec.Count != nil {
		if *foo.Spec.Count < 3 || *foo.Spec.Count > 15 {
			runtime.HandleError(fmt.Errorf("Cluster members must be between 3 and 5"))
			return nil
		}
	}
	count = int32(*foo.Spec.Count)
	var artifact *appsv1beta2.StatefulSet
	statefulSet, err := c.statefulSetLister.StatefulSets(foo.Namespace).Get(statefulSetName)
	if errors.IsNotFound(err) {
		recipe := sts.NewRabbitmqRecipient(statefulSetName, foo.Namespace, foo.Name, serviceName, &count)
		artifact, err = recipe.Generate()
		if err != nil {
			runtime.HandleError(fmt.Errorf("Internel error: %s", err.Error()))
			return nil
		}
		artifact.ObjectMeta.OwnerReferences = []metav1.OwnerReference{
			*metav1.NewControllerRef(foo, schema.GroupVersionKind{
				Group:   samplev1alpha1.SchemeGroupVersion.Group,
				Version: samplev1alpha1.SchemeGroupVersion.Version,
				Kind:    samplev1alpha1.CustomResourceKind,
			}),
		}
		statefulSet, err = c.kubeclientset.AppsV1beta2().StatefulSets(foo.Namespace).Create(artifact)
	}
	if err != nil {
		glog.V(2).Info(err)
		return err
	}
	if !metav1.IsControlledBy(  statefulSet, foo) {
		msg := fmt.Sprintf(MessageResourceExists , statefulSet.Name)
		c.recorder.Event(foo, corev1.EventTypeWarning, ErrResourceExists, msg)
		return fmt.Errorf(msg)
	}
	if foo.Spec.Count != nil && *foo.Spec.Count != *statefulSet.Spec.Replicas {
		glog.V(4).Infof("Count: %d, Replicas: %d", *foo.Spec.Count, *statefulSet.Spec.Replicas)
		statefulSet, err = c.kubeclientset.AppsV1beta2().StatefulSets(foo.Namespace).Update(artifact)
	}
	if err != nil {
		glog.V(2).Info(err)
		return err
	}
	c.recorder.Event(foo, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced)
	return nil
}
func ( c * Controller ) syncHandler ( key string ) error { ns , name , err := cache . SplitMetaNamespaceKey ( key ) if err != nil { runtime . HandleError ( fmt . Errorf ( " " , key ) ) return nil } foo , err := c . foosLister . Rabbitmqs ( ns ) . Get ( name ) if err != nil { if errors . IsNotFound ( err ) { runtime . HandleError ( fmt . Errorf ( " " , key ) ) return nil } return err } serviceName := foo . Name if foo . Spec . ServiceName != " " { serviceName = foo . Spec . ServiceName } service , err := c . serviceLister . Services ( foo . Namespace ) . Get ( serviceName ) if errors . IsNotFound ( err ) { recipe := svc . NewRabbitmqRecipient ( serviceName , foo . Namespace , foo . Name ) artifact , err := recipe . Generate ( ) if err != nil { runtime . HandleError ( fmt . Errorf ( " " , err . Error ) ) return nil } artifact . ObjectMeta . OwnerReferences = [ ] metav1 . OwnerReference { * metav1 . NewControllerRef ( foo , schema . GroupVersionKind { Group : samplev1alpha1 . SchemeGroupVersion . Group , Version : samplev1alpha1 . SchemeGroupVersion . Version , Kind : samplev1alpha1 . CustomResourceKind , } ) , } service , err = c . kubeclientset . CoreV1 ( ) . Services ( foo . Namespace ) . Create ( artifact ) } if err != nil { glog . V ( 2 ) . Info ( err ) return err } if ! metav1 . IsControlledBy ( service , foo ) { msg := fmt . Sprintf ( MessageResourceExists , service . Name ) c . recorder . Event ( foo , corev1 . EventTypeWarning , ErrResourceExists , msg ) return fmt . Errorf ( msg ) } statefulSetName := foo . Spec . StatefulSetName if statefulSetName == " " { statefulSetName = foo . Name } count := int32 ( 3 ) if foo . Spec . Count != nil { if * foo . Spec . Count < 3 || * foo . Spec . Count > 15 { runtime . HandleError ( fmt . Errorf ( " " ) ) return nil } } count = int32 ( * foo . Spec . Count ) var artifact * appsv1beta2 . StatefulSet statefulSet , err := c . statefulSetLister . StatefulSets ( foo . Namespace ) . Get ( statefulSetName ) if errors . IsNotFound ( err ) { recipe := sts . NewRabbitmqRecipient ( statefulSetName , foo . Namespace , foo . Name , serviceName , & count ) artifact , err = recipe . Generate ( ) if err != nil { runtime . HandleError ( fmt . Errorf ( " " , err . Error ( ) ) ) return nil } artifact . ObjectMeta . OwnerReferences = [ ] metav1 . OwnerReference { * metav1 . NewControllerRef ( foo , schema . GroupVersionKind { Group : samplev1alpha1 . SchemeGroupVersion . Group , Version : samplev1alpha1 . SchemeGroupVersion . Version , Kind : samplev1alpha1 . CustomResourceKind , } ) , } statefulSet , err = c . kubeclientset . AppsV1beta2 ( ) . StatefulSets ( foo . Namespace ) . Create ( artifact ) } if err != nil { glog . V ( 2 ) . Info ( err ) return err } if ! metav1 . IsControlledBy ( statefulSet , foo ) { msg := fmt . Sprintf ( MessageResourceExists , statefulSet . Name ) c . recorder . Event ( foo , corev1 . EventTypeWarning , ErrResourceExists , msg ) return fmt . Errorf ( msg ) } if foo . Spec . Count != nil && * foo . Spec . Count != * statefulSet . Spec . Replicas { glog . V ( 4 ) . Infof ( " " , * foo . Spec . Count , * statefulSet . Spec . Replicas ) statefulSet , err = c . kubeclientset . AppsV1beta2 ( ) . StatefulSets ( foo . Namespace ) . Update ( artifact ) } if err != nil { glog . V ( 2 ) . Info ( err ) return err } c . recorder . Event ( foo , corev1 . EventTypeNormal , SuccessSynced , MessageResourceSynced ) return nil }
syncHandler compares the actual state with the desired, and attempts to
converge the two.
syncHandler compares the actual state with the desired and attempts to converge the two .
// Convert the namespace/name string into a distinct namespace and name // return err // Get the Foo resource with this namespace/name // The Foo resource may no longer exist, in which case we stop // processing. // if util.ResourceNotFoundError(err) { // 	 delete(c.redises, name) // 	 return c.deleteResources(ns, name) // } // deploymentName := foo.Spec.DeploymentName //if deploymentName == "" { // We choose to absorb the error here as the worker would requeue the // resource otherwise. Instead, the next time the resource is updated // the resource will be queued again. //key := foo.Name //runtime.HandleError(fmt.Errorf("%s: deployment name must be specified", key)) //return nil //var artifact extensions.Deployment // Get the deployment with the name specified in Foo.spec //deployment, err := c.deploymentsLister.Deployments(foo.Namespace).Get(deploymentName) // If the resource doesn't exist, we'll create it //deployment, err = c.kubeclientset.ExtensionsV1beta1().Deployments(foo.Namespace).Create(newDeployment(foo)) //deployment, err = c.kubeclientset.AppsV1beta2().Deployments(foo.Namespace).Create(artifact) // If an error occurs during Get/Create, we'll requeue the item so we can // attempt processing again later. This could have been caused by a // temporary network failure, or any other transient reason. // If the Deployment is not controlled by this Foo resource, we should log // a warning to the event recorder and ret /*deployment*/ /*deployment*/ // If this number of the replicas on the Foo resource is specified, and the // number does not equal the current desired replicas on the Deployment, we // should update the Deployment resource. //deployment, err = c.kubeclientset.ExtensionsV1beta1().Deployments(foo.Namespace).Update(newDeployment(foo)) //deployment, err = c.kubeclientset.AppsV1beta2().Deployments(foo.Namespace).Update(artifact) // If an error occurs during Update, we'll requeue the item so we can // attempt processing again later. THis could have been caused by a // temporary network failure, or any other transient reason. // Finally, we update the status block of the Foo resource to reflect the // current state of the world //	err = c.updateFooStatus(foo, statefulSet) //	if err != nil { //		return err //	}