// createOrUpdateService Creates or updates k8s service for the deployment
createOrUpdateService Creates or updates k8s service for the deployment
// createOrUpdateService Creates or updates k8s service for the deployment
func (r *ReconcileIntegration) createOrUpdateService(config EIConfigNew) error {
	service := &corev1.Service{}
	var integration = config.integration
	namespace := types.NamespacedName{Name: nameForService(&integration), Namespace: integration.Namespace}
	err := k8s.Get(&r.client, namespace, service)
	if err != nil {
		if errors.IsNotFound(err) {
			serviceFromConfig := r.serviceForIntegration(config)
			err := k8s.Create(&r.client,serviceFromConfig)
			if err != nil {
				log.Error(err, "Error creating k8s service", "object", serviceFromConfig)
				return err
			}
			log.Info("Creating k8s service is success", "kind",
				serviceFromConfig.Kind, "object", serviceFromConfig)
		} else {
			log.Error(err, "Failed to get Service for integration")
			return err
		}
	} else {
		serviceFromConfig := r.serviceForIntegration(config)
		serviceFromConfig.ObjectMeta.ResourceVersion = service.ObjectMeta.ResourceVersion
		serviceFromConfig.Spec.ClusterIP = service.Spec.ClusterIP
		err := k8s.Apply(&r.client,serviceFromConfig)
		if err != nil {
			log.Error(err, "Failed to update Service for integration " ,
				"serviceName", serviceFromConfig.Name)
			return err
		}
	}
	return nil
}
func ( r * ReconcileIntegration ) createOrUpdateService ( config EIConfigNew ) error { service := & corev1 . Service { } var integration = config . integration namespace := types . NamespacedName { Name : nameForService ( & integration ) , Namespace : integration . Namespace } err := k8s . Get ( & r . client , namespace , service ) if err != nil { if errors . IsNotFound ( err ) { serviceFromConfig := r . serviceForIntegration ( config ) err := k8s . Create ( & r . client , serviceFromConfig ) if err != nil { log . Error ( err , " " , " " , serviceFromConfig ) return err } log . Info ( " " , " " , serviceFromConfig . Kind , " " , serviceFromConfig ) } else { log . Error ( err , " " ) return err } } else { serviceFromConfig := r . serviceForIntegration ( config ) serviceFromConfig . ObjectMeta . ResourceVersion = service . ObjectMeta . ResourceVersion serviceFromConfig . Spec . ClusterIP = service . Spec . ClusterIP err := k8s . Apply ( & r . client , serviceFromConfig ) if err != nil { log . Error ( err , " " , " " , serviceFromConfig . Name ) return err } } return nil }
createOrUpdateService Creates or updates k8s service for the deployment
createOrUpdateService Creates or updates k8s service for the deployment
//service not found, create it //service exists, update it //workaround for https://github.com/kubernetes/kubernetes/issues/36072