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

BYOH agent systemd service #5

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open

BYOH agent systemd service #5

wants to merge 37 commits into from

Conversation

snslk
Copy link

@snslk snslk commented Jan 7, 2025

Changed Makefile to create deb and rpm package :
-> Added pf9-byohostagent.service
-> added pf9-byoh-agent-after-install.sh
-> added pf9-byoh-agent-before-remove.sh
-> added pf9-byoh-agent-after-remove.sh
-> added pf9-byohost.spec for rpm package (in progress)

Summary by Bito

This PR implements major BYOH infrastructure changes, transitioning from Docker-based installation to native packaging (DEB/RPM) with systemd integration. The implementation includes moving from ~/.byoh/conf/bootstrap-kubeconfig.yaml to ~/.byoh/config and implementing dynamic namespace-based configuration. Key improvements include certificate handling, dependency management, and systemd integration with restart policies and logging. The changes involve RBAC policy updates, streamlined Dockerfile dependencies, and removal of unnecessary systemd-resolved service enablement.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 5

Snehal Shelke and others added 2 commits January 7, 2025 01:55
Copy link

bito-code-review bot commented Feb 7, 2025

Code Review Agent Run #dbd031

Actionable Suggestions - 10
  • Makefile - 2
    • Consider checking check_env.sh return value · Line 41-41
    • Consider fixing githash macro definition · Line 295-295
  • scripts/pf9-byohost-agent-after-install.sh - 2
    • Consider adding file existence check · Line 8-8
    • Add error handling for service file copy · Line 9-9
  • scripts/sign_packages.sh - 1
    • Consider adding error handling for expect · Line 4-5
  • scripts/pf9-byohost-agent-before-remove.sh - 2
    • Consider fixing if condition syntax · Line 58-58
    • Consider more specific file deletion pattern · Line 60-60
  • chart-generator/byoh-chart/manager_auth_proxy_patch.yaml - 1
    • Consider updating kube-rbac-proxy image version · Line 13-13
  • config/manager/manager.yaml - 1
    • Consider using specific version tag · Line 34-34
  • scripts/pf9-byohost.spec - 1
    • Incorrect mkdir path includes filename · Line 28-28
Additional Suggestions - 5
  • scripts/sign_packages_deb.sh - 1
    • Consider using double quotes for variables · Line 4-4
  • service/pf9-byohostagent.service - 1
    • Review service restart rate limits · Line 5-6
  • chart-generator/byoh-chart/webhookcainjection_patch.yaml - 1
    • Consider more specific webhook config name · Line 7-7
  • scripts/pf9-byohost.spec - 1
    • Consider removing duplicate file entry · Line 41-41
  • chart-generator/byoh-chart/metrics_service.yaml - 1
    • Consider more specific service naming · Line 8-8
Review Details
  • Files reviewed - 19 · Commit Range: 7cff74b..3533edc
    • Makefile
    • agent/main.go
    • chart-generator/byoh-chart/kustomization.yaml
    • chart-generator/byoh-chart/kustomizeconfig.yaml
    • chart-generator/byoh-chart/manager_auth_proxy_patch.yaml
    • chart-generator/byoh-chart/manager_config_patch.yaml
    • chart-generator/byoh-chart/manager_webhook_patch.yaml
    • chart-generator/byoh-chart/metrics_service.yaml
    • chart-generator/byoh-chart/webhookcainjection_patch.yaml
    • chart-generator/chart-generator.sh
    • chart-generator/sample-values.yaml
    • config/manager/manager.yaml
    • scripts/pf9-byohost-agent-after-install.sh
    • scripts/pf9-byohost-agent-after-remove.sh
    • scripts/pf9-byohost-agent-before-remove.sh
    • scripts/pf9-byohost.spec
    • scripts/sign_packages.sh
    • scripts/sign_packages_deb.sh
    • service/pf9-byohostagent.service
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Copy link

bito-code-review bot commented Feb 7, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - BYOH Agent Service Management and Packaging

pf9-byohost-agent-before-remove.sh - Added uninstallation script with systemd service cleanup

pf9-byohost.spec - Added RPM spec file with package dependencies and installation scripts

pf9-byohostagent.service - Added systemd service configuration with restart policies

sign_packages.sh - Added package signing script for RPM packages

sign_packages_deb.sh - Added package signing script for DEB packages

Makefile - Added build targets for creating DEB and RPM packages with dependencies

build-and-push.sh - Added build script for container image management

pf9-byohost-agent-after-install.sh - Added post-installation script for service setup

pf9-byohost-agent-after-remove.sh - Added post-removal cleanup script

Dockerfile - Added Dockerfile for dependency packaging

install.sh - Added installation script for package deployment

Other Improvements - RBAC and Authorization Configuration

after-csr.yaml - Added RBAC roles and bindings for BYOH host management

before-csr.yaml - Added initial RBAC setup for certificate management

byoh_ns_service_account.yaml - Added RBAC policies and service account configurations

csr.go - Updated certificate signing request configuration

byoadmission_controller.go - Modified certificate approval process

manifests.yaml - Removed CREATE and UPDATE webhook operations

Feature Improvement - Helm Chart and Deployment Updates

chart-generator.sh - Added script for generating Helm charts with version management

kustomization.yaml - Updated namespace configuration for Helm deployment

manager.yaml - Updated container image and termination settings

Other Improvements - Code Refactoring and Configuration Updates

main.go - Updated namespace configuration and constants

byohost_webhook.go - Modified service account namespace

getting_started.sh - Updated deployment namespace references

helm-chart-version - Added version tracking file

@@ -36,6 +37,28 @@ BYOH_TEMPLATES := $(REPO_ROOT)/test/e2e/data/infrastructure-provider-byoh
LDFLAGS := -w -s $(shell hack/version.sh)
STATIC=-extldflags '-static'

check-env:
$(shell ./check_env.sh)

Choose a reason for hiding this comment

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

Consider checking check_env.sh return value

Consider capturing and checking the return value of check_env.sh script execution. Currently, the shell command output is captured but not evaluated, which could mask potential environment setup issues.

Code suggestion
Check the AI-generated fix before applying
 @@ -40,2 +40,2 @@ STATIC=-extldflags '-static'
 check-env:
 	./check_env.sh || (echo "Environment check failed"; exit 1)

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

rpmbuild -bb \
--define "_topdir $(RPMBUILD_DIR)" \
--define "_src_dir $(RPM_SRC_ROOT)" \
--define "_githash $(AGENT_SRC_DIR)/scripts/pf9-byohost.spec "

Choose a reason for hiding this comment

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

Consider fixing githash macro definition

The _githash definition in the rpmbuild command appears to be pointing to a spec file path instead of an actual git hash value. Consider updating to use the actual git hash value for proper versioning.

Code suggestion
Check the AI-generated fix before applying
Suggested change
--define "_githash $(AGENT_SRC_DIR)/scripts/pf9-byohost.spec "
--define "_githash $(shell git rev-parse HEAD)" \

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

mkdir -p /var/log/pf9/byoh
mkdir -p $HOME/.byoh/
touch /var/log/pf9/byoh/byoh-agent.log
chmod +x /binary/pf9-byoh-hostagent-linux-amd64

Choose a reason for hiding this comment

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

Consider adding file existence check

Consider checking if the binary file /binary/pf9-byoh-hostagent-linux-amd64 exists before attempting to change its permissions. This could prevent errors if the file is missing.

Code suggestion
Check the AI-generated fix before applying
Suggested change
chmod +x /binary/pf9-byoh-hostagent-linux-amd64
if [ -f /binary/pf9-byoh-hostagent-linux-amd64 ]; then
chmod +x /binary/pf9-byoh-hostagent-linux-amd64
else
echo "Error: Binary file not found at /binary/pf9-byoh-hostagent-linux-amd64"
exit 1
fi

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

mkdir -p $HOME/.byoh/
touch /var/log/pf9/byoh/byoh-agent.log
chmod +x /binary/pf9-byoh-hostagent-linux-amd64
cp /lib/systemd/system/pf9-byohost-agent.service /etc/systemd/system/pf9-byohost-agent.service

Choose a reason for hiding this comment

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

Add error handling for service file copy

Consider adding error handling when copying the service file. The script should verify if the source file exists and handle potential copy failures.

Code suggestion
Check the AI-generated fix before applying
Suggested change
cp /lib/systemd/system/pf9-byohost-agent.service /etc/systemd/system/pf9-byohost-agent.service
if [ -f /lib/systemd/system/pf9-byohost-agent.service ]; then
if ! cp /lib/systemd/system/pf9-byohost-agent.service /etc/systemd/system/pf9-byohost-agent.service; then
echo "Error: Failed to copy service file"
exit 1
fi
else
echo "Error: Service file not found at /lib/systemd/system/pf9-byohost-agent.service"
exit 1
fi

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +4 to +5
expect "$(dirname $0)/rpmsign.expect" "$@"
fi

Choose a reason for hiding this comment

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

Consider adding error handling for expect

Consider adding error handling for the expect command execution. If the expect script fails, the error should be caught and handled appropriately. Could add a check for the return value.

Code suggestion
Check the AI-generated fix before applying
Suggested change
expect "$(dirname $0)/rpmsign.expect" "$@"
fi
if ! expect "$(dirname $0)/rpmsign.expect" "$@"; then
echo "Error: Package signing failed"
exit 1
fi
fi

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

echo "Log files already removed or not found" | tee -a "$LOG_FILE"
fi

if [-f /etc/pf9-byohost* ]; then

Choose a reason for hiding this comment

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

Consider fixing if condition syntax

There appears to be a syntax error in the if condition. The test command requires a space after [. Consider changing [-f /etc/pf9-byohost*] to [ -f /etc/pf9-byohost* ].

Code suggestion
Check the AI-generated fix before applying
Suggested change
if [-f /etc/pf9-byohost* ]; then
if [ -f /etc/pf9-byohost* ]; then

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged


if [-f /etc/pf9-byohost* ]; then
echo "Removing Pf9 conf files" | tee -a "$LOG_FILE"
rm -f /etc/pf9*

Choose a reason for hiding this comment

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

Consider more specific file deletion pattern

The wildcard pattern pf9* in rm -f /etc/pf9* seems too broad and may unintentionally remove unrelated files. Consider using a more specific pattern like pf9-byohost* to match only relevant files.

Code suggestion
Check the AI-generated fix before applying
Suggested change
rm -f /etc/pf9*
rm -f /etc/pf9-byohost*

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

spec:
containers:
- name: kube-rbac-proxy
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0

Choose a reason for hiding this comment

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

Consider updating kube-rbac-proxy image version

Consider updating the kube-rbac-proxy image version from v0.8.0 to a newer version as v0.8.0 may have known security vulnerabilities. It would be worth checking if a newer version is available.

Code suggestion
Check the AI-generated fix before applying
Suggested change
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@@ -31,7 +31,7 @@ spec:
args:
- --enable-leader-election
- "--metrics-bind-addr=127.0.0.1:8080"
image: gcr.io/k8s-staging-cluster-api/cluster-api-byoh-controller:latest
image: docker.io/psarwate/pf9-cluster-api-byoh-controller:dev

Choose a reason for hiding this comment

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

Consider using specific version tag

Consider using a specific version tag instead of dev for the container image docker.io/psarwate/pf9-cluster-api-byoh-controller:dev. Using floating tags like dev can lead to inconsistent deployments and make it difficult to track which version is actually running.

Code suggestion
Check the AI-generated fix before applying
Suggested change
image: docker.io/psarwate/pf9-cluster-api-byoh-controller:dev
image: docker.io/psarwate/pf9-cluster-api-byoh-controller:v1.0.0

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

rm -fr $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT
cp -r $SRC_DIR/* $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/var/log/pf9/byoh/byoh-agent.log

Choose a reason for hiding this comment

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

Incorrect mkdir path includes filename

The mkdir command is creating a path to what appears to be a log file rather than a directory. Consider removing /byoh-agent.log from the path.

Code suggestion
Check the AI-generated fix before applying
Suggested change
mkdir -p $RPM_BUILD_ROOT/var/log/pf9/byoh/byoh-agent.log
mkdir -p $RPM_BUILD_ROOT/var/log/pf9/byoh

Code Review Run #dbd031


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Copy link

bito-code-review bot commented Feb 7, 2025

Code Review Agent Run #8b88d4

Actionable Suggestions - 6
  • byoh-chart/templates/workload.yaml - 5
  • byoh-chart/values.yaml - 1
    • Consider using specific version tag · Line 1-1
Review Details
  • Files reviewed - 8 · Commit Range: 3533edc..da62861
    • byoh-chart/.helmignore
    • byoh-chart/Chart.yaml
    • byoh-chart/templates/_helpers.tpl
    • byoh-chart/templates/workload.yaml
    • byoh-chart/values.yaml
    • chart-generator/chart-generator.sh
    • chart-generator/sample-values.yaml
    • helm-chart-version
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines 683 to 684
description: BundleLookupBaseRegistry is the base Registry URL that is used for pulling byoh bundle images, if not set, the default will be set to https://projects.registry.vmware.com/cluster_api_provider_bringyourownhost
type: string

Choose a reason for hiding this comment

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

Consider making registry URL configurable

Consider making the default registry URL configurable through a variable or environment setting rather than hardcoding it in the description. The current hardcoded URL https://projects.registry.vmware.com/cluster_api_provider_bringyourownhost may need to change in the future.

Code suggestion
Check the AI-generated fix before applying
Suggested change
description: BundleLookupBaseRegistry is the base Registry URL that is used for pulling byoh bundle images, if not set, the default will be set to https://projects.registry.vmware.com/cluster_api_provider_bringyourownhost
type: string
description: BundleLookupBaseRegistry is the base Registry URL that is used for pulling byoh bundle images. If not set, the default will be set to the value of BYOH_DEFAULT_REGISTRY environment variable
type: string

Code Review Run #8b88d4


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines 802 to 833
- apiGroups:
- ""
resources:
- events
verbs:
- create
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- events
- secrets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- list
- watch

Choose a reason for hiding this comment

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

Consider consolidating duplicate RBAC rules

Consider consolidating duplicate RBAC rules for events and secrets resources in the "" API group to avoid redundancy. The permissions can be combined into a single rule with merged verbs.

Code suggestion
Check the AI-generated fix before applying
    - apiGroups:
        - ""
      resources:
 -      - events
 -    verbs:
 -      - create
 -      - get
 -      - list
 -      - patch
 -      - update
 -      - watch
 -  - apiGroups:
 -      - ""
 -    resources:
        - events
        - secrets
      verbs:
        - create
        - delete
        - get
        - list
        - patch
        - update
        - watch
 -  - apiGroups:
 -      - ""
 -    resources:
 -      - secrets
 -    verbs:
 -      - get
 -      - list
 -      - watch

Code Review Run #8b88d4


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines 917 to 1091
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- byomachines/status
verbs:
- get
- patch
- update
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- byomachinetemplates
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- byomachinetemplates/finalizers
verbs:
- update
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- byomachinetemplates/status
verbs:
- get
- patch
- update
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- k8sinstallerconfigs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- k8sinstallerconfigs/finalizers
verbs:
- update
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- k8sinstallerconfigs/status
verbs:
- get
- patch
- update
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.10.0
labels:
cluster.x-k8s.io/provider: infrastructure-byoh
cluster.x-k8s.io/v1beta1: v1beta1
name: k8sinstallerconfigtemplates.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
names:
kind: K8sInstallerConfigTemplate
listKind: K8sInstallerConfigTemplateList
plural: k8sinstallerconfigtemplates
singular: k8sinstallerconfigtemplate
scope: Namespaced
versions:
- name: v1beta1
schema:
openAPIV3Schema:
description: K8sInstallerConfigTemplate is the Schema for the k8sinstallerconfigtemplates API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: K8sInstallerConfigTemplateSpec defines the desired state of K8sInstallerConfigTemplate
properties:
template:
properties:
spec:
description: Spec is the specification of the desired behavior of the installer config.
properties:

Choose a reason for hiding this comment

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

Consider consolidating similar RBAC rules

Consider consolidating similar RBAC rules for resources under the same API group infrastructure.cluster.x-k8s.io. The current structure has repetitive declarations that could be simplified by grouping common verbs and resources together.

Code suggestion
Check the AI-generated fix before applying
 -  - apiGroups:
 -      - infrastructure.cluster.x-k8s.io
 -    resources:
 -      - byoclusters
 -    verbs:
 -      - create
 -      - delete
 -      - get
 -      - list
 -      - patch
 -      - update
 -      - watch
 -  - apiGroups:
 -      - infrastructure.cluster.x-k8s.io
 -    resources:
 -      - byohosts
 -    verbs:
 -      - create
 -      - delete
 -      - get
 -      - list
 -      - patch
 -      - update
 -      - watch
 +  - apiGroups:
 +      - infrastructure.cluster.x-k8s.io
 +    resources:
 +      - byoclusters
 +      - byohosts
 +      - byomachines
 +      - byomachinetemplates
 +      - k8sinstallerconfigs
 +    verbs:
 +      - create
 +      - delete
 +      - get
 +      - list
 +      - patch
 +      - update
 +      - watch

Code Review Run #8b88d4


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

conntrack \
systemctl

CMD dpkg -i /pf9-byohost-agent.deb

Choose a reason for hiding this comment

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

Consider entrypoint script for installation

Using CMD with dpkg -i may not handle package installation errors gracefully. Consider using an entrypoint script that can perform proper error handling and initialization.

Code suggestion
Check the AI-generated fix before applying
Suggested change
CMD dpkg -i /pf9-byohost-agent.deb
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# Example entrypoint.sh content:
# #!/bin/bash
# dpkg -i /pf9-byohost-agent.deb || exit 1
# exec "$@"

Code Review Run #a3b31d


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

  • Yes, avoid them

Copy link

bito-code-review bot commented Feb 24, 2025

Code Review Agent Run #e6df91

Actionable Suggestions - 6
  • Makefile - 2
    • Consider consolidating copy and echo operations · Line 342-343
    • Consider consolidating copy and echo operations · Line 342-343
  • scripts/install.sh - 2
    • Consider adding error handling for systemctl · Line 4-7
    • Add sudo and error check for dpkg · Line 5-5
  • scripts/Dockerfile - 1
    • Consider adding autoremove for better cleanup · Line 24-25
  • controllers/infrastructure/byoadmission_controller.go - 1
    • Consider using UpdateApproval for CSR approval · Line 69-69
Review Details
  • Files reviewed - 10 · Commit Range: 9805a86..00c803b
    • Makefile
    • agent/registration/csr.go
    • build/pf9-byohost/common/lib/systemd/system/pf9-byohost-agent.service
    • build/pf9-byohost/debsrc/lib/systemd/system/pf9-byohost-agent.service
    • build/pf9-byohost/debsrc/pf9-byohost-agent.deb.md5
    • build/pf9-byohost/dependencies/Dockerfile
    • controllers/infrastructure/byoadmission_controller.go
    • scripts/Dockerfile
    • scripts/install.sh
    • scripts/pf9-byohost-agent-after-install.sh
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines +342 to +343
cp $(AGENT_SRC_DIR)/scripts/install.sh $(DEB_DEP_SRC_ROOT)/install.sh
echo "Successfully copied install.sh"

Choose a reason for hiding this comment

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

Consider consolidating copy and echo operations

Consider consolidating the copy operation and its echo statement into a single command using && operator to ensure the echo only prints on successful copy. This would make the build process more reliable by failing fast if the copy fails.

Code suggestion
Check the AI-generated fix before applying
Suggested change
cp $(AGENT_SRC_DIR)/scripts/install.sh $(DEB_DEP_SRC_ROOT)/install.sh
echo "Successfully copied install.sh"
cp $(AGENT_SRC_DIR)/scripts/install.sh $(DEB_DEP_SRC_ROOT)/install.sh && echo "Successfully copied install.sh"

Code Review Run #e6df91


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

  • Yes, avoid them

Comment on lines 4 to 7
sudo systemctl enable systemd-resolved --now
dpkg -i pf9-byohost-agent.deb
systemctl enable pf9-byohost-agent
systemctl start pf9-byohost-agent

Choose a reason for hiding this comment

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

Consider adding error handling for systemctl

Consider adding error handling for the systemctl enable command. The script might fail silently if the command fails. Could add a check for the command's exit status.

Code suggestion
Check the AI-generated fix before applying
Suggested change
sudo systemctl enable systemd-resolved --now
dpkg -i pf9-byohost-agent.deb
systemctl enable pf9-byohost-agent
systemctl start pf9-byohost-agent
if ! sudo systemctl enable systemd-resolved --now; then
echo "Failed to enable systemd-resolved service"
exit 1
fi
if ! dpkg -i pf9-byohost-agent.deb; then
echo "Failed to install pf9-byohost-agent"
exit 1
fi
if ! systemctl enable pf9-byohost-agent; then
echo "Failed to enable pf9-byohost-agent service"
exit 1
fi
if ! systemctl start pf9-byohost-agent; then
echo "Failed to start pf9-byohost-agent service"
exit 1
fi

Code Review Run #e6df91


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

  • Yes, avoid them


echo " Starting pf9-byohost-agent"
sudo systemctl enable systemd-resolved --now
dpkg -i pf9-byohost-agent.deb

Choose a reason for hiding this comment

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

Add sudo and error check for dpkg

The dpkg -i command should be run with sudo and include error handling. Package installation could fail silently.

Code suggestion
Check the AI-generated fix before applying
Suggested change
dpkg -i pf9-byohost-agent.deb
if ! sudo dpkg -i pf9-byohost-agent.deb; then
echo "Failed to install pf9-byohost-agent package"
exit 1
fi

Code Review Run #e6df91


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

  • Yes, avoid them

Comment on lines +24 to +25
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Choose a reason for hiding this comment

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

Consider adding autoremove for better cleanup

Consider adding apt-get autoremove -y before cleanup commands to remove automatically installed dependencies that are no longer needed. This helps reduce the image size further.

Code suggestion
Check the AI-generated fix before applying
Suggested change
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Code Review Run #e6df91


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

  • Yes, avoid them

@@ -66,7 +66,7 @@ func (r *ByoAdmissionReconciler) Reconcile(ctx context.Context, req ctrl.Request

// Approve the CSR
logger.Info("Approving CSR", "object", req.NamespacedName)
_, err = r.ClientSet.CertificatesV1().CertificateSigningRequests().UpdateApproval(ctx, csr.Name, csr, metav1.UpdateOptions{})
_, err = r.ClientSet.CertificatesV1().CertificateSigningRequests().UpdateStatus(ctx, csr, metav1.UpdateOptions{})

Choose a reason for hiding this comment

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

Consider using UpdateApproval for CSR approval

Consider using UpdateApproval instead of UpdateStatus for CSR approval. The UpdateStatus method may not properly handle the approval workflow for certificate signing requests.

Code suggestion
Check the AI-generated fix before applying
Suggested change
_, err = r.ClientSet.CertificatesV1().CertificateSigningRequests().UpdateStatus(ctx, csr, metav1.UpdateOptions{})
_, err = r.ClientSet.CertificatesV1().CertificateSigningRequests().UpdateApproval(ctx, csr.Name, csr, metav1.UpdateOptions{})

Code Review Run #e6df91


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

  • Yes, avoid them

…p-kubeconfig.yaml and added build dir which contains byoh-agent image creation files
Copy link

bito-code-review bot commented Feb 26, 2025

Code Review Agent Run #7b5bb4

Actionable Suggestions - 4
  • scripts/Dockerfile - 1
    • Consider using systemd package instead · Line 23-23
  • build/pf9-byohost/dependencies/install.sh - 1
    • Consider adding error handling for dpkg · Line 5-5
  • test/e2e/docker_helper.go - 1
    • Consider extracting kubeconfig path to constant · Line 224-224
  • scripts/pf9-byohost-agent-after-install.sh - 1
    • Consider adding error handling for namespace · Line 15-16
Review Details
  • Files reviewed - 12 · Commit Range: 00c803b..268fe4d
    • agent/main.go
    • agent/registration/csr.go
    • build/pf9-byohost/common/lib/systemd/system/pf9-byohost-agent.service
    • build/pf9-byohost/debsrc/lib/systemd/system/pf9-byohost-agent.service
    • build/pf9-byohost/debsrc/pf9-byohost-agent.deb.md5
    • build/pf9-byohost/dependencies/Dockerfile
    • build/pf9-byohost/dependencies/install.sh
    • config/webhook/manifests.yaml
    • hack/install-host-agent-service.sh
    • scripts/Dockerfile
    • scripts/pf9-byohost-agent-after-install.sh
    • test/e2e/docker_helper.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

ebtables \
ethtool \
conntrack \
systemctl \

Choose a reason for hiding this comment

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

Consider using systemd package instead

Consider using systemd instead of systemctl package in the Dockerfile. While systemctl is the command-line tool, systemd is the actual init system package that provides the complete functionality. Installing just systemctl might lead to missing dependencies.

Code suggestion
Check the AI-generated fix before applying
Suggested change
systemctl \
systemd \

Code Review Run #7b5bb4


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

  • Yes, avoid them


echo " Starting pf9-byohost-agent"
sudo systemctl enable systemd-resolved --now
dpkg -i pf9-byohost-agent.deb

Choose a reason for hiding this comment

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

Consider adding error handling for dpkg

Consider adding error handling for the dpkg -i command. If package installation fails, the script continues executing which could lead to service startup failures.

Code suggestion
Check the AI-generated fix before applying
Suggested change
dpkg -i pf9-byohost-agent.deb
if ! dpkg -i pf9-byohost-agent.deb; then
echo "Failed to install pf9-byohost-agent package"
exit 1
fi

Code Review Run #7b5bb4


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

  • Yes, avoid them

@@ -221,7 +221,7 @@ func (r *ByoHostRunner) copyKubeconfig(config cpConfig, listopt types.ContainerL

config.sourcePath = TempKubeconfigPath
// SplitAfterN used to remove the unwanted special characters in the homeDir
config.destPath = strings.SplitAfterN(strings.TrimSpace(homeDir)+"/.byoh/config", "/", 2)[1] //nolint: gomnd
config.destPath = strings.SplitAfterN(strings.TrimSpace(homeDir)+"/.byoh/conf/bootstrap-kubeconfig.yaml", "/", 2)[1] //nolint: gomnd

Choose a reason for hiding this comment

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

Consider extracting kubeconfig path to constant

Consider extracting the kubeconfig path .byoh/conf/bootstrap-kubeconfig.yaml into a constant since it appears in multiple places. This would make future path changes easier to maintain and reduce the risk of inconsistencies.

Code suggestion
Check the AI-generated fix before applying
 @@ -28,6 +28,7 @@
  const (
  	kindImage           = "byoh/node:e2e"
  	TempKubeconfigPath  = "/tmp/mgmt.conf"
  	bootstrapKubeconfig = "/tmp/boostrap-kubeconfig"
 +	ByohKubeconfigPath  = ".byoh/conf/bootstrap-kubeconfig.yaml"
  )

Code Review Run #7b5bb4


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

  • Yes, avoid them

Comment on lines 15 to 16
export NAMESPACE=$(grep "namespace" /root/.byoh/conf/bootstrap-kubeconfig.yaml | awk '{print $2}')
echo "NAMESPACE=$NAMESPACE" > /etc/pf9-byohost-agent.service.d/pf9-byohost-agent.conf

Choose a reason for hiding this comment

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

Consider adding error handling for namespace

Consider adding error handling when reading the namespace from bootstrap-kubeconfig.yaml. If the file doesn't exist or the namespace field is missing, the script might fail silently. Maybe add a check and set a default namespace value if the grep fails.

Code suggestion
Check the AI-generated fix before applying
Suggested change
export NAMESPACE=$(grep "namespace" /root/.byoh/conf/bootstrap-kubeconfig.yaml | awk '{print $2}')
echo "NAMESPACE=$NAMESPACE" > /etc/pf9-byohost-agent.service.d/pf9-byohost-agent.conf
NAMESPACE=$(grep "namespace" /root/.byoh/conf/bootstrap-kubeconfig.yaml | awk '{print $2}' || echo "")
if [ -z "$NAMESPACE" ]; then
echo "Warning: Could not read namespace from config, using default"
NAMESPACE="default"
fi
echo "NAMESPACE=$NAMESPACE" > /etc/pf9-byohost-agent.service.d/pf9-byohost-agent.conf

Code Review Run #7b5bb4


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

  • Yes, avoid them

Copy link

bito-code-review bot commented Feb 27, 2025

Code Review Agent Run #7d319e

Actionable Suggestions - 1
  • scripts/pf9-byohost-agent-after-install.sh - 1
    • Consider adding error handling for systemctl · Line 21-22
Review Details
  • Files reviewed - 12 · Commit Range: 268fe4d..0145ef2
    • Makefile
    • agent/main.go
    • agent/registration/csr.go
    • build/pf9-byohost/common/lib/systemd/system/pf9-byohost-agent.service
    • build/pf9-byohost/debsrc/lib/systemd/system/pf9-byohost-agent.service
    • build/pf9-byohost/debsrc/pf9-byohost-agent.deb.md5
    • build/pf9-byohost/dependencies/Dockerfile
    • build/pf9-byohost/dependencies/install.sh
    • hack/install-host-agent-service.sh
    • scripts/install.sh
    • scripts/pf9-byohost-agent-after-install.sh
    • test/e2e/docker_helper.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines +21 to +22
# systemctl enable pf9-byohost-agent.service
# systemctl start pf9-byohost-agent.service

Choose a reason for hiding this comment

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

Consider adding error handling for systemctl

Consider adding error handling for the systemctl commands to ensure the service is properly enabled and started. Could check the return status and log any failures.

Code suggestion
Check the AI-generated fix before applying
Suggested change
# systemctl enable pf9-byohost-agent.service
# systemctl start pf9-byohost-agent.service
if ! systemctl enable pf9-byohost-agent.service; then
echo "Failed to enable pf9-byohost-agent service"
exit 1
fi
if ! systemctl start pf9-byohost-agent.service; then
echo "Failed to start pf9-byohost-agent service"
exit 1
fi

Code Review Run #7d319e


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

  • Yes, avoid them

Copy link

bito-code-review bot commented Feb 27, 2025

Code Review Agent Run #816e29

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 0145ef2..cccb84e
    • scripts/Dockerfile
    • scripts/install.sh
    • scripts/pf9-byohost-agent-after-install.sh
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Copy link

bito-code-review bot commented Feb 27, 2025

Code Review Agent Run #3e8bed

Actionable Suggestions - 2
  • scripts/pf9-byohost-agent-after-install.sh - 1
    • Consider enabling systemctl daemon-reload command · Line 20-20
  • chart-generator/byoh-chart/kustomization.yaml - 1
    • Consider validating Release.Namespace template value · Line 2-2
Review Details
  • Files reviewed - 4 · Commit Range: cccb84e..30b0e5d
    • chart-generator/byoh-chart/kustomization.yaml
    • config/default/kustomization.yaml
    • scripts/install.sh
    • scripts/pf9-byohost-agent-after-install.sh
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

echo "NAMESPACE=$NAMESPACE" > /etc/pf9-byohost-agent.service.d/pf9-byohost-agent.conf
echo "BOOTSTRAP_KUBECONFIG=/etc/pf9-byohost-agent.service.d/bootstrap-kubeconfig.yaml" >> /etc/pf9-byohost-agent.service.d/pf9-byohost-agent.conf

# systemctl daemon-reload

Choose a reason for hiding this comment

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

Consider enabling systemctl daemon-reload command

Consider removing the comment and enabling the systemctl daemon-reload command since it appears to be required for the service to work properly. The subsequent commands on lines 21-22 depend on this reload.

Code suggestion
Check the AI-generated fix before applying
Suggested change
# systemctl daemon-reload
systemctl daemon-reload

Code Review Run #3e8bed


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

  • Yes, avoid them

@@ -0,0 +1,75 @@
# Adds namespace to all resources.
namespace: '{{ .Release.Namespace }}'

Choose a reason for hiding this comment

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

Consider validating Release.Namespace template value

Consider adding validation for {{ .Release.Namespace }} to ensure it's not empty or invalid. The namespace value is critical for resource placement.

Code suggestion
Check the AI-generated fix before applying
Suggested change
namespace: '{{ .Release.Namespace }}'
namespace: '{{ required "Release.Namespace is required" .Release.Namespace }}'

Code Review Run #3e8bed


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.

3 participants