Skip to content

Commit

Permalink
fix: add Closed phase for execution context
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujian7 committed Aug 20, 2019
1 parent e408f15 commit ce96b27
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
25 changes: 14 additions & 11 deletions pkg/server/apis/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,27 +251,27 @@ type StorageCleanup struct {

// ExecutionContextSpec describes the execution context
type ExecutionContextSpec struct {
Cluster string `json:"cluster"`
Namespace string `json:"namespace"`
Integration string `json:"integration"`
PVC string `json:"pvc"`
Cluster string `json:"cluster"`
Namespace string `json:"namespace"`
PVC string `json:"pvc"`
}

// ExecutionContextStatus describe the status of execution context, it contains information that affects
// pipeline execution, like reserved resources, pvc status.
type ExecutionContextStatus struct {
// Phase of the execution context, could be 'Ready', 'NotReady' or 'Unknown'
Phase ExecutionContextPhase `json:"phase"`
ReservedResources map[core_v1.ResourceName]string `json:"reservedResources"`
PVC *core_v1.PersistentVolumeClaimStatus `json:"pvc"`
Phase ExecutionContextPhase `json:"phase"`
// ReservedResources indicate resources that will be used by system components, like pvc watcher, and
// can not be used by workflows execution.
ReservedResources map[core_v1.ResourceName]string `json:"reservedResources"`
// PVC describes status of PVC
PVC *core_v1.PersistentVolumeClaimStatus `json:"pvc"`
}

// ExecutionContext represtents a context used to execute workflows.
type ExecutionContext struct {
// Metadata for the particular object, including name, namespace, labels, etc
meta_v1.ObjectMeta `json:"metadata,omitempty"`
Spec ExecutionContextSpec `json:"spec"`
Status ExecutionContextStatus `json:"status"`
Spec ExecutionContextSpec `json:"spec"`
Status ExecutionContextStatus `json:"status"`
}

// ExecutionContextPhase represents the phase of ExecutionContext.
Expand All @@ -284,4 +284,7 @@ const (
ExecutionContextNotReady ExecutionContextPhase = "NotReady"
// ExecutionContextNotUnknown is unknown phase
ExecutionContextNotUnknown ExecutionContextPhase = "Unknown"
// ExecutionContextClosed is closed phase; if you want to use a closed execution context, you need to
// open the related cluster integration firstly.
ExecutionContextClosed ExecutionContextPhase = "Closed"
)
27 changes: 15 additions & 12 deletions pkg/server/handler/v1alpha1/executioncontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,30 @@ func ListExecutionContexts(ctx context.Context, tenant string) (*types.ListRespo

executionContext := api.ExecutionContext{
Spec: api.ExecutionContextSpec{
Integration: integration.Name,
Cluster: cluster.ClusterName,
Namespace: cluster.Namespace,
PVC: pvcName,
Cluster: cluster.ClusterName,
Namespace: cluster.Namespace,
PVC: pvcName,
},
Status: api.ExecutionContextStatus{
Phase: api.ExecutionContextNotUnknown,
ReservedResources: config.Config.StorageUsageWatcher.ResourceRequirements,
},
}

pvcStatus, err := getPVCStatus(tenant, pvcName, cluster)
if err != nil {
log.Warningf("Get PVC status in %s/%s", cluster.ClusterName, cluster.Namespace)
} else {
executionContext.Status.PVC = pvcStatus
if pvcStatus.Phase == "Bound" {
executionContext.Status.Phase = api.ExecutionContextReady
if cluster.IsWorkerCluster {
pvcStatus, err := getPVCStatus(tenant, pvcName, cluster)
if err != nil {
log.Warningf("Get PVC status in %s/%s", cluster.ClusterName, cluster.Namespace)
} else {
executionContext.Status.Phase = api.ExecutionContextNotReady
executionContext.Status.PVC = pvcStatus
if pvcStatus.Phase == corev1.ClaimBound {
executionContext.Status.Phase = api.ExecutionContextReady
} else {
executionContext.Status.Phase = api.ExecutionContextNotReady
}
}
} else {
executionContext.Status.Phase = api.ExecutionContextClosed
}

executionContexts = append(executionContexts, executionContext)
Expand Down

0 comments on commit ce96b27

Please sign in to comment.