Skip to content

Commit

Permalink
remove unused code and fix a bunch of linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavmpandey08 committed Apr 9, 2024
1 parent c6d4af1 commit 5f19795
Show file tree
Hide file tree
Showing 33 changed files with 88 additions and 152 deletions.
5 changes: 2 additions & 3 deletions cmd/eks-a-tool/cmd/uniqueip.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"log"

Expand All @@ -18,7 +17,7 @@ var uniqueIpCmd = &cobra.Command{
Long: "Generate a random unique IP to be used for control plane endpoint ip",
PreRun: preRunUniqueIp,
RunE: func(cmd *cobra.Command, args []string) error {
uniqueIp, err := generateUniqueIP(cmd.Context())
uniqueIp, err := generateUniqueIP()

Check warning on line 20 in cmd/eks-a-tool/cmd/uniqueip.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var uniqueIp should be uniqueIP (revive)
if err != nil {
log.Fatalf("Error generating unique ip: %v", err)
}
Expand All @@ -45,7 +44,7 @@ func preRunUniqueIp(cmd *cobra.Command, args []string) {
})
}

func generateUniqueIP(ctx context.Context) (string, error) {
func generateUniqueIP() (string, error) {
cidr := viper.GetString("cidr")
ipgen := networkutils.NewIPGenerator(&networkutils.DefaultNetClient{})
return ipgen.GenerateUniqueIP(cidr)
Expand Down
5 changes: 2 additions & 3 deletions cmd/eks-a-tool/cmd/vsphereautofill.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"log"
"os"
Expand All @@ -26,7 +25,7 @@ var autofillCmd = &cobra.Command{
Long: "Fills provider config with values set in environment variables",
PreRun: preRunAutofill,
RunE: func(cmd *cobra.Command, args []string) error {
err := autofill(cmd.Context())
err := autofill()
if err != nil {
log.Fatalf("Error filling the provider config: %v", err)
}
Expand All @@ -52,7 +51,7 @@ func preRunAutofill(cmd *cobra.Command, args []string) {
})
}

func autofill(ctx context.Context) error {
func autofill() error {

Check failure on line 54 in cmd/eks-a-tool/cmd/vsphereautofill.go

View workflow job for this annotation

GitHub Actions / lint

cyclomatic complexity 15 of func `autofill` is high (> 10) (gocyclo)
clusterConfigFileName := viper.GetString("filename")
clusterConfigFileExist := validations.FileExists(clusterConfigFileName)
if !clusterConfigFileExist {
Expand Down
4 changes: 1 addition & 3 deletions cmd/eksctl-anywhere/cmd/copypackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var copyPackagesCmd = &cobra.Command{
RunE: runCopyPackages,
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return fmt.Errorf("A destination registry must be specified as an argument")
return fmt.Errorf("destination registry must be specified as an argument")
}
return nil
},
Expand Down Expand Up @@ -68,8 +68,6 @@ func init() {

var cpc = copyPackagesConfig{}

var publicPackages = []string{"ecr-token-refresher", "eks-anywhere-packages", "credential-provider-package"}

// copyPackagesConfig copies packages specified in a bundle to a destination.
type copyPackagesConfig struct {
destRegistry string
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (cc *createClusterOptions) createCluster(cmd *cobra.Command, _ []string) er
return err
}

clusterManagerTimeoutOpts, err := buildClusterManagerOpts(cc.timeoutOptions, clusterSpec.Cluster.Spec.DatacenterRef.Kind)
clusterManagerTimeoutOpts, err := buildClusterManagerOpts(cc.timeoutOptions)
if err != nil {
return fmt.Errorf("failed to build cluster manager opts: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/generatepackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var generatePackageCommand = &cobra.Command{
if err := cobra.ExactArgs(1)(cmd, args); err == nil {
return nil
}
return fmt.Errorf("The name of the package to install must be specified as an argument")
return fmt.Errorf("name of the package to install must be specified as an argument")
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/installpackages.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var installPackageCommand = &cobra.Command{
if err := cobra.ExactArgs(1)(cmd, args); err == nil {
return nil
}
return fmt.Errorf("The name of the package to install must be specified as an argument")
return fmt.Errorf("name of the package to install must be specified as an argument")
},
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/eksctl-anywhere/cmd/listimages.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"log"

Expand Down Expand Up @@ -37,11 +36,11 @@ var listImagesCommand = &cobra.Command{
},
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return listImages(cmd.Context(), lio.fileName, lio.bundlesOverride)
return listImages(lio.fileName, lio.bundlesOverride)
},
}

func listImages(context context.Context, clusterSpecPath, bundlesOverride string) error {
func listImages(clusterSpecPath, bundlesOverride string) error {
images, err := getImages(clusterSpecPath, bundlesOverride)
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions cmd/eksctl-anywhere/cmd/listovas.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -48,14 +47,14 @@ var listOvasCmd = &cobra.Command{
PreRunE: preRunListOvasCmd,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := listOvas(cmd.Context(), listOvaOpts.fileName, listOvaOpts.bundlesOverride); err != nil {
if err := listOvas(listOvaOpts.fileName, listOvaOpts.bundlesOverride); err != nil {
return err
}
return nil
},
}

func listOvas(context context.Context, clusterSpecPath, bundlesOverride string) error {
func listOvas(clusterSpecPath, bundlesOverride string) error {
var specOpts []cluster.FileSpecBuilderOpt
if bundlesOverride != "" {
specOpts = append(specOpts, cluster.WithOverrideBundlesManifest(bundlesOverride))
Expand Down
4 changes: 1 addition & 3 deletions cmd/eksctl-anywhere/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
releasev1 "github.com/aws/eks-anywhere/release/api/v1alpha1"
)

const defaultTinkerbellNodeStartupTimeout = 20 * time.Minute

const timeoutErrorTemplate = "failed to parse timeout %s: %v"

type timeoutOptions struct {
Expand All @@ -50,7 +48,7 @@ func applyTimeoutFlags(flagSet *pflag.FlagSet, t *timeoutOptions) {

// buildClusterManagerOpts builds options for constructing a ClusterManager from CLI flags.
// datacenterKind is an API kind such as v1alpha1.TinkerbellDatacenterKind.
func buildClusterManagerOpts(t timeoutOptions, datacenterKind string) (*dependencies.ClusterManagerTimeoutOptions, error) {
func buildClusterManagerOpts(t timeoutOptions) (*dependencies.ClusterManagerTimeoutOptions, error) {
cpWaitTimeout, err := time.ParseDuration(t.cpWaitTimeout)
if err != nil {
return nil, fmt.Errorf(timeoutErrorTemplate, cpWaitTimeoutFlag, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/upgradecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (uc *upgradeClusterOptions) upgradeCluster(cmd *cobra.Command, args []strin
return err
}

clusterManagerTimeoutOpts, err := buildClusterManagerOpts(uc.timeoutOptions, clusterSpec.Cluster.Spec.DatacenterRef.Kind)
clusterManagerTimeoutOpts, err := buildClusterManagerOpts(uc.timeoutOptions)
if err != nil {
return fmt.Errorf("failed to build cluster manager opts: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/upgradeplancluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func serialize(componentChangeDiffs *types.ChangeDiff, outputFormat string) (str
}

func serializeToText(componentChangeDiffs *types.ChangeDiff) (string, error) {
if componentChangeDiffs == nil || (componentChangeDiffs != nil && len(componentChangeDiffs.ComponentReports) == 0) {
if componentChangeDiffs == nil || len(componentChangeDiffs.ComponentReports) == 0 {
return "All the components are up to date with the latest versions", nil
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/integration_test/cmd/cleanupaws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"log"

Expand All @@ -25,7 +24,7 @@ var cleanUpAwsCmd = &cobra.Command{
SilenceUsage: true,
PreRun: preRunCleanUpAwsSetup,
RunE: func(cmd *cobra.Command, args []string) error {
err := cleanUpAwsTestResources(cmd.Context())
err := cleanUpAwsTestResources()
if err != nil {
logger.Fatal(err, "Failed to cleanup e2e resources on aws")
}
Expand Down Expand Up @@ -57,7 +56,7 @@ func init() {
}
}

func cleanUpAwsTestResources(ctx context.Context) error {
func cleanUpAwsTestResources() error {
maxAge := viper.GetString(maxAgeFlagName)
storageBucket := viper.GetString(storageBucketFlagName)
tag := viper.GetString(tagFlagName)
Expand Down
5 changes: 2 additions & 3 deletions cmd/integration_test/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"log"

Expand Down Expand Up @@ -36,7 +35,7 @@ var runE2ECmd = &cobra.Command{
SilenceUsage: true,
PreRun: preRunSetup,
RunE: func(cmd *cobra.Command, args []string) error {
err := runE2E(cmd.Context())
err := runE2E()
if err != nil {
logger.Fatal(err, "Failed to run e2e test")
}
Expand Down Expand Up @@ -78,7 +77,7 @@ func init() {
}
}

func runE2E(ctx context.Context) error {
func runE2E() error {
instanceConfigFile := viper.GetString(instanceConfigFlagName)
storageBucket := viper.GetString(storageBucketFlagName)
jobId := viper.GetString(jobIdFlagName)
Expand Down
4 changes: 0 additions & 4 deletions pkg/api/v1alpha1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,6 @@ func validateWorkerNodeGroups(clusterConfig *Cluster) error {
return errors.New("cannot taint control plane when there is no worker node")
}

if len(workerNodeGroupConfigs) == 0 && clusterConfig.Spec.KubernetesVersion <= Kube121 {
return errors.New("Empty workerNodeGroupConfigs is not supported for kube version <= 1.21")
}

return nil
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/api/v1alpha1/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v1alpha1
import (
"errors"
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -1506,7 +1505,7 @@ func Test_ParseClusterConfigFromContent(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
content, err := ioutil.ReadFile(test.fileName)
content, err := os.ReadFile(test.fileName)
require.NoError(t, err)

err = ParseClusterConfigFromContent(content, test.clusterConfig)
Expand Down
3 changes: 1 addition & 2 deletions pkg/executables/clusterctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"

"github.com/aws/eks-anywhere/pkg/cluster"
anywherecluster "github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/clusterapi"
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/filewriter"
Expand Down Expand Up @@ -247,7 +246,7 @@ func (c *Clusterctl) InitInfrastructure(ctx context.Context, managementComponent
return nil
}

func (c *Clusterctl) buildConfig(managementComponents *anywherecluster.ManagementComponents, clusterName string, provider providers.Provider) (*clusterctlConfiguration, error) {
func (c *Clusterctl) buildConfig(managementComponents *cluster.ManagementComponents, clusterName string, provider providers.Provider) (*clusterctlConfiguration, error) {
t := templater.New(c.writer)

path, err := os.Getwd()
Expand Down
4 changes: 2 additions & 2 deletions pkg/executables/dockerlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func (e *linuxDockerExecutable) Command(ctx context.Context, args ...string) *Co
}

func (e *linuxDockerExecutable) Run(cmd *Command) (stdout bytes.Buffer, err error) {
return execute(cmd.ctx, "docker", cmd.stdIn, cmd.envVars, e.buildCommand(cmd.envVars, e.cli, cmd.args...)...)
return execute(cmd.ctx, "docker", cmd.stdIn, cmd.envVars, e.buildCommand(cmd.envVars, cmd.args...)...)
}

func (e *linuxDockerExecutable) buildCommand(envs map[string]string, cli string, args ...string) []string {
func (e *linuxDockerExecutable) buildCommand(envs map[string]string, args ...string) []string {
var envVars []string
for k, v := range envs {
envVars = append(envVars, "-e", fmt.Sprintf("%s=%s", k, v))
Expand Down
14 changes: 7 additions & 7 deletions pkg/executables/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func (k *Kubectl) Wait(ctx context.Context, kubeconfig string, timeout string, f

// WaitJSONPathLoop will wait for a given JSONPath to reach a required state similar to wait command for objects without conditions.
// This will be deprecated in favor of WaitJSONPath after version 1.23.
func (k *Kubectl) WaitJSONPathLoop(ctx context.Context, kubeconfig string, timeout string, jsonpath, forCondition string, property string, namespace string, opts ...KubectlOpt) error {
func (k *Kubectl) WaitJSONPathLoop(ctx context.Context, kubeconfig string, timeout string, jsonpath, forCondition string, property string, namespace string) error {
// On each retry kubectl wait timeout values will have to be adjusted to only wait for the remaining timeout duration.
// Here we establish an absolute timeout time for this based on the caller-specified timeout.
timeoutDuration, err := time.ParseDuration(timeout)
Expand All @@ -522,7 +522,7 @@ func (k *Kubectl) WaitJSONPathLoop(ctx context.Context, kubeconfig string, timeo
retrier := retrier.New(timeoutDuration, retrier.WithRetryPolicy(k.kubectlWaitRetryPolicy))
err = retrier.Retry(
func() error {
return k.waitJSONPathLoop(ctx, kubeconfig, timeout, jsonpath, forCondition, property, namespace, opts...)
return k.waitJSONPathLoop(ctx, kubeconfig, timeout, jsonpath, forCondition, property, namespace)
},
)
if err != nil {
Expand All @@ -532,7 +532,7 @@ func (k *Kubectl) WaitJSONPathLoop(ctx context.Context, kubeconfig string, timeo
}

// WaitJSONPath will wait for a given JSONPath of a required state. Only compatible on K8s 1.23+.
func (k *Kubectl) WaitJSONPath(ctx context.Context, kubeconfig string, timeout string, jsonpath, forCondition string, property string, namespace string, opts ...KubectlOpt) error {
func (k *Kubectl) WaitJSONPath(ctx context.Context, kubeconfig string, timeout string, jsonpath, forCondition string, property string, namespace string) error {
// On each retry kubectl wait timeout values will have to be adjusted to only wait for the remaining timeout duration.
// Here we establish an absolute timeout time for this based on the caller-specified timeout.
timeoutDuration, err := time.ParseDuration(timeout)
Expand All @@ -546,7 +546,7 @@ func (k *Kubectl) WaitJSONPath(ctx context.Context, kubeconfig string, timeout s
retrier := retrier.New(timeoutDuration, retrier.WithRetryPolicy(k.kubectlWaitRetryPolicy))
err = retrier.Retry(
func() error {
return k.waitJSONPath(ctx, kubeconfig, timeout, jsonpath, forCondition, property, namespace, opts...)
return k.waitJSONPath(ctx, kubeconfig, timeout, jsonpath, forCondition, property, namespace)
},
)
if err != nil {
Expand Down Expand Up @@ -592,7 +592,7 @@ func (k *Kubectl) wait(ctx context.Context, kubeconfig string, timeoutTime time.
return nil
}

func (k *Kubectl) waitJSONPath(ctx context.Context, kubeconfig, timeout string, jsonpath string, forCondition string, property string, namespace string, opts ...KubectlOpt) error {
func (k *Kubectl) waitJSONPath(ctx context.Context, kubeconfig, timeout string, jsonpath string, forCondition string, property string, namespace string) error {
if jsonpath == "" || forCondition == "" {
return fmt.Errorf("empty conditions params passed to waitJSONPath()")
}
Expand All @@ -607,7 +607,7 @@ func (k *Kubectl) waitJSONPath(ctx context.Context, kubeconfig, timeout string,
}

// waitJsonPathLoop will be deprecated in favor of waitJsonPath after version 1.23.
func (k *Kubectl) waitJSONPathLoop(ctx context.Context, kubeconfig string, timeout string, jsonpath string, forCondition string, property string, namespace string, opts ...KubectlOpt) error {
func (k *Kubectl) waitJSONPathLoop(ctx context.Context, kubeconfig string, timeout string, jsonpath string, forCondition string, property string, namespace string) error {
if jsonpath == "" || forCondition == "" {
return fmt.Errorf("empty conditions params passed to waitJSONPathLoop()")
}
Expand Down Expand Up @@ -1059,7 +1059,7 @@ func (k *Kubectl) getPodLogs(ctx context.Context, namespace, podName, containerN
}
logs := stdOut.String()
if strings.Contains(logs, "Internal Error") {
return "", fmt.Errorf("Fetched log contains \"Internal Error\": %q", logs)
return "", fmt.Errorf("fetched log contains \"Internal Error\": %q", logs)
}
return logs, err
}
Expand Down

0 comments on commit 5f19795

Please sign in to comment.