-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[installer] make sure dashboard is deployed after server and papi-server #19042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8857387
[installer] make sure dashboard is deployed after server and papi-server
mustard-mh 71d7918
fix build
mustard-mh d299722
Add unit tests
mustard-mh efc8c90
address feedback
mustard-mh a5b3cce
wait feature flag until get actual value of timed out
mustard-mh cc4cca0
default config cat client nil
mustard-mh 5960757
log avg fetch time
mustard-mh 2518798
1
mustard-mh e1dcb63
mock feature flag hang
mustard-mh 198d71d
Add metric
mustard-mh c6aa11c
fixup
mustard-mh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,24 +7,31 @@ package cmd | |
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/gitpod-io/gitpod/common-go/experiments" | ||
"github.com/gitpod-io/gitpod/common-go/log" | ||
"github.com/gitpod-io/gitpod/service-waiter/pkg/metrics" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
var componentCmdOpt struct { | ||
image string | ||
namespace string | ||
component string | ||
labels string | ||
image string | ||
namespace string | ||
component string | ||
labels string | ||
ideMetricsHost string | ||
gitpodHost string | ||
|
||
featureFlagTimeout time.Duration | ||
} | ||
|
||
var componentCmd = &cobra.Command{ | ||
|
@@ -46,6 +53,8 @@ var componentCmd = &cobra.Command{ | |
ctx, cancel := context.WithTimeout(cmd.Context(), timeout) | ||
defer cancel() | ||
|
||
go startWaitFeatureFlag(ctx, componentCmdOpt.featureFlagTimeout) | ||
|
||
err := waitPodsImage(ctx) | ||
|
||
if err != nil { | ||
|
@@ -56,6 +65,8 @@ var componentCmd = &cobra.Command{ | |
}, | ||
} | ||
|
||
var shouldSkipComponentWaiter bool = false | ||
|
||
func checkPodsImage(ctx context.Context, k8sClient *kubernetes.Clientset) (bool, error) { | ||
pods, err := k8sClient.CoreV1().Pods(componentCmdOpt.namespace).List(ctx, metav1.ListOptions{ | ||
LabelSelector: componentCmdOpt.labels, | ||
|
@@ -107,6 +118,10 @@ func waitPodsImage(ctx context.Context) error { | |
} | ||
return ctx.Err() | ||
default: | ||
if shouldSkipComponentWaiter { | ||
log.Infof("skip component waiter %s with Feature Flag", componentCmdOpt.component) | ||
return nil | ||
} | ||
ok, err := checkPodsImage(ctx, k8sClient) | ||
if err != nil { | ||
log.WithError(err).Error("image check failed") | ||
|
@@ -127,8 +142,75 @@ func init() { | |
componentCmd.Flags().StringVar(&componentCmdOpt.namespace, "namespace", "", "The namespace of deployment") | ||
componentCmd.Flags().StringVar(&componentCmdOpt.component, "component", "", "Component name of deployment") | ||
componentCmd.Flags().StringVar(&componentCmdOpt.labels, "labels", "", "Labels of deployment") | ||
componentCmd.Flags().StringVar(&componentCmdOpt.ideMetricsHost, "ide-metrics-host", "", "Host of ide metrics") | ||
componentCmd.Flags().DurationVar(&componentCmdOpt.featureFlagTimeout, "feature-flag-timeout", 3*time.Minute, "The maximum time to wait for feature flag") | ||
akosyakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
componentCmd.Flags().StringVar(&componentCmdOpt.gitpodHost, "gitpod-host", "", "Domain of Gitpod installation") | ||
|
||
_ = componentCmd.MarkFlagRequired("namespace") | ||
_ = componentCmd.MarkFlagRequired("component") | ||
_ = componentCmd.MarkFlagRequired("labels") | ||
} | ||
|
||
func startWaitFeatureFlag(ctx context.Context, timeout time.Duration) { | ||
featureFlagCtx, cancel := context.WithTimeout(ctx, timeout) | ||
defer cancel() | ||
client := experiments.NewClient(experiments.WithDefaultClient(nil), experiments.WithPollInterval(time.Second*3)) | ||
defaultSkip := true | ||
if client == nil { | ||
log.Error("failed to create experiments client, skip immediately") | ||
shouldSkipComponentWaiter = defaultSkip | ||
metrics.AddSkipComponentsCounter(componentCmdOpt.ideMetricsHost, strconv.FormatBool(shouldSkipComponentWaiter), false) | ||
return | ||
} | ||
getShouldSkipComponentWaiter := func() { | ||
startTime := time.Now() | ||
value, isActualValue, fetchTimes := ActualWaitFeatureFlag(featureFlagCtx, client, defaultSkip) | ||
avgTime := time.Duration(0) | ||
if fetchTimes > 0 { | ||
avgTime = time.Since(startTime) / time.Duration(fetchTimes) | ||
} | ||
log.WithField("fetchTimes", fetchTimes).WithField("avgTime", avgTime).WithField("isActualValue", isActualValue).WithField("value", value).Info("get final value of feature flag") | ||
shouldSkipComponentWaiter = value | ||
metrics.AddSkipComponentsCounter(componentCmdOpt.ideMetricsHost, strconv.FormatBool(shouldSkipComponentWaiter), isActualValue) | ||
} | ||
for !shouldSkipComponentWaiter { | ||
if featureFlagCtx.Err() != nil { | ||
break | ||
} | ||
getShouldSkipComponentWaiter() | ||
time.Sleep(1 * time.Second) | ||
} | ||
} | ||
|
||
var FeatureSleepDuration = 1 * time.Second | ||
|
||
func ActualWaitFeatureFlag(ctx context.Context, client experiments.Client, defaultValue bool) (flagValue bool, ok bool, fetchTimes int) { | ||
if client == nil { | ||
return defaultValue, false, fetchTimes | ||
} | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
log.WithField("defaultValue", defaultValue).Info("feature flag timeout with no expected value, fallback") | ||
return defaultValue, false, fetchTimes | ||
default: | ||
stringValue := client.GetStringValue(ctx, experiments.ServiceWaiterSkipComponentsFlag, "NONE", experiments.Attributes{ | ||
GitpodHost: componentCmdOpt.gitpodHost, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧡 |
||
Component: componentCmdOpt.component, | ||
}) | ||
fetchTimes++ | ||
if stringValue == "true" { | ||
return true, true, fetchTimes | ||
} | ||
if stringValue == "false" { | ||
return false, true, fetchTimes | ||
} | ||
if stringValue == "NONE" { | ||
time.Sleep(FeatureSleepDuration) | ||
continue | ||
} | ||
log.WithField("value", stringValue).Warn("unexpected value from feature flag") | ||
time.Sleep(FeatureSleepDuration) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.