-
Notifications
You must be signed in to change notification settings - Fork 7
Refactor: extract rollingUpdateFn for batching and customization #180
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
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,21 +104,20 @@ func RepeatJobWithPod(ctx context.Context, kubeCfgPath string, namespace string, | |
} | ||
} | ||
|
||
// DeployAndRepeatRollingUpdateDeployments deploys and repeats to rolling-update deployments. | ||
func DeployAndRepeatRollingUpdateDeployments( | ||
// DeployDeployments deploys deployments. | ||
func DeployDeployments( | ||
ctx context.Context, | ||
kubeCfgPath string, | ||
releaseName string, | ||
total, replica, paddingBytes int, | ||
internal time.Duration, | ||
) (rollingUpdateFn, cleanupFn func(), retErr error) { | ||
) (cleanupFn func(), retErr error) { | ||
infoLogger := log.GetLogger(ctx).WithKeyValues("level", "info") | ||
warnLogger := log.GetLogger(ctx).WithKeyValues("level", "warn") | ||
|
||
target := "workload/deployments" | ||
ch, err := manifests.LoadChart(target) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to load %s chart: %w", target, err) | ||
return nil, fmt.Errorf("failed to load %s chart: %w", target, err) | ||
} | ||
|
||
namePattern := releaseName | ||
|
@@ -139,7 +138,7 @@ func DeployAndRepeatRollingUpdateDeployments( | |
), | ||
) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to create a new helm release cli: %w", err) | ||
return nil, fmt.Errorf("failed to create a new helm release cli: %w", err) | ||
} | ||
|
||
infoLogger.LogKV( | ||
|
@@ -153,9 +152,9 @@ func DeployAndRepeatRollingUpdateDeployments( | |
if err != nil { | ||
if errors.Is(err, context.Canceled) { | ||
infoLogger.LogKV("msg", "deploy is canceled") | ||
return func() {}, func() {}, nil | ||
return func() {}, nil | ||
} | ||
return nil, nil, fmt.Errorf("failed to deploy helm chart %s: %w", target, err) | ||
return nil, fmt.Errorf("failed to deploy helm chart %s: %w", target, err) | ||
} | ||
infoLogger.LogKV("msg", "deployed deployments") | ||
|
||
|
@@ -169,45 +168,48 @@ func DeployAndRepeatRollingUpdateDeployments( | |
} | ||
} | ||
|
||
rollingUpdateFn = func() { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
infoLogger.LogKV("msg", "stop rolling-updating") | ||
return | ||
case <-time.After(internal): | ||
} | ||
return cleanupFn, nil | ||
} | ||
|
||
infoLogger.LogKV("msg", "start to rolling-update deployments") | ||
for i := 0; i < total; i++ { | ||
name := fmt.Sprintf("%s-%d", namePattern, i) | ||
ns := name | ||
func RollingUpdateDeployments(ctx context.Context, total int, namePattern string, kubeCfgPath string, internal time.Duration) { | ||
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. not blocker: you can help it in the follow-up func RollingUpdateDeployments(ctx context.Context, kubeCfgPath string, namePattern string, total int, internal time.Duration) |
||
infoLogger := log.GetLogger(ctx).WithKeyValues("level", "info") | ||
warnLogger := log.GetLogger(ctx).WithKeyValues("level", "warn") | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
infoLogger.LogKV("msg", "stop rolling-updating") | ||
return | ||
case <-time.After(internal): | ||
} | ||
|
||
infoLogger.LogKV("msg", "rolling-update deployment", "name", name, "namespace", ns) | ||
err := func() error { | ||
kr := NewKubectlRunner(kubeCfgPath, ns) | ||
infoLogger.LogKV("msg", "start to rolling-update deployments") | ||
for i := range total { | ||
name := fmt.Sprintf("%s-%d", namePattern, i) | ||
ns := name | ||
|
||
err := kr.DeploymentRestart(ctx, 2*time.Minute, name) | ||
if err != nil { | ||
return fmt.Errorf("failed to restart deployment %s: %w", name, err) | ||
} | ||
infoLogger.LogKV("msg", "rolling-update deployment", "name", name, "namespace", ns) | ||
err := func() error { | ||
kr := NewKubectlRunner(kubeCfgPath, ns) | ||
|
||
err = kr.DeploymentRolloutStatus(ctx, 10*time.Minute, name) | ||
if err != nil { | ||
return fmt.Errorf("failed to watch the rollout status of deployment %s: %w", name, err) | ||
} | ||
return nil | ||
}() | ||
err := kr.DeploymentRestart(ctx, 2*time.Minute, name) | ||
if err != nil { | ||
warnLogger.LogKV("msg", "failed to rolling-update", | ||
"error", err, | ||
"deployment", name, | ||
"namespace", ns) | ||
return fmt.Errorf("failed to restart deployment %s: %w", name, err) | ||
} | ||
|
||
err = kr.DeploymentRolloutStatus(ctx, 10*time.Minute, name) | ||
if err != nil { | ||
return fmt.Errorf("failed to watch the rollout status of deployment %s: %w", name, err) | ||
} | ||
return nil | ||
}() | ||
if err != nil { | ||
warnLogger.LogKV("msg", "failed to rolling-update", | ||
"error", err, | ||
"deployment", name, | ||
"namespace", ns) | ||
} | ||
} | ||
} | ||
return rollingUpdateFn, cleanupFn, nil | ||
} | ||
|
||
// NewRunnerGroupSpecFromYAML returns RunnerGroupSpec instance from yaml data. | ||
|
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.