func (a KubernetesAdapter) CreateServices(services []*pmxadapter.Service) ([]pmxadapter.ServiceDeployment, error) { deployments := make([]pmxadapter.ServiceDeployment, len(services)) // TODO destroy all services (and RCs I guess!) if there is an error // anywhere. Otherwise they'll be orphaned and screw up subsequent deploys. kServices, err := kServicesFromServices(services) if err != nil { return nil, err } if err := DefaultExecutor.CreateKServices(kServices); err != nil { return nil, err } for i, s := range services { rcSpec := replicationControllerSpecFromService(*s) rc, err := DefaultExecutor.CreateReplicationController(rcSpec) if err != nil { if sErr, ok := err.(*errors.StatusError); ok && sErr.ErrStatus.Reason == api.StatusReasonAlreadyExists { return nil, pmxadapter.NewAlreadyExistsError(err.Error()) } return nil, err } status, err := statusFromReplicationController(rc) if err != nil { return nil, err } deployments[i].ID = rc.ObjectMeta.Name deployments[i].ActualState = status } return deployments, nil }
// Once K8s allows multiple ports per service, we can lift the restriction on // a single port. We can't do anything about it now because we need to mimic // current Docker environment variables while satisfying K8s's requirement // for unique service names. func validateServicesPorts(services []*pmxadapter.Service) error { for _, s := range services { if len(s.Ports) > 1 { return pmxadapter.NewAlreadyExistsError(multiplePortsError) } } return nil }