From 8ac3142b12a3a62b83e1a469e0c23ed9b59ddac4 Mon Sep 17 00:00:00 2001 From: Aslak Knutsen Date: Thu, 24 Sep 2020 13:41:28 +0200 Subject: [PATCH] feat(client): allow client to wait for different conditions based on 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 --- pkg/internal/session/session.go | 34 ++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/pkg/internal/session/session.go b/pkg/internal/session/session.go index 4ef1e55d2..e9f7c872b 100644 --- a/pkg/internal/session/session.go +++ b/pkg/internal/session/session.go @@ -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. @@ -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