Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 47 additions & 49 deletions pkg/deploy/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)

// A Deployment represents a single unique realization of a DeploymentConfig.
type Deployment struct {
api.JSONBase `json:",inline" yaml:",inline"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Strategy DeploymentStrategy `json:"strategy,omitempty" yaml:"strategy,omitempty"`
ControllerTemplate api.ReplicationControllerState `json:"controllerTemplate,omitempty" yaml:"controllerTemplate,omitempty"`
Status DeploymentStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

// A DeploymentList is a collection of deployments.
type DeploymentList struct {
api.JSONBase `json:",inline" yaml:",inline"`
Items []Deployment `json:"items,omitempty" yaml:"items,omitempty"`
}

// DeploymentStatus decribes the possible states a Deployment can be in.
type DeploymentStatus string

const (
DeploymentStatusNew DeploymentStatus = "New"
DeploymentStatusPending DeploymentStatus = "Pending"
DeploymentStatusRunning DeploymentStatus = "Running"
DeploymentStatusComplete DeploymentStatus = "Complete"
DeploymentStatusFailed DeploymentStatus = "Failed"
)

// DeploymentConfigIDLabel is the key of a Deployment label whose value is the ID of a DeploymentConfig
// on which the Deployment is based.
const DeploymentConfigIDLabel = "deploymentConfigID"

// CustomPodDeploymentStrategy describes a deployment carried out by a custom pod.
type CustomPodDeploymentStrategy struct {
Image string `json:"image,omitempty" yaml:"image,omitempty"`
Expand All @@ -16,39 +46,30 @@ type DeploymentStrategy struct {
CustomPod *CustomPodDeploymentStrategy `json:"customPod,omitempty" yaml:"customPod,omitempty"`
}

// DeploymentTemplate contains all the necessary information to create a Deployment from a
// DeploymentStrategy.
type DeploymentTemplate struct {
Strategy DeploymentStrategy `json:"strategy,omitempty" yaml:"strategy,omitempty"`
ControllerTemplate api.ReplicationControllerState `json:"controllerTemplate,omitempty" yaml:"controllerTemplate,omitempty"`
// DeploymentConfig represents a configuration for a single deployment of a replication controller:
// what the template for the deployment, how new deployments are triggered, what the current
// deployed state is.
type DeploymentConfig struct {
api.JSONBase `json:",inline" yaml:",inline"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Triggers []DeploymentTriggerPolicy `json:"triggers,omitempty" yaml:"triggers,omitempty"`
Template DeploymentTemplate `json:"template,omitempty" yaml:"template,omitempty"`
LatestVersion int `json:"latestVersion,omitempty" yaml:"latestVersion,omitempty"`
}

// DeploymentState decribes the possible states a Deployment can be in.
type DeploymentState string

// TODO: review which of these states are needed.
const (
DeploymentStateNew DeploymentState = "New"
DeploymentStatePending DeploymentState = "Pending"
DeploymentStateRunning DeploymentState = "Running"
DeploymentStateComplete DeploymentState = "Complete"
DeploymentStateFailed DeploymentState = "Failed"
DeploymentStateCancelled DeploymentState = "Cancelled"
)
// A DeploymentConfigList is a collection of deployment configs
type DeploymentConfigList struct {
api.JSONBase `json:",inline" yaml:",inline"`
Items []DeploymentConfig `json:"items,omitempty" yaml:"items,omitempty"`
}

// A Deployment represents a single unique realization of a DeploymentConfig.
type Deployment struct {
api.JSONBase `json:",inline" yaml:",inline"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
// DeploymentTemplate contains all the necessary information to create a Deployment from a
// DeploymentStrategy.
type DeploymentTemplate struct {
Strategy DeploymentStrategy `json:"strategy,omitempty" yaml:"strategy,omitempty"`
ControllerTemplate api.ReplicationControllerState `json:"controllerTemplate,omitempty" yaml:"controllerTemplate,omitempty"`
State DeploymentState `json:"state,omitempty" yaml:"state,omitempty"`
}

// DeploymentConfigIDLabel is the key of a Deployment label whose value is the ID of a DeploymentConfig
// on which the Deployment is based.
const DeploymentConfigIDLabel = "deploymentConfigID"

// DeploymentTriggerPolicy describes a policy for a single trigger that results in a new Deployment.
type DeploymentTriggerPolicy struct {
Type DeploymentTriggerType `json:"type,omitempty" yaml:"type,omitempty"`
Expand All @@ -69,26 +90,3 @@ const (
DeploymentTriggerOnImageChange DeploymentTriggerType = "ImageChange"
DeploymentTriggerOnConfigChange DeploymentTriggerType = "ConfigChange"
)

// DeploymentConfig represents a configuration for a single deployment of a replication controller:
// what the template for the deployment, how new deployments are triggered, what the current
// deployed state is.
type DeploymentConfig struct {
api.JSONBase `json:",inline" yaml:",inline"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Triggers []DeploymentTriggerPolicy `json:"triggers,omitempty" yaml:"triggers,omitempty"`
Template DeploymentTemplate `json:"template,omitempty" yaml:"template,omitempty"`
LatestVersion int `json:"latestVersion,omitempty" yaml:"latestVersion,omitempty"`
}

// A DeploymentConfigList is a collection of deployment configs
type DeploymentConfigList struct {
api.JSONBase `json:",inline" yaml:",inline"`
Items []DeploymentConfig `json:"items,omitempty" yaml:"items,omitempty"`
}

// A DeploymentList is a collection of deployments.
type DeploymentList struct {
api.JSONBase `json:",inline" yaml:",inline"`
Items []Deployment `json:"items,omitempty" yaml:"items,omitempty"`
}
17 changes: 8 additions & 9 deletions pkg/deploy/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ type DeploymentTemplate struct {
ControllerTemplate api.ReplicationControllerState `json:"controllerTemplate,omitempty" yaml:"controllerTemplate,omitempty"`
}

// DeploymentState decribes the possible states a Deployment can be in.
type DeploymentState string
// DeploymentStatus decribes the possible states a Deployment can be in.
type DeploymentStatus string

// TODO: review which of these states are needed.
const (
DeploymentStateNew DeploymentState = "New"
DeploymentStatePending DeploymentState = "Pending"
DeploymentStateRunning DeploymentState = "Running"
DeploymentStateComplete DeploymentState = "Complete"
DeploymentStateFailed DeploymentState = "Failed"
DeploymentStateCancelled DeploymentState = "Cancelled"
DeploymentStatusNew DeploymentStatus = "New"
DeploymentStatusPending DeploymentStatus = "Pending"
DeploymentStatusRunning DeploymentStatus = "Running"
DeploymentStatusComplete DeploymentStatus = "Complete"
DeploymentStatusFailed DeploymentStatus = "Failed"
)

// A Deployment represents a single unique realization of a DeploymentConfig.
Expand All @@ -42,7 +41,7 @@ type Deployment struct {
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Strategy DeploymentStrategy `json:"strategy,omitempty" yaml:"strategy,omitempty"`
ControllerTemplate api.ReplicationControllerState `json:"controllerTemplate,omitempty" yaml:"controllerTemplate,omitempty"`
State DeploymentState `json:"state,omitempty" yaml:"state,omitempty"`
Status DeploymentStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

// DeploymentTriggerPolicy describes a policy for a single trigger that results in a new Deployment.
Expand Down
4 changes: 2 additions & 2 deletions pkg/deploy/client/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/openshift/origin/pkg/deploy/api"
)

var deploymentColumns = []string{"ID", "State"}
var deploymentColumns = []string{"ID", "Status"}
var deploymentConfigColumns = []string{"ID", "Triggers", "LatestVersion"}

// RegisterPrintHandlers registers human-readable printers for deploy types.
Expand All @@ -22,7 +22,7 @@ func RegisterPrintHandlers(printer *kubecfg.HumanReadablePrinter) {
}

func printDeployment(d *api.Deployment, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\n", d.ID, d.State)
_, err := fmt.Fprintf(w, "%s\t%s\n", d.ID, d.Status)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/deploy/controller/config_change_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func generatedConfig() *deployapi.DeploymentConfig {
func matchingInitialDeployment() *deployapi.Deployment {
return &deployapi.Deployment{
JSONBase: kapi.JSONBase{ID: "test-deploy-config-1"},
State: deployapi.DeploymentStateNew,
Status: deployapi.DeploymentStatusNew,
Strategy: deployapi.DeploymentStrategy{
Type: "customPod",
CustomPod: &deployapi.CustomPodDeploymentStrategy{
Expand Down
2 changes: 1 addition & 1 deletion pkg/deploy/controller/deployment_config_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func manualDeploymentConfig() *deployapi.DeploymentConfig {
func matchingDeployment() *deployapi.Deployment {
return &deployapi.Deployment{
JSONBase: kapi.JSONBase{ID: "manual-deploy-config-1"},
State: deployapi.DeploymentStateNew,
Status: deployapi.DeploymentStatusNew,
Strategy: deployapi.DeploymentStrategy{
Type: "customPod",
CustomPod: &deployapi.CustomPodDeploymentStrategy{
Expand Down
74 changes: 37 additions & 37 deletions pkg/deploy/controller/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,117 +36,117 @@ func (dc *DeploymentController) Run() {
func (dc *DeploymentController) HandleDeployment() error {
deployment := dc.NextDeployment()
ctx := kapi.WithNamespace(kapi.NewContext(), deployment.Namespace)
glog.Infof("Synchronizing deployment id: %v state: %v resourceVersion: %v", deployment.ID, deployment.State, deployment.ResourceVersion)

nextState := deployment.State
switch deployment.State {
case deployapi.DeploymentStateNew:
nextState = dc.handleNew(ctx, deployment)
case deployapi.DeploymentStatePending:
nextState = dc.handlePending(ctx, deployment)
case deployapi.DeploymentStateRunning:
nextState = dc.handleRunning(ctx, deployment)
glog.Infof("Synchronizing deployment id: %v status: %v resourceVersion: %v", deployment.ID, deployment.Status, deployment.ResourceVersion)

nextStatus := deployment.Status
switch deployment.Status {
case deployapi.DeploymentStatusNew:
nextStatus = dc.handleNew(ctx, deployment)
case deployapi.DeploymentStatusPending:
nextStatus = dc.handlePending(ctx, deployment)
case deployapi.DeploymentStatusRunning:
nextStatus = dc.handleRunning(ctx, deployment)
}

if deployment.State != nextState {
deployment.State = nextState
if deployment.Status != nextStatus {
deployment.Status = nextStatus
return dc.saveDeployment(ctx, deployment)
} else {
return nil
}
}

// Handler for a deployment in the 'new' state.
func (dc *DeploymentController) handleNew(ctx kapi.Context, deployment *deployapi.Deployment) deployapi.DeploymentState {
nextState := deployment.State
func (dc *DeploymentController) handleNew(ctx kapi.Context, deployment *deployapi.Deployment) deployapi.DeploymentStatus {
nextStatus := deployment.Status

deploymentPod := dc.makeDeploymentPod(deployment)
glog.Infof("Attempting to create deployment pod: %+v", deploymentPod)
if pod, err := dc.PodInterface.CreatePod(kapi.NewContext(), deploymentPod); err != nil {
glog.Warningf("Received error creating pod: %v", err)
nextState = deployapi.DeploymentStateFailed
nextStatus = deployapi.DeploymentStatusFailed
} else {
glog.Infof("Successfully created pod %+v", pod)
nextState = deployapi.DeploymentStatePending
nextStatus = deployapi.DeploymentStatusPending
}

return nextState
return nextStatus
}

// Handler for a deployment in the 'pending' state
func (dc *DeploymentController) handlePending(ctx kapi.Context, deployment *deployapi.Deployment) deployapi.DeploymentState {
nextState := deployment.State
func (dc *DeploymentController) handlePending(ctx kapi.Context, deployment *deployapi.Deployment) deployapi.DeploymentStatus {
nextStatus := deployment.Status

podID := deploymentPodID(deployment)
glog.Infof("Retrieving deployment pod id %s", podID)

pod, err := dc.PodInterface.GetPod(ctx, podID)
if err != nil {
glog.Errorf("Error retrieving pod for deployment ID %v: %#v", deployment.ID, err)
nextState = deployapi.DeploymentStateFailed
nextStatus = deployapi.DeploymentStatusFailed
} else {
glog.Infof("Deployment pod is %+v", pod)

switch pod.CurrentState.Status {
case kapi.PodRunning:
nextState = deployapi.DeploymentStateRunning
nextStatus = deployapi.DeploymentStatusRunning
case kapi.PodTerminated:
nextState = dc.checkForTerminatedDeploymentPod(deployment, pod)
nextStatus = dc.checkForTerminatedDeploymentPod(deployment, pod)
}
}

return nextState
return nextStatus
}

// Handler for a deployment in the 'running' state
func (dc *DeploymentController) handleRunning(ctx kapi.Context, deployment *deployapi.Deployment) deployapi.DeploymentState {
nextState := deployment.State
func (dc *DeploymentController) handleRunning(ctx kapi.Context, deployment *deployapi.Deployment) deployapi.DeploymentStatus {
nextStatus := deployment.Status

podID := deploymentPodID(deployment)
glog.Infof("Retrieving deployment pod id %s", podID)

pod, err := dc.PodInterface.GetPod(ctx, podID)
if err != nil {
glog.Errorf("Error retrieving pod for deployment ID %v: %#v", deployment.ID, err)
nextState = deployapi.DeploymentStateFailed
nextStatus = deployapi.DeploymentStatusFailed
} else {
glog.Infof("Deployment pod is %+v", pod)
nextState = dc.checkForTerminatedDeploymentPod(deployment, pod)
nextStatus = dc.checkForTerminatedDeploymentPod(deployment, pod)
}

return nextState
return nextStatus
}

func deploymentPodID(deployment *deployapi.Deployment) string {
return "deploy-" + deployment.ID
}

func (dc *DeploymentController) checkForTerminatedDeploymentPod(deployment *deployapi.Deployment, pod *kapi.Pod) deployapi.DeploymentState {
nextState := deployment.State
func (dc *DeploymentController) checkForTerminatedDeploymentPod(deployment *deployapi.Deployment, pod *kapi.Pod) deployapi.DeploymentStatus {
nextStatus := deployment.Status
if pod.CurrentState.Status != kapi.PodTerminated {
glog.Infof("The deployment has not yet finished. Pod status is %s. Continuing", pod.CurrentState.Status)
return nextState
return nextStatus
}

nextState = deployapi.DeploymentStateComplete
nextStatus = deployapi.DeploymentStatusComplete
for _, info := range pod.CurrentState.Info {
if info.State.Termination != nil && info.State.Termination.ExitCode != 0 {
nextState = deployapi.DeploymentStateFailed
nextStatus = deployapi.DeploymentStatusFailed
}
}

if nextState == deployapi.DeploymentStateComplete {
if nextStatus == deployapi.DeploymentStatusComplete {
podID := deploymentPodID(deployment)
glog.Infof("Removing deployment pod for ID %v", podID)
dc.PodInterface.DeletePod(kapi.NewContext(), podID)
}

glog.Infof("The deployment pod has finished. Setting deployment state to %s", deployment.State)
return nextState
glog.Infof("The deployment pod has finished. Setting deployment state to %s", deployment.Status)
return nextStatus
}

func (dc *DeploymentController) saveDeployment(ctx kapi.Context, deployment *deployapi.Deployment) error {
glog.Infof("Saving deployment %v state: %v", deployment.ID, deployment.State)
glog.Infof("Saving deployment %v status: %v", deployment.ID, deployment.Status)
_, err := dc.DeploymentInterface.UpdateDeployment(ctx, deployment)
if err != nil {
glog.Errorf("Received error while saving deployment %v: %v", deployment.ID, err)
Expand Down
Loading