From 8ac3142b12a3a62b83e1a469e0c23ed9b59ddac4 Mon Sep 17 00:00:00 2001 From: Aslak Knutsen Date: Thu, 24 Sep 2020 13:41:28 +0200 Subject: [PATCH 1/4] 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 From 116e2bd74dfa8c5b7a24e0b8ff84960ded0acadd Mon Sep 17 00:00:00 2001 From: Aslak Knutsen Date: Thu, 24 Sep 2020 15:04:30 +0200 Subject: [PATCH 2/4] Update pkg/internal/session/session.go Co-authored-by: Bartosz Majsak --- pkg/internal/session/session.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/internal/session/session.go b/pkg/internal/session/session.go index e9f7c872b..1d4ad700c 100644 --- a/pkg/internal/session/session.go +++ b/pkg/internal/session/session.go @@ -43,10 +43,7 @@ func (o *Options) ConditionFound(res *istiov1alpha1.RefResource) bool { } func defaultWaitCondition(res *istiov1alpha1.RefResource) bool { - if *res.Kind == "Deployment" || *res.Kind == "DeploymentConfig" { - return true - } - return false + return *res.Kind == "Deployment" || *res.Kind == "DeploymentConfig" } // State holds the new variables as presented by the creation of the session. From df6ca57d043355c65416dea7fa5cf320b489d27d Mon Sep 17 00:00:00 2001 From: Aslak Knutsen Date: Thu, 24 Sep 2020 16:41:35 +0200 Subject: [PATCH 3/4] lint --- pkg/internal/session/session.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/internal/session/session.go b/pkg/internal/session/session.go index 1d4ad700c..a3fda4119 100644 --- a/pkg/internal/session/session.go +++ b/pkg/internal/session/session.go @@ -6,11 +6,12 @@ import ( "strings" "time" + "github.com/go-logr/logr" + istiov1alpha1 "github.com/maistra/istio-workspace/pkg/apis/maistra/v1alpha1" "github.com/maistra/istio-workspace/pkg/log" "github.com/maistra/istio-workspace/pkg/naming" - "github.com/go-logr/logr" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" ) @@ -43,7 +44,7 @@ func (o *Options) ConditionFound(res *istiov1alpha1.RefResource) bool { } func defaultWaitCondition(res *istiov1alpha1.RefResource) bool { - return *res.Kind == "Deployment" || *res.Kind == "DeploymentConfig" + return *res.Kind == "Deployment" || *res.Kind == "DeploymentConfig" } // State holds the new variables as presented by the creation of the session. From f1e3928c063a48541a9c04bb238b35c9dd2b4872 Mon Sep 17 00:00:00 2001 From: Aslak Knutsen Date: Thu, 24 Sep 2020 16:57:03 +0200 Subject: [PATCH 4/4] fix: fix microk8s to 1.9 stable --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a99687e2e..60027ff1f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -199,7 +199,7 @@ jobs: - run: name: Launch Microk8s command: | - sudo snap install microk8s --classic --channel 1.19/candidate + sudo snap install microk8s --classic --channel 1.19/stable sudo microk8s.kubectl config view --raw > /tmp/kubeconfig export KUBECONFIG=/tmp/kubeconfig