Skip to content

Commit

Permalink
feat(client): allow client to wait for different conditions based on …
Browse files Browse the repository at this point in the history
…usage

In a normal cli setting we're looking for a Deployment or a DeploymentConfig,
but with the che integration the Deployment already exists so we need to be
able to wait for something else.

related to #528
  • Loading branch information
aslakknutsen committed Sep 24, 2020
1 parent 464bbbb commit 8ac3142
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions pkg/internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,30 @@ var (

// Options holds the variables used by the Session Handler.
type Options struct {
NamespaceName string // name of the namespace for target resource
DeploymentName string // name of the initial resource to target
SessionName string // name of the session create or join if exist
RouteExp string // expression of how to route the traffic to the target resource
Strategy string // name of the strategy to use for the target resource
StrategyArgs map[string]string // additional arguments for the strategy
Revert bool // Revert back to previous known value if join/leave a existing session with a known ref
Duration *time.Duration // Duration defines the interval used to check for changes to the session object
NamespaceName string // name of the namespace for target resource
DeploymentName string // name of the initial resource to target
SessionName string // name of the session create or join if exist
RouteExp string // expression of how to route the traffic to the target resource
Strategy string // name of the strategy to use for the target resource
StrategyArgs map[string]string // additional arguments for the strategy
Revert bool // Revert back to previous known value if join/leave a existing session with a known ref
Duration *time.Duration // Duration defines the interval used to check for changes to the session object
WaitCondition func(*istiov1alpha1.RefResource) bool // WaitCondition should return true when session is in a state to move on
}

// ConditionFound returns true if the RefResource is in a done state based on the WaitCondition. Defaults to defaultWaitCondition.
func (o *Options) ConditionFound(res *istiov1alpha1.RefResource) bool {
if o.WaitCondition == nil {
o.WaitCondition = defaultWaitCondition
}
return o.WaitCondition(res)
}

func defaultWaitCondition(res *istiov1alpha1.RefResource) bool {
if *res.Kind == "Deployment" || *res.Kind == "DeploymentConfig" {
return true
}
return false
}

// State holds the new variables as presented by the creation of the session.
Expand Down Expand Up @@ -185,7 +201,7 @@ func (h *handler) waitForRefToComplete() (*istiov1alpha1.Session, string, error)
for _, refs := range sessionStatus.Status.Refs {
if refs.Name == h.opts.DeploymentName {
for _, res := range refs.Resources {
if *res.Kind == "Deployment" || *res.Kind == "DeploymentConfig" {
if h.opts.ConditionFound(res) {
name = *res.Name
logger().Info("target found", *res.Kind, name)
return true, nil
Expand Down

0 comments on commit 8ac3142

Please sign in to comment.