deploy

package
v0.0.0-...-f35731a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2017 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPushLister = func(host, user, password string) ([]*PushApplication, error) {
	hc := http.Client{}
	hc.Timeout = time.Second * 10
	form := url.Values{}
	form.Add("grant_type", "password")
	form.Add("username", user)
	form.Add("password", password)
	form.Add("client_id", "unified-push-server-js")

	req, err := http.NewRequest("POST", fmt.Sprintf("%s/auth/realms/aerogear/protocol/openid-connect/token", host), strings.NewReader(form.Encode()))
	if err != nil {
		return nil, errors.Wrap(err, "failed to listPushApplications ")
	}
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	resp, err := hc.Do(req)
	if err != nil {
		return nil, errors.Wrap(err, "failed to make request to listPushApplications ")
	}
	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, errors.Wrap(err, "failed to read body listPushApplications ")
	}
	payload := map[string]interface{}{}
	if err := json.Unmarshal(data, &payload); err != nil {
		return nil, errors.Wrap(err, "failed to Unmarshal listPushApplications ")
	}
	token := payload["access_token"].(string)

	req, err = http.NewRequest("GET", fmt.Sprintf("%s/ag-push/rest/applications", host), nil)
	if err != nil {
		return nil, errors.Wrap(err, "failed to create request listPushApplications ")
	}
	req.Header.Add("Authorization", "Bearer "+token)
	req.Header.Add("Content-type", "application/json")
	resp, err = hc.Do(req)
	if err != nil {
		return nil, errors.Wrap(err, "failed to make request to listPushApplications ")
	}
	defer resp.Body.Close()
	data, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, errors.Wrap(err, "failed to read response listPushApplications ")
	}
	apps := []*PushApplication{}
	if err := json.Unmarshal(data, &apps); err != nil {
		return nil, errors.Wrap(err, "failed to Unmarshal listPushApplications ")
	}

	return apps, nil
}

DefaultPushLister list PushApplications from ups

Functions

func InstanceID

func InstanceID(namespace, serviceName string) string

func StatusKey

func StatusKey(instanceID, operation string) string

StatusKey returns a key for logging information against

Types

type CacheRedisConfigure

type CacheRedisConfigure struct {
	StatusPublisher StatusPublisher
	// contains filtered or unexported fields
}

CacheRedisConfigure is a Configurer for the cache service

func (*CacheRedisConfigure) Configure

func (c *CacheRedisConfigure) Configure(client Client, deployment *dc.DeploymentConfig, namespace string) (*dc.DeploymentConfig, error)

Configure configures the current DeploymentConfig with the need configuration to use cache

type Client

type Client interface {
	CreateConfigMap(ns string, cm *k8api.ConfigMap) (*k8api.ConfigMap, error)
	UpdateConfigMap(ns string, cm *k8api.ConfigMap) (*k8api.ConfigMap, error)
	CreateServiceInNamespace(ns string, svc *k8api.Service) (*k8api.Service, error)
	CreateRouteInNamespace(ns string, r *roapi.Route) (*roapi.Route, error)
	CreateImageStream(ns string, i *image.ImageStream) (*image.ImageStream, error)
	CreateBuildConfigInNamespace(namespace string, b *bc.BuildConfig) (*bc.BuildConfig, error)
	CreateDeployConfigInNamespace(namespace string, d *dc.DeploymentConfig) (*dc.DeploymentConfig, error)
	CreateSecretInNamespace(namespace string, s *k8api.Secret) (*k8api.Secret, error)
	CreatePersistentVolumeClaim(namespace string, claim *k8api.PersistentVolumeClaim) (*k8api.PersistentVolumeClaim, error)
	CreateJobToWatch(j *batch.Job, ns string) (watch.Interface, error)
	CreatePod(ns string, p *k8api.Pod) (*k8api.Pod, error)
	UpdateBuildConfigInNamespace(namespace string, b *bc.BuildConfig) (*bc.BuildConfig, error)
	UpdateDeployConfigInNamespace(ns string, d *dc.DeploymentConfig) (*dc.DeploymentConfig, error)
	UpdateRouteInNamespace(ns string, r *roapi.Route) (*roapi.Route, error)
	InstantiateBuild(ns, buildName string) (*bc.Build, error)
	FindDeploymentConfigsByLabel(ns string, searchLabels map[string]string) ([]dc.DeploymentConfig, error)
	FindServiceByLabel(ns string, searchLabels map[string]string) ([]k8api.Service, error)
	FindJobByName(ns, name string) (*batch.Job, error)
	FindRouteByName(ns, name string) (*route.Route, error)
	FindConfigMapByName(ns, name string) (*k8api.ConfigMap, error)
	FindBuildConfigByLabel(ns string, searchLabels map[string]string) (*bc.BuildConfig, error)
	GetDeploymentConfigByName(ns, deploymentName string) (*dc.DeploymentConfig, error)
	DeployLogURL(ns, dc string) string
	BuildConfigLogURL(ns, dc string) string
	BuildURL(ns, bc, id string) string
	GetDeployLogs(ns, deployName string) (string, error)
}

Client is the interface this controller expects for interacting with an openshift paas TODO break this up it is getting too big perhaps into finder, creater updater interfaces

type Configuration

type Configuration struct {
	DeploymentName string
	NameSpace      string
	Action         string
	InstanceID     string
}

Configuration encapsulates information needed to configure a service

type ConfigurationFactory

type ConfigurationFactory struct {
	StatusPublisher StatusPublisher
	TemplateLoader  TemplateLoader
	Logger          log.Logger
}

ConfigurationFactory is responsible for finding the right implementation of the Configurer interface and returning it to all the configuration of the environment

func (*ConfigurationFactory) Factory

func (cf *ConfigurationFactory) Factory(service string, config *Configuration, wait *sync.WaitGroup) Configurer

Factory is called to get a new Configurer based on the service type

func (*ConfigurationFactory) Publisher

func (cf *ConfigurationFactory) Publisher(publisher StatusPublisher)

Publisher allows us to set the StatusPublisher for the Configurers

type Configurer

type Configurer interface {
	Configure(client Client, deployment *dc.DeploymentConfig, namespace string) (*dc.DeploymentConfig, error)
}

Configurer defines what an environment Configurer should look like

type Controller

type Controller struct {
	TemplateDecoder         TemplateDecoder
	Logger                  log.Logger
	ConfigurationController *EnvironmentServiceConfigController
	// contains filtered or unexported fields
}

Controller handle deploy templates to OSCP

func New

func New(tl TemplateLoader, td TemplateDecoder, logger log.Logger, configuration *EnvironmentServiceConfigController, statusPublisher StatusPublisher) *Controller

New returns a new Controller

func (Controller) Template

func (c Controller) Template(client Client, template, nameSpace string, payload *Payload) (*Dispatched, error)

Template deploys a set of objects based on an OSCP Template Object. Templates are located in resources/templates

type DataMongoConfigure

type DataMongoConfigure struct {
	StatusPublisher StatusPublisher

	TemplateLoader TemplateLoader
	// contains filtered or unexported fields
}

DataMongoConfigure is a object for configuring mongo connection strings

func (*DataMongoConfigure) Configure

func (d *DataMongoConfigure) Configure(client Client, deployment *dc.DeploymentConfig, namespace string) (*dc.DeploymentConfig, error)

Configure takes an apps DeployConfig and sets of a job to create a new user and database in the mongodb data service. It also sets the expected env var FH_MONGODB_CONN_URL on the apps DeploymentConfig so it can be used to connect to the data service

type DataMysqlConfigure

type DataMysqlConfigure struct {
	StatusPublisher StatusPublisher

	TemplateLoader TemplateLoader
	// contains filtered or unexported fields
}

DataMysqlConfigure is a object for configuring mysql connection variables

func (*DataMysqlConfigure) Configure

func (d *DataMysqlConfigure) Configure(client Client, deployment *dc.DeploymentConfig, namespace string) (*dc.DeploymentConfig, error)

Configure the mysql connection vars here

type Dispatched

type Dispatched struct {
	// WatchURL is the url used to watch and stream the logs of a deployment or build
	WatchURL string       `json:"watchURL"`
	Route    *roapi.Route `json:"route"`
	// BuildURL is the url used to get the status of a build
	BuildURL string `json:"buildURL"`

	DeploymentName   string            `json:"deploymentName"`
	DeploymentLabels map[string]string `json:"deploymentLabels"`
	//instanceID is used to identify a particular service instance. It is set as the namespace + deploymentName for the service
	InstanceID string `json:"instanceID"`
	//Operation can be provision/deprovision/update/
	Operation string `json:"operation"`
}

Dispatched represents what is returned when a deploy dispatches sucessfully

type EnvVar

type EnvVar struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

EnvVar defines an environment variables name and value

type EnvironmentServiceConfigController

type EnvironmentServiceConfigController struct {
	ConfigurationFactory ServiceConfigFactory
	StatusPublisher      StatusPublisher
	// contains filtered or unexported fields
}

EnvironmentServiceConfigController controlls the configuration of environments and services

func NewEnvironmentServiceConfigController

func NewEnvironmentServiceConfigController(configFactory ServiceConfigFactory, log log.Logger, publisher StatusPublisher, tl TemplateLoader) *EnvironmentServiceConfigController

NewEnvironmentServiceConfigController returns a new EnvironmentServiceConfigController

func (*EnvironmentServiceConfigController) Configure

func (cac *EnvironmentServiceConfigController) Configure(client Client, config *Configuration) error

Configure is called to configure the DeploymentConfig of a service that is currently being deployed

type ErrInvalid

type ErrInvalid struct {
	// contains filtered or unexported fields
}

ErrInvalid is returned when something invalid happens

func (ErrInvalid) Error

func (e ErrInvalid) Error() string

type Payload

type Payload struct {
	ServiceName  string                 `json:"serviceName"`
	Route        string                 `json:"route"`
	ProjectGUID  string                 `json:"projectGuid"`
	CloudAppGUID string                 `json:"cloudAppGuid"`
	Domain       string                 `json:"domain"`
	Env          string                 `json:"env"`
	Replicas     int                    `json:"replicas"`
	EnvVars      []*EnvVar              `json:"envVars"`
	Repo         *Repo                  `json:"repo"`
	Target       *Target                `json:"target"`
	Options      map[string]interface{} `json:"options"`
}

Payload represents a deployment payload

func (Payload) Validate

func (p Payload) Validate(template string) error

Validate validates a payload

type PushApplication

type PushApplication struct {
	PushApplicationID string `json:"pushApplicationID"`
	MasterSecret      string `json:"masterSecret"`
	Name              string `json:"name"`
}

type PushUpsConfigure

type PushUpsConfigure struct {
	StatusPublisher StatusPublisher
	TemplateLoader  TemplateLoader

	PushLister func(host, user, password string) ([]*PushApplication, error)
	// contains filtered or unexported fields
}

PushUpsConfigure is an object for configuring push connection variables

func (*PushUpsConfigure) Configure

func (p *PushUpsConfigure) Configure(client Client, deployment *dc.DeploymentConfig, namespace string) (*dc.DeploymentConfig, error)

Configure the Push vars here

type Repo

type Repo struct {
	Loc  string `json:"loc"`
	Ref  string `json:"ref"`
	Auth struct {
		AuthType string `json:"authType"` //basic or ssh
		User     string `json:"user"`
		Key      string `json:"key"`
	} `json:"auth"`
}

Repo represents a git Repo

type ServiceConfigFactory

type ServiceConfigFactory interface {
	Factory(serviceName string, config *Configuration, wait *sync.WaitGroup) Configurer
	Publisher(publisher StatusPublisher)
}

ServiceConfigFactory creates service configs todo: improve this comment

type StatusPublisher

type StatusPublisher interface {
	Publish(key string, status, description string) error
	Clear(key string) error
}

StatusPublisher defines what a status publisher should implement

type Target

type Target struct {
	Host  string `json:"host"`
	Token string `json:"token"`
}

Target is part of a Payload to deploy it is the target OSCP

type Template

type Template struct {
	*api.Template
}

Template wraps the OpenShift template to give us some domain specific logic

type TemplateDecoder

type TemplateDecoder interface {
	Decode(template []byte) (*Template, error)
}

TemplateDecoder defines how deploy wants to decode the templates into data structures

type TemplateLoader

type TemplateLoader interface {
	Load(name string) (*template.Template, error)
	ListServices() ([]*Template, error)
	FindInTemplate(t *api.Template, resource string) (interface{}, error)
}

TemplateLoader defines how deploy wants to load templates in order to be able to deploy them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL