Skip to content

Conversation

@hsri-pf9
Copy link
Collaborator

@hsri-pf9 hsri-pf9 commented Jul 15, 2025

Made changes in the host_reconciler.go and reconciler_test.go to have the proper functionality and unit tests for the installation and uninstallation secret.

Summary by Bito

This PR enhances the host reconciler by fixing issues in installation and uninstallation secrets handling. It refines unit tests, modifies patch helper operations, and improves script parsing and execution logic while adding better logging and error reporting. The changes increase system robustness and provide clearer diagnostics during failures.

@bito-code-review
Copy link

bito-code-review bot commented Jul 15, 2025

Code Review Agent Run #15e4cb

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: dbc5447..dbc5447
    • agent/reconciler/host_reconciler.go
    • agent/reconciler/reconciler_test.go
    • controllers/infrastructure/k8sinstallerconfig_controller.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review
Copy link

bito-code-review bot commented Jul 15, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Bug Fix - Secret Handling and Functionality Fix

host_reconciler.go - Refined secret processing for install/uninstall scripts with improved error handling and logging.

k8sinstallerconfig_controller.go - Renamed the function to store installation and uninstallation data, clarifying the secret storage process.

Testing - Unit Test and Debug Enhancements

host_agent_suite_test.go - Added debug statements to verify kubeconfig operations and enhanced PEM decoding validation in tests.

host_agent_test.go - Included additional import changes and minor tweaks to support updated testing configurations.

reconciler_test.go - Updated unit test expectations and warning messages, refined patch operations, and ensured consistent handling of secret scenarios in tests.

Copy link

@sebastian-pf9 sebastian-pf9 left a comment

Choose a reason for hiding this comment

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

lgtm, but I have no deep insights if this makes sense

byoHostLookupKey types.NamespacedName
bootstrapSecret *corev1.Secret
installationSecret *corev1.Secret
uninstallationSecret *corev1.Secret // <-- add this

Choose a reason for hiding this comment

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

Suggested change
uninstallationSecret *corev1.Secret // <-- add this
uninstallationSecret *corev1.Secret

@bito-code-review
Copy link

bito-code-review bot commented Jul 15, 2025

Code Review Agent Run #e06a4a

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: dbc5447..04cda70
    • agent/reconciler/reconciler_test.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review
Copy link

bito-code-review bot commented Jul 16, 2025

Code Review Agent Run #8ed0b0

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 04cda70..883e96b
    • agent/reconciler/reconciler_test.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review
Copy link

bito-code-review bot commented Jul 18, 2025

Bito Review Skipped - No Changes Detected

Bito didn't review this pull request because we did not detect any changes in the pull request to review.

Copy link

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

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

Code Review Agent Run #158647

Actionable Suggestions - 1
  • agent/host_agent_suite_test.go - 1
Review Details
  • Files reviewed - 1 · Commit Range: 883e96b..93f19bd
    • agent/host_agent_suite_test.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +156 to +161
configObj, err := clientcmd.LoadFromFile(getKubeConfig().Name())
Expect(err).NotTo(HaveOccurred())
userObj := configObj.AuthInfos["envtest"]
printDecodedPEM := func(field string, data []byte) {
decoded, err := base64.StdEncoding.DecodeString(string(data))
if err != nil {

Choose a reason for hiding this comment

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

Incorrect user name in kubeconfig access

The code assumes the user name is 'envtest' but it's actually 'envtest-admin' as set in line 135. This will cause the PEM decoding to fail as it's looking for the wrong user in the kubeconfig.

Code suggestion
Check the AI-generated fix before applying
Suggested change
configObj, err := clientcmd.LoadFromFile(getKubeConfig().Name())
Expect(err).NotTo(HaveOccurred())
userObj := configObj.AuthInfos["envtest"]
printDecodedPEM := func(field string, data []byte) {
decoded, err := base64.StdEncoding.DecodeString(string(data))
if err != nil {
configObj, err := clientcmd.LoadFromFile(getKubeConfig().Name())
Expect(err).NotTo(HaveOccurred())
userObj := configObj.AuthInfos["envtest-admin"]
printDecodedPEM := func(field string, data []byte) {
decoded, err := base64.StdEncoding.DecodeString(string(data))
if err != nil {

Code Review Run #158647


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@bito-code-review
Copy link

bito-code-review bot commented Jul 22, 2025

Code Review Agent Run #bd2dae

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 93f19bd..0163ff2
    • agent/host_agent_test.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@hsri-pf9
Copy link
Collaborator Author

Agent Unit tests passed, Now webhook unit tests are remainig which I am working on it.

Copy link

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

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

Code Review Agent Run #d14744

Actionable Suggestions - 2
  • agent/reconciler/host_reconciler.go - 2
    • Missing existence check before creating uninstall secret · Line 188-205
    • Secret deleted before node reset operation completes · Line 313-325
Review Details
  • Files reviewed - 2 · Commit Range: 0163ff2..357f2c2
    • agent/reconciler/host_reconciler.go
    • agent/reconciler/reconciler_test.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +188 to +205
if uninstallOk {
uninstallSecretName := "byoh-uninstall-" + byoHost.Name
uninstallSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: uninstallSecretName,
Namespace: byoHost.Namespace,
},
Data: map[string][]byte{
"uninstall": uninstallScriptBytes,
},
}
if err := r.Client.Create(ctx, uninstallSecret); err != nil {
logger.Error(err, "error creating uninstall secret")
return err
}
byoHost.Spec.UninstallationSecret = &corev1.ObjectReference{
Name: uninstallSecretName,
Namespace: byoHost.Namespace,

Choose a reason for hiding this comment

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

Missing existence check before creating uninstall secret

The code creates a new uninstall secret even if one might already exist with the same name. This could lead to errors if the secret already exists. Consider checking if the secret exists before creating it.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if uninstallOk {
uninstallSecretName := "byoh-uninstall-" + byoHost.Name
uninstallSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: uninstallSecretName,
Namespace: byoHost.Namespace,
},
Data: map[string][]byte{
"uninstall": uninstallScriptBytes,
},
}
if err := r.Client.Create(ctx, uninstallSecret); err != nil {
logger.Error(err, "error creating uninstall secret")
return err
}
byoHost.Spec.UninstallationSecret = &corev1.ObjectReference{
Name: uninstallSecretName,
Namespace: byoHost.Namespace,
if uninstallOk {
uninstallSecretName := "byoh-uninstall-" + byoHost.Name
// Check if secret already exists
existingSecret := &corev1.Secret{}
err := r.Client.Get(ctx, types.NamespacedName{
Name: uninstallSecretName,
Namespace: byoHost.Namespace,
}, existingSecret)
if err != nil && !errors.IsNotFound(err) {
logger.Error(err, "error checking for existing uninstall secret")
return err
}
if errors.IsNotFound(err) {
// Create new secret if it doesn't exist
uninstallSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: uninstallSecretName,
Namespace: byoHost.Namespace,
},
Data: map[string][]byte{
"uninstall": uninstallScriptBytes,
},
}
if err := r.Client.Create(ctx, uninstallSecret); err != nil {
logger.Error(err, "error creating uninstall secret")
return err
}
}
byoHost.Spec.UninstallationSecret = &corev1.ObjectReference{
Name: uninstallSecretName,
Namespace: byoHost.Namespace,

Code Review Run #d14744


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines +313 to +325
if err := r.Client.Delete(ctx, secret); err != nil {
logger.Error(err, "error deleting uninstallation secret")
return err
}
} else {
logger.Info("Skipping uninstallation of k8s components")
}

err := r.resetNode(ctx, byoHost)
if err != nil {
return err
}

Choose a reason for hiding this comment

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

Secret deleted before node reset operation completes

The uninstallation secret is deleted after execution but before the node reset, which could cause issues if the reset fails and reconciliation needs to retry. Consider moving the secret deletion after the node reset.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if err := r.Client.Delete(ctx, secret); err != nil {
logger.Error(err, "error deleting uninstallation secret")
return err
}
} else {
logger.Info("Skipping uninstallation of k8s components")
}
err := r.resetNode(ctx, byoHost)
if err != nil {
return err
}
} else {
logger.Info("Skipping uninstallation of k8s components")
}
err := r.resetNode(ctx, byoHost)
if err != nil {
return err
}
if !r.SkipK8sInstallation && secret != nil {
if err := r.Client.Delete(ctx, secret); err != nil {
logger.Error(err, "error deleting uninstallation secret")
return err
}
}

Code Review Run #d14744


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants