diff --git a/agent/cloudinit/cloudinit.go b/agent/cloudinit/cloudinit.go index 5e6647b13..6a327e3ec 100644 --- a/agent/cloudinit/cloudinit.go +++ b/agent/cloudinit/cloudinit.go @@ -14,6 +14,7 @@ import ( "sigs.k8s.io/yaml" ) +// ScriptExecutor bootstrap script executor type ScriptExecutor struct { WriteFilesExecutor IFileWriter RunCmdExecutor ICmdRunner @@ -25,6 +26,7 @@ type bootstrapConfig struct { CommandsToExecute []string `json:"runCmd"` } +// Files details required for files written by bootstrap script type Files struct { Path string `json:"path,"` Encoding string `json:"encoding,omitempty"` diff --git a/agent/cloudinit/cmd_runner.go b/agent/cloudinit/cmd_runner.go index 69ae6e822..80acfe961 100644 --- a/agent/cloudinit/cmd_runner.go +++ b/agent/cloudinit/cmd_runner.go @@ -13,6 +13,8 @@ type ICmdRunner interface { RunCmd(string) error } +// CmdRunner default implementer of ICmdRunner +// TODO reevaluate empty interface/struct type CmdRunner struct { } diff --git a/agent/cloudinit/file_writer.go b/agent/cloudinit/file_writer.go index 98caf37dd..6c7b70ef4 100644 --- a/agent/cloudinit/file_writer.go +++ b/agent/cloudinit/file_writer.go @@ -27,6 +27,7 @@ type IFileWriter interface { WriteToFile(*Files) error } +// FileWriter default implementation of IFileWriter type FileWriter struct { } diff --git a/agent/cloudinit/template_parser.go b/agent/cloudinit/template_parser.go index 5c372c9b6..6a54d8836 100644 --- a/agent/cloudinit/template_parser.go +++ b/agent/cloudinit/template_parser.go @@ -13,10 +13,12 @@ type ITemplateParser interface { ParseTemplate(string) (string, error) } +// TemplateParser cloudinit templates parsing using ITemplateParser type TemplateParser struct { Template interface{} } +// ParseTemplate parses and returns the parsed template content func (tp TemplateParser) ParseTemplate(templateContent string) (string, error) { tmpl, err := template.New("byoh").Parse(templateContent) if err != nil { diff --git a/agent/help_flag_test.go b/agent/help_flag_test.go index c9e559b7a..d2d1720b0 100644 --- a/agent/help_flag_test.go +++ b/agent/help_flag_test.go @@ -41,7 +41,7 @@ var _ = Describe("Help flag for host agent", func() { continue } words := strings.Split(line, " ") - line = (words[0] + " " + words[1]) // checking the first two words + line = words[0] + " " + words[1] // checking the first two words // Any option not belongs to expectedOptions is not allowed. Expect(strings.TrimSpace(line)).To(BeElementOf(expectedOptions)) } diff --git a/agent/installer/bundle_downloader.go b/agent/installer/bundle_downloader.go index 6355f2510..36315515d 100644 --- a/agent/installer/bundle_downloader.go +++ b/agent/installer/bundle_downloader.go @@ -16,6 +16,7 @@ import ( ) var ( + // DownloadPathPermissions file mode permissions for download path DownloadPathPermissions fs.FileMode = 0777 ) @@ -53,7 +54,13 @@ func (bd *bundleDownloader) DownloadFromRepo( downloadPathWithRepo := bd.getBundlePathWithRepo() err := ensureDirExist(downloadPathWithRepo) - defer os.Remove(downloadPathWithRepo) + defer func(name string) { + err = os.Remove(name) + if err != nil { + bd.logger.Error(err, "Failed to remove directory", "path", name) + } + }(downloadPathWithRepo) + if err != nil { return err } diff --git a/agent/installer/checks.go b/agent/installer/checks.go index 56af47278..063b194d7 100644 --- a/agent/installer/checks.go +++ b/agent/installer/checks.go @@ -13,7 +13,7 @@ import ( func checkPreRequsitePackages() error { if runtime.GOOS == "linux" { - unavailablePackages := []string{} + unavailablePackages := make([]string, 0) execr := utilsexec.New() for _, pkgName := range preRequisitePackages { _, err := execr.LookPath(pkgName) diff --git a/agent/installer/cli-dev.go b/agent/installer/cli-dev.go index 70685ae57..2cccab44a 100644 --- a/agent/installer/cli-dev.go +++ b/agent/installer/cli-dev.go @@ -35,6 +35,7 @@ var ( klogger logr.Logger ) +// Main entry point for the installer dev/test CLI func Main() { klogger = klogr.New() diff --git a/agent/installer/installer.go b/agent/installer/installer.go index 1ef03ca48..7ed9848ed 100644 --- a/agent/installer/installer.go +++ b/agent/installer/installer.go @@ -149,7 +149,7 @@ func (i *installer) Install(bundleRepo, k8sVer, tag string) error { return nil } -// Uninstal uninstalls the specified k8s version on the current OS +// Uninstall uninstalls the specified k8s version on the current OS func (i *installer) Uninstall(bundleRepo, k8sVer, tag string) error { i.setBundleRepo(bundleRepo) algoInst, err := i.getAlgoInstallerWithBundle(k8sVer, tag) diff --git a/agent/installer/internal/algo/apt_step.go b/agent/installer/internal/algo/apt_step.go index ce27aa984..365ab7250 100755 --- a/agent/installer/internal/algo/apt_step.go +++ b/agent/installer/internal/algo/apt_step.go @@ -9,6 +9,7 @@ import ( "strings" ) +// NewAptStep returns a new step to install apt package func NewAptStep(k *BaseK8sInstaller, aptPkg string) Step { return NewAptStepEx(k, aptPkg, false) } diff --git a/agent/installer/internal/algo/installer.go b/agent/installer/internal/algo/installer.go index 745129238..18bbb9377 100755 --- a/agent/installer/internal/algo/installer.go +++ b/agent/installer/internal/algo/installer.go @@ -36,11 +36,13 @@ are required in order to: 6) disable unattended OS updates */ +// Step execute/rollback interface type Step interface { do() error undo() error } +// K8sStepProvider steps provider for k8s installer type K8sStepProvider interface { getSteps(*BaseK8sInstaller) []Step @@ -68,6 +70,7 @@ type BaseK8sInstaller struct { OutputBuilder } +// Install installation of k8s cluster as per configured steps in the provider func (b *BaseK8sInstaller) Install() error { steps := b.getSteps(b) @@ -83,6 +86,7 @@ func (b *BaseK8sInstaller) Install() error { return nil } +// Uninstall uninstallation of k8s cluster as per configured steps in the provider func (b *BaseK8sInstaller) Uninstall() error { lastStepIdx := len(b.getSteps(b)) - 1 b.rollback(lastStepIdx) diff --git a/agent/installer/internal/algo/mock_ubuntu_with_error.go b/agent/installer/internal/algo/mock_ubuntu_with_error.go index f60a28568..e9ca1604e 100644 --- a/agent/installer/internal/algo/mock_ubuntu_with_error.go +++ b/agent/installer/internal/algo/mock_ubuntu_with_error.go @@ -23,6 +23,7 @@ func (s *mockStep) undo() error { return s.Err } +// MockUbuntuWithError is a mock implementation of BaseK8sInstaller that returns an error on the steps type MockUbuntuWithError struct { BaseK8sInstaller errorOnStep int diff --git a/agent/installer/internal/algo/output_builder.go b/agent/installer/internal/algo/output_builder.go index d5b484f1d..190d23e21 100755 --- a/agent/installer/internal/algo/output_builder.go +++ b/agent/installer/internal/algo/output_builder.go @@ -3,6 +3,7 @@ package algo +// OutputBuilder is an interface for building output as the algorithm runs. type OutputBuilder interface { Out(string) Err(string) diff --git a/agent/installer/internal/algo/output_builder_counter.go b/agent/installer/internal/algo/output_builder_counter.go index f6940de03..50f10fd65 100644 --- a/agent/installer/internal/algo/output_builder_counter.go +++ b/agent/installer/internal/algo/output_builder_counter.go @@ -3,26 +3,32 @@ package algo +// OutputBuilderCounter used to count the logs called by the OutputBuilder under various heads/types of output type OutputBuilderCounter struct { LogCalledCnt int } +// Out increments the log count for info/content output func (c *OutputBuilderCounter) Out(str string) { c.LogCalledCnt++ } +// Err increments the log count for error output func (c *OutputBuilderCounter) Err(str string) { c.LogCalledCnt++ } +// Cmd increments the log count for command output func (c *OutputBuilderCounter) Cmd(str string) { c.LogCalledCnt++ } +// Desc increments the log count for description output func (c *OutputBuilderCounter) Desc(str string) { c.LogCalledCnt++ } +// Msg increments the log count for message output func (c *OutputBuilderCounter) Msg(str string) { c.LogCalledCnt++ } diff --git a/agent/installer/internal/algo/ubuntu20_4K8s1_22.go b/agent/installer/internal/algo/ubuntu20_4K8s1_22.go index b1d6d20cc..9cf0ca185 100755 --- a/agent/installer/internal/algo/ubuntu20_4K8s1_22.go +++ b/agent/installer/internal/algo/ubuntu20_4K8s1_22.go @@ -8,6 +8,7 @@ import ( "path/filepath" ) +// Ubuntu20_4K8s1_22 is the configuration for Ubuntu 20.4.X, K8s 1.22.X extending BaseK8sInstaller type Ubuntu20_4K8s1_22 struct { BaseK8sInstaller } diff --git a/agent/installer/registry.go b/agent/installer/registry.go index e09f13302..26a8a2a58 100644 --- a/agent/installer/registry.go +++ b/agent/installer/registry.go @@ -29,6 +29,7 @@ func newRegistry() registry { return registry{osk8sInstallerMap: make(osk8sInstallerMap)} } +// AddBundleInstaller adds a bundle installer to the registry func (r *registry) AddBundleInstaller(os, k8sVer string, installer osk8sInstaller) { if _, ok := r.osk8sInstallerMap[os]; !ok { r.osk8sInstallerMap[os] = make(k8sInstallerMap) @@ -41,10 +42,12 @@ func (r *registry) AddBundleInstaller(os, k8sVer string, installer osk8sInstalle r.osk8sInstallerMap[os][k8sVer] = installer } +// AddOsFilter adds an OS filter to the filtered bundle list of registry func (r *registry) AddOsFilter(osFilter, osBundle string) { r.filterBundleList = append(r.filterBundleList, filterBundlePair{osFilter: osFilter, osBundle: osBundle}) } +// ListOS returns a list of OSes supported by the registry func (r *registry) ListOS() (osFilter, osBundle []string) { osFilter = make([]string, 0, len(r.filterBundleList)) osBundle = make([]string, 0, len(r.filterBundleList)) @@ -57,6 +60,7 @@ func (r *registry) ListOS() (osFilter, osBundle []string) { return } +// ListK8s returns a list of K8s versions supported by the registry func (r *registry) ListK8s(osBundleHost string) []string { var result []string @@ -77,6 +81,7 @@ func (r *registry) ListK8s(osBundleHost string) []string { return result } +// GetInstaller returns the bundle installer for the given os and k8s version func (r *registry) GetInstaller(osHost, k8sVer string) (osk8si osk8sInstaller, osBundle string) { osBundle = r.resolveOsToOsBundle(osHost) osk8si = r.osk8sInstallerMap[osBundle][k8sVer] diff --git a/agent/main.go b/agent/main.go index a3839bfe1..0cb67585e 100644 --- a/agent/main.go +++ b/agent/main.go @@ -10,7 +10,7 @@ import ( "os" "strings" - pflag "github.com/spf13/pflag" + "github.com/spf13/pflag" "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/cloudinit" "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/installer" "github.com/vmware-tanzu/cluster-api-provider-bringyourownhost/agent/reconciler" diff --git a/agent/reconciler/host_reconciler.go b/agent/reconciler/host_reconciler.go index 4748b964f..7ab83ae37 100644 --- a/agent/reconciler/host_reconciler.go +++ b/agent/reconciler/host_reconciler.go @@ -35,6 +35,7 @@ type IK8sInstaller interface { Uninstall(string, string, string) error } +// HostReconciler encapsulates the data/logic needed to reconcile a ByoHost type HostReconciler struct { Client client.Client CmdRunner cloudinit.ICmdRunner @@ -46,7 +47,8 @@ type HostReconciler struct { const ( bootstrapSentinelFile = "/run/cluster-api/bootstrap-success.complete" - KubeadmResetCommand = "kubeadm reset --force" + // KubeadmResetCommand is the command to run to force reset/remove nodes' local file system of the files created by kubeadm + KubeadmResetCommand = "kubeadm reset --force" ) // Reconcile handles events for the ByoHost that is registered by this agent process @@ -161,6 +163,7 @@ func (r *HostReconciler) getBootstrapScript(ctx context.Context, dataSecretName, return bootstrapSecret, nil } +// SetupWithManager sets up the controller with the manager func (r *HostReconciler) SetupWithManager(ctx context.Context, mgr manager.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&infrastructurev1beta1.ByoHost{}). diff --git a/agent/registration/host_registrar.go b/agent/registration/host_registrar.go index 3c377d65b..ca2f5ddb5 100644 --- a/agent/registration/host_registrar.go +++ b/agent/registration/host_registrar.go @@ -18,13 +18,16 @@ import ( ) var ( + // LocalHostRegistrar is a HostRegistrar that registers the local host. LocalHostRegistrar *HostRegistrar ) +// HostInfo contains information about the host network interface. type HostInfo struct { DefaultNetworkInterfaceName string } +// HostRegistrar used to register a host. type HostRegistrar struct { K8sClient client.Client ByoHostInfo HostInfo @@ -67,6 +70,7 @@ func (hr *HostRegistrar) Register(hostName, namespace string, hostLabels map[str return hr.UpdateNetwork(ctx, byoHost) } +// UpdateNetwork updates the network interface status for the host func (hr *HostRegistrar) UpdateNetwork(ctx context.Context, byoHost *infrastructurev1beta1.ByoHost) error { klog.Info("Add Network Info") helper, err := patch.NewHelper(byoHost, hr.K8sClient) @@ -79,6 +83,7 @@ func (hr *HostRegistrar) UpdateNetwork(ctx context.Context, byoHost *infrastruct return helper.Patch(ctx, byoHost) } +// GetNetworkStatus returns the network interface(s) status for the host func (hr *HostRegistrar) GetNetworkStatus() []infrastructurev1beta1.NetworkStatus { Network := make([]infrastructurev1beta1.NetworkStatus, 0) diff --git a/agent/version/version.go b/agent/version/version.go index a9b1646d1..62407c881 100644 --- a/agent/version/version.go +++ b/agent/version/version.go @@ -10,13 +10,15 @@ import ( ) var ( - Version string + // Version is the version of the agent. + Version string + // BuildDate is the date the agent was built. BuildDate string ) const ( - Dev = "dev" - GitTagLength = 3 + dev = "dev" + gitTagLength = 3 ) // Info exposes information about the version used for the current running code. @@ -46,13 +48,13 @@ func Get() Info { } func extractVersion(major, minor, patch *string) { - if Version == Dev { - *major = Dev + if Version == dev { + *major = dev return } version := strings.Split(Version, ".") - if len(version) != GitTagLength { + if len(version) != gitTagLength { return } diff --git a/agent/version/version_test.go b/agent/version/version_test.go index 7dcc3ff24..cb5c14465 100644 --- a/agent/version/version_test.go +++ b/agent/version/version_test.go @@ -60,7 +60,7 @@ var _ = Describe("Agent version", func() { Context("When version is set", func() { Context("When version is set to dev", func() { BeforeEach(func() { - version.Version = version.Dev + version.Version = version.dev }) AfterEach(func() { @@ -69,7 +69,7 @@ var _ = Describe("Agent version", func() { It("Shows the version major to be dev", func() { expected := version.Info{ - Major: version.Dev, + Major: version.dev, Minor: "", Patch: "", BuildDate: "", diff --git a/apis/infrastructure/v1beta1/byocluster_webhook.go b/apis/infrastructure/v1beta1/byocluster_webhook.go index f6b40fda8..1d7279bf4 100644 --- a/apis/infrastructure/v1beta1/byocluster_webhook.go +++ b/apis/infrastructure/v1beta1/byocluster_webhook.go @@ -17,6 +17,7 @@ import ( // log is for logging in this package. var byoclusterlog = logf.Log.WithName("byocluster-resource") +// SetupWebhookWithManager sets up the webhook for the byocluster resource func (byoCluster *ByoCluster) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(byoCluster). diff --git a/apis/infrastructure/v1beta1/byohost_types.go b/apis/infrastructure/v1beta1/byohost_types.go index f5fac481c..7e2c03202 100644 --- a/apis/infrastructure/v1beta1/byohost_types.go +++ b/apis/infrastructure/v1beta1/byohost_types.go @@ -10,12 +10,18 @@ import ( ) const ( - HostCleanupAnnotation = "byoh.infrastructure.cluster.x-k8s.io/unregistering" - EndPointIPAnnotation = "byoh.infrastructure.cluster.x-k8s.io/endpointip" - K8sVersionAnnotation = "byoh.infrastructure.cluster.x-k8s.io/k8sversion" - AttachedByoMachineLabel = "byoh.infrastructure.cluster.x-k8s.io/byomachine-name" + // HostCleanupAnnotation annotation used to mark a host for cleanup + HostCleanupAnnotation = "byoh.infrastructure.cluster.x-k8s.io/unregistering" + // EndPointIPAnnotation annotation used to store the IP address of the endpoint + EndPointIPAnnotation = "byoh.infrastructure.cluster.x-k8s.io/endpointip" + // K8sVersionAnnotation annotation used to store the k8s version + K8sVersionAnnotation = "byoh.infrastructure.cluster.x-k8s.io/k8sversion" + // AttachedByoMachineLabel label used to mark a node name attached to a byo host + AttachedByoMachineLabel = "byoh.infrastructure.cluster.x-k8s.io/byomachine-name" + // BundleLookupBaseRegistryAnnotation annotation used to store the base registry for the bundle lookup BundleLookupBaseRegistryAnnotation = "byoh.infrastructure.cluster.x-k8s.io/bundle-registry" - BundleLookupTagAnnotation = "byoh.infrastructure.cluster.x-k8s.io/bundle-tag" + // BundleLookupTagAnnotation annotation used to store the bundle tag + BundleLookupTagAnnotation = "byoh.infrastructure.cluster.x-k8s.io/bundle-tag" ) // ByoHostSpec defines the desired state of ByoHost diff --git a/apis/infrastructure/v1beta1/byohost_webhook.go b/apis/infrastructure/v1beta1/byohost_webhook.go index 88f0f197f..58c2243e4 100644 --- a/apis/infrastructure/v1beta1/byohost_webhook.go +++ b/apis/infrastructure/v1beta1/byohost_webhook.go @@ -17,6 +17,7 @@ import ( // log is for logging in this package var byohostlog = logf.Log.WithName("byohost-resource") +// SetupWebhookWithManager sets up the webhook for the byohost resource func (byoHost *ByoHost) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). For(byoHost). diff --git a/controllers/infrastructure/byocluster_controller.go b/controllers/infrastructure/byocluster_controller.go index 4d5335777..950036a00 100644 --- a/controllers/infrastructure/byocluster_controller.go +++ b/controllers/infrastructure/byocluster_controller.go @@ -29,6 +29,7 @@ import ( ) var ( + // DefaultAPIEndpointPort default port for the API endpoint DefaultAPIEndpointPort = 6443 clusterControlledType = &infrav1.ByoCluster{} clusterControlledTypeName = reflect.TypeOf(clusterControlledType).Elem().Name() @@ -46,6 +47,7 @@ type ByoClusterReconciler struct { //+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=byoclusters/finalizers,verbs=update // +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters;clusters/status,verbs=get;list;watch +// Reconcile handles the byo cluster reconciliations func (r *ByoClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) { logger := log.FromContext(ctx) diff --git a/controllers/infrastructure/byomachine_controller.go b/controllers/infrastructure/byomachine_controller.go index c638e0360..9a3513955 100644 --- a/controllers/infrastructure/byomachine_controller.go +++ b/controllers/infrastructure/byomachine_controller.go @@ -41,9 +41,12 @@ import ( ) const ( - ProviderIDPrefix = "byoh://" + // ProviderIDPrefix prefix for provider id + ProviderIDPrefix = "byoh://" + // ProviderIDSuffixLength length of provider id suffix ProviderIDSuffixLength = 6 - RequeueForbyohost = 10 * time.Second + // RequeueForbyohost requeue delay for byoh host + RequeueForbyohost = 10 * time.Second ) // ByoMachineReconciler reconciles a ByoMachine object @@ -177,6 +180,7 @@ func (r *ByoMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) return r.reconcileNormal(ctx, machineScope) } +// FetchAttachedByoHost fetches BYOHost attached to this machine func (r *ByoMachineReconciler) FetchAttachedByoHost(ctx context.Context, byomachineName, byomachineNamespace string) (*infrav1.ByoHost, error) { logger := log.FromContext(ctx) logger.Info("Fetching an attached ByoHost") diff --git a/test/e2e/docker_helper.go b/test/e2e/docker_helper.go index 6e15edea5..1225f82b6 100644 --- a/test/e2e/docker_helper.go +++ b/test/e2e/docker_helper.go @@ -25,8 +25,8 @@ import ( ) const ( - KindImage = "byoh/node:v1.22.3" - TempKubeconfigPath = "/tmp/mgmt.conf" + kindImage = "byoh/node:v1.22.3" + tempKubeconfigPath = "/tmp/mgmt.conf" ) type cpConfig struct { @@ -37,6 +37,7 @@ type cpConfig struct { container string } +// ByoHostRunner runs bring-you-own-host cluster in docker type ByoHostRunner struct { Context context.Context clusterConName string @@ -160,7 +161,7 @@ func (r *ByoHostRunner) createDockerContainer() (container.ContainerCreateCreate return r.DockerClient.ContainerCreate(r.Context, &container.Config{Hostname: r.ByoHostName, - Image: KindImage, + Image: kindImage, }, &container.HostConfig{Privileged: true, SecurityOpt: []string{"seccomp=unconfined"}, @@ -200,14 +201,15 @@ func (r *ByoHostRunner) copyKubeconfig(config cpConfig, listopt types.ContainerL re := regexp.MustCompile("server:.*") kubeconfig = re.ReplaceAll(kubeconfig, []byte("server: https://"+profile.NetworkSettings.Networks[r.NetworkInterface].IPAddress+":6443")) } - Expect(os.WriteFile(TempKubeconfigPath, kubeconfig, 0644)).NotTo(HaveOccurred()) // nolint: gosec,gomnd + Expect(os.WriteFile(tempKubeconfigPath, kubeconfig, 0644)).NotTo(HaveOccurred()) // nolint: gosec,gomnd - config.sourcePath = TempKubeconfigPath + config.sourcePath = tempKubeconfigPath config.destPath = r.CommandArgs["--kubeconfig"] err := copyToContainer(r.Context, r.DockerClient, config) return err } +// SetupByoDockerHost sets up the byohost docker container func (r *ByoHostRunner) SetupByoDockerHost() (*container.ContainerCreateCreatedBody, error) { var byohost container.ContainerCreateCreatedBody var err error @@ -231,6 +233,7 @@ func (r *ByoHostRunner) SetupByoDockerHost() (*container.ContainerCreateCreatedB return &byohost, err } +// ExecByoDockerHost runs the exec command in the byohost docker container func (r *ByoHostRunner) ExecByoDockerHost(byohost *container.ContainerCreateCreatedBody) (types.HijackedResponse, string, error) { var cmdArgs []string cmdArgs = append(cmdArgs, "./agent") @@ -264,5 +267,8 @@ func setControlPlaneIP(ctx context.Context, dockerClient *client.Client) { // can safely use this IP for the ControlPlaneEndpoint ipOctets[3] = "151" ip := strings.Join(ipOctets, ".") - os.Setenv("CONTROL_PLANE_ENDPOINT_IP", ip) + err := os.Setenv("CONTROL_PLANE_ENDPOINT_IP", ip) + if err != nil { + Expect(err).NotTo(HaveOccurred()) + } } diff --git a/test/e2e/e2e_debug_helper.go b/test/e2e/e2e_debug_helper.go index a310c357e..27c22e541 100644 --- a/test/e2e/e2e_debug_helper.go +++ b/test/e2e/e2e_debug_helper.go @@ -14,11 +14,15 @@ import ( ) const ( - DefaultFileMode fs.FileMode = 0777 - ReadByohControllerManagerLogShellFile string = "/tmp/read-byoh-controller-manager-log.sh" - ReadAllPodsShellFile string = "/tmp/read-all-pods.sh" + // DefaultFileMode the default file mode of files created for tests + DefaultFileMode fs.FileMode = 0777 + // ReadByohControllerManagerLogShellFile location of script to read the controller manager log + ReadByohControllerManagerLogShellFile string = "/tmp/read-byoh-controller-manager-log.sh" + // ReadAllPodsShellFile location of script to read all pods logs + ReadAllPodsShellFile string = "/tmp/read-all-pods.sh" ) +// WriteDockerLog redirects the docker logs to the given file func WriteDockerLog(output types.HijackedResponse, outputFile string) *os.File { s := make(chan string) e := make(chan error) @@ -62,11 +66,13 @@ func WriteDockerLog(output types.HijackedResponse, outputFile string) *os.File { return f } +// Showf prints formatted string to stdout func Showf(format string, a ...interface{}) { fmt.Printf(format, a...) fmt.Printf("\n") } +// ShowFileContent prints to stdout the content of the given file func ShowFileContent(fileName string) { content, err := os.ReadFile(fileName) if err != nil { @@ -79,6 +85,7 @@ func ShowFileContent(fileName string) { Showf("######################End: Content of %s##################", fileName) } +// ExecuteShellScript executes a given shell script file location func ExecuteShellScript(shellFileName string) { cmd := exec.Command("/bin/sh", "-x", shellFileName) output, err := cmd.Output() @@ -91,6 +98,7 @@ func ExecuteShellScript(shellFileName string) { Showf("######################End: execute result of %s##################", shellFileName) } +// WriteShellScript writes shell script contents/commands to the given file location func WriteShellScript(shellFileName string, shellFileContent []string) { f, err := os.OpenFile(shellFileName, os.O_APPEND|os.O_WRONLY|os.O_CREATE, DefaultFileMode) if err != nil { @@ -117,6 +125,7 @@ func WriteShellScript(shellFileName string, shellFileContent []string) { } } +// ShowInfo shows all the pods status, agent logs, and controller manager logs func ShowInfo(allAgentLogFiles []string) { // show swap status // showFileContent("/proc/swaps")