Skip to content
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

fix: upgrade hook job npe #8780

Open
wants to merge 1 commit into
base: release-0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/helmhook/hook/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ func GetKubeBlocksDeploy(ctx context.Context, client *kubernetes.Clientset, ns s
return &deployments.Items[0], nil
}

// IgnoreKubeblocksHook checks if KubeBlocks deployment exists.
func IgnoreKubeblocksHook(ctx context.Context, client *kubernetes.Clientset, ns string) bool {
deploy, err := GetKubeBlocksDeploy(ctx, client, ns, kubeblocksAppComponent)
if err != nil {
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook will continue running if an error occurs (e.g. network errors). Is it an expected behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is expected. If an error occurs, it should be handled by hook job. The hook job may be processed successfully, or it may fail and try again.

The only case in which upgrading can be ignored: the kubeblocks component is not deployed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but if a network error occurs, you will not know whether the deployment exists. It would be better to return this error to main() and exit quickly.

}
return deploy == nil
}

// deleteDeployment deletes deployment.
func deleteDeployment(ctx context.Context, client *kubernetes.Clientset, ns, componentName string, getter deploymentGetter) error {
deploy, err := getter(ctx, client, ns, componentName)
Expand Down
5 changes: 5 additions & 0 deletions cmd/helmhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func main() {
hook.CheckErr(err)

upgradeContext := hook.NewUpgradeContext(ctx, config, version, crdPath, namespace)
// If KubeBlocks deployment does not exist, ignore the hook.
if hook.IgnoreKubeblocksHook(ctx, upgradeContext.K8sClient, namespace) {
return
}

hook.CheckErr(hook.NewUpgradeWorkflow().
WrapStage(hook.PrepareFor).
AddStage(&hook.StopOperator{}).
Expand Down
Loading