From 7549fdbeb0bd6c5f6126bb9c6b6951984accb4b3 Mon Sep 17 00:00:00 2001 From: Alexander Hughes Date: Thu, 5 Mar 2020 11:39:13 -0500 Subject: [PATCH] [#86] remove unused code A number of items were identified by GoLand's code inspection as being unused. These are being removed in this change. Change-Id: I0c8c0b5f5c33f2e715f991a02ddd63174758c533 Signed-off-by: Alexander Hughes --- cmd/bootstrap/bootstrap.go | 2 +- cmd/bootstrap/bootstrap_isogen.go | 4 +- cmd/document/document.go | 2 +- cmd/document/secret/generate/generate.go | 10 +-- .../secret/generate/masterpassphrase.go | 3 +- cmd/document/secret/secret.go | 5 +- pkg/bootstrap/isogen/command.go | 2 +- pkg/cluster/initinfra/infra_test.go | 12 ---- pkg/config/constants.go | 63 +++++++++---------- pkg/container/container_docker.go | 2 +- pkg/container/container_docker_test.go | 12 ++-- pkg/document/constants.go | 2 - pkg/document/repo/repo.go | 13 +--- pkg/document/repo/repo_test.go | 6 +- pkg/environment/constants.go | 9 --- pkg/k8s/kubectl/kubectl_test.go | 4 +- pkg/remote/redfish/redfish.go | 2 +- pkg/remote/redfish/utils.go | 5 +- pkg/remote/remote_direct.go | 1 - testutil/k8sutils/mock_kubectl_factory.go | 2 +- testutil/utilities.go | 14 ----- 21 files changed, 57 insertions(+), 118 deletions(-) diff --git a/cmd/bootstrap/bootstrap.go b/cmd/bootstrap/bootstrap.go index 709d42e19..3712cfc34 100644 --- a/cmd/bootstrap/bootstrap.go +++ b/cmd/bootstrap/bootstrap.go @@ -13,7 +13,7 @@ func NewBootstrapCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Co Short: "Bootstrap ephemeral Kubernetes cluster", } - isoGenCmd := NewISOGenCommand(bootstrapRootCmd, rootSettings) + isoGenCmd := NewISOGenCommand(rootSettings) bootstrapRootCmd.AddCommand(isoGenCmd) remoteDirectCmd := NewRemoteDirectCommand(rootSettings) diff --git a/cmd/bootstrap/bootstrap_isogen.go b/cmd/bootstrap/bootstrap_isogen.go index 7f24fbefc..aacc13028 100644 --- a/cmd/bootstrap/bootstrap_isogen.go +++ b/cmd/bootstrap/bootstrap_isogen.go @@ -8,12 +8,12 @@ import ( ) // NewISOGenCommand creates a new command for ISO image creation -func NewISOGenCommand(parent *cobra.Command, rootSettings *environment.AirshipCTLSettings) *cobra.Command { +func NewISOGenCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { imageGen := &cobra.Command{ Use: "isogen", Short: "Generate bootstrap ISO image", RunE: func(cmd *cobra.Command, args []string) error { - return isogen.GenerateBootstrapIso(rootSettings, args) + return isogen.GenerateBootstrapIso(rootSettings) }, } diff --git a/cmd/document/document.go b/cmd/document/document.go index 61f0735e3..16d0e6e53 100644 --- a/cmd/document/document.go +++ b/cmd/document/document.go @@ -15,7 +15,7 @@ func NewDocumentCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com } documentRootCmd.AddCommand(NewDocumentPullCommand(rootSettings)) - documentRootCmd.AddCommand(secret.NewSecretCommand(rootSettings)) + documentRootCmd.AddCommand(secret.NewSecretCommand()) documentRootCmd.AddCommand(NewRenderCommand(rootSettings)) return documentRootCmd diff --git a/cmd/document/secret/generate/generate.go b/cmd/document/secret/generate/generate.go index d6cdc8047..6ab66eb43 100644 --- a/cmd/document/secret/generate/generate.go +++ b/cmd/document/secret/generate/generate.go @@ -1,20 +1,16 @@ package generate -import ( - "github.com/spf13/cobra" - - "opendev.org/airship/airshipctl/pkg/environment" -) +import "github.com/spf13/cobra" // NewGenerateCommand creates a new command for generating secret information -func NewGenerateCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { +func NewGenerateCommand() *cobra.Command { generateRootCmd := &cobra.Command{ Use: "generate", // TODO(howell): Make this more expressive Short: "generates various secrets", } - generateRootCmd.AddCommand(NewGenerateMasterPassphraseCommand(rootSettings)) + generateRootCmd.AddCommand(NewGenerateMasterPassphraseCommand()) return generateRootCmd } diff --git a/cmd/document/secret/generate/masterpassphrase.go b/cmd/document/secret/generate/masterpassphrase.go index dbf8171b2..4862f3841 100644 --- a/cmd/document/secret/generate/masterpassphrase.go +++ b/cmd/document/secret/generate/masterpassphrase.go @@ -5,12 +5,11 @@ import ( "github.com/spf13/cobra" - "opendev.org/airship/airshipctl/pkg/environment" "opendev.org/airship/airshipctl/pkg/secret" ) // NewGenerateMasterPassphraseCommand creates a new command for generating secret information -func NewGenerateMasterPassphraseCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { +func NewGenerateMasterPassphraseCommand() *cobra.Command { masterPassphraseCmd := &cobra.Command{ Use: "masterpassphrase", // TODO(howell): Make this more expressive diff --git a/cmd/document/secret/secret.go b/cmd/document/secret/secret.go index d8ef1f82d..9a02bab6a 100644 --- a/cmd/document/secret/secret.go +++ b/cmd/document/secret/secret.go @@ -4,18 +4,17 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/cmd/document/secret/generate" - "opendev.org/airship/airshipctl/pkg/environment" ) // NewSecretCommand creates a new command for managing airshipctl secrets -func NewSecretCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { +func NewSecretCommand() *cobra.Command { secretRootCmd := &cobra.Command{ Use: "secret", // TODO(howell): Make this more expressive Short: "manages secrets", } - secretRootCmd.AddCommand(generate.NewGenerateCommand(rootSettings)) + secretRootCmd.AddCommand(generate.NewGenerateCommand()) return secretRootCmd } diff --git a/pkg/bootstrap/isogen/command.go b/pkg/bootstrap/isogen/command.go index 62c1e4d5f..dba3b6236 100644 --- a/pkg/bootstrap/isogen/command.go +++ b/pkg/bootstrap/isogen/command.go @@ -21,7 +21,7 @@ const ( ) // GenerateBootstrapIso will generate data for cloud init and start ISO builder container -func GenerateBootstrapIso(settings *environment.AirshipCTLSettings, args []string) error { +func GenerateBootstrapIso(settings *environment.AirshipCTLSettings) error { ctx := context.Background() globalConf := settings.Config() diff --git a/pkg/cluster/initinfra/infra_test.go b/pkg/cluster/initinfra/infra_test.go index d2aee9616..4edbddd0f 100644 --- a/pkg/cluster/initinfra/infra_test.go +++ b/pkg/cluster/initinfra/infra_test.go @@ -26,18 +26,6 @@ type TestClient struct { func (tc TestClient) ClientSet() kubernetes.Interface { return tc.MockClientset() } func (tc TestClient) Kubectl() kubectl.Interface { return tc.MockKubectl() } -type TestKubectl struct { - MockApply func() error - MockApplyOptions func() (*kubectl.ApplyOptions, error) -} - -func (tk TestKubectl) Apply(docs []document.Document, ao *kubectl.ApplyOptions) error { - return tk.MockApply() -} -func (tk TestKubectl) ApplyOptions() (*kubectl.ApplyOptions, error) { - return tk.MockApplyOptions() -} - const ( kubeconfigPath = "testdata/kubeconfig.yaml" filenameRC = "testdata/replicationcontroller.yaml" diff --git a/pkg/config/constants.go b/pkg/config/constants.go index 0f4da582d..333b336d9 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -16,18 +16,15 @@ var AllClusterTypes = [2]string{Ephemeral, Target} // Constants defining default values const ( - AirshipConfigGroup = "airshipit.org" - AirshipConfigVersion = "v1alpha1" - AirshipConfigAPIVersion = AirshipConfigGroup + "/" + AirshipConfigVersion - AirshipConfigKind = "Config" - - AirshipConfigDir = ".airship" - AirshipConfig = "config" - AirshipKubeConfig = "kubeconfig" - - AirshipConfigEnv = "AIRSHIPCONFIG" - AirshipKubeConfigEnv = "AIRSHIP_KUBECONFIG" - + AirshipConfigGroup = "airshipit.org" + AirshipConfigVersion = "v1alpha1" + AirshipConfigAPIVersion = AirshipConfigGroup + "/" + AirshipConfigVersion + AirshipConfigKind = "Config" + AirshipConfigDir = ".airship" + AirshipConfig = "config" + AirshipKubeConfig = "kubeconfig" + AirshipConfigEnv = "AIRSHIPCONFIG" + AirshipKubeConfigEnv = "AIRSHIP_KUBECONFIG" AirshipDefaultContext = "default" AirshipDefaultManifest = "default" AirshipDefaultManifestRepo = "treasuremap" @@ -39,27 +36,25 @@ const ( AirshipDefaultRemoteType = "redfish" ) -// Constants defining CLI flags const ( - FlagAPIServer = "server" - FlagAuthInfoName = "user" - FlagBearerToken = "token" - FlagCAFile = "certificate-authority" - FlagCertFile = "client-certificate" - FlagClusterName = "cluster" - FlagClusterType = "cluster-type" - FlagContext = "context" - FlagCurrentContext = "current-context" - FlagConfigFilePath = "airshipconf" - FlagEmbedCerts = "embed-certs" - FlagImpersonate = "as" - FlagImpersonateGroup = "as-group" - FlagInsecure = "insecure-skip-tls-verify" - FlagKeyFile = "client-key" - FlagManifest = "manifest" - FlagNamespace = "namespace" - FlagPassword = "password" - FlagTimeout = "request-timeout" - FlagUsername = "username" - FlagCurrent = "current" + FlagAPIServer = "server" + FlagAuthInfoName = "user" + FlagBearerToken = "token" + FlagCAFile = "certificate-authority" + FlagCertFile = "client-certificate" + FlagClusterName = "cluster" + FlagClusterType = "cluster-type" + + FlagCurrentContext = "current-context" + FlagConfigFilePath = "airshipconf" + FlagEmbedCerts = "embed-certs" + + FlagInsecure = "insecure-skip-tls-verify" + FlagKeyFile = "client-key" + FlagManifest = "manifest" + FlagNamespace = "namespace" + FlagPassword = "password" + + FlagUsername = "username" + FlagCurrent = "current" ) diff --git a/pkg/container/container_docker.go b/pkg/container/container_docker.go index 89bacb15c..202197816 100644 --- a/pkg/container/container_docker.go +++ b/pkg/container/container_docker.go @@ -218,7 +218,7 @@ func (c *DockerContainer) RunCommand( volumeMounts []string, envVars []string, // TODO (D. Ukov) add debug logic - debug bool, + _ bool, ) error { realCmd, err := c.getCmd(cmd) if err != nil { diff --git a/pkg/container/container_docker_test.go b/pkg/container/container_docker_test.go index 5afccc36f..cfdd9137a 100644 --- a/pkg/container/container_docker_test.go +++ b/pkg/container/container_docker_test.go @@ -27,12 +27,12 @@ func (mc mockConn) Write(b []byte) (n int, err error) { copy(mc.WData, b) return len(b), nil } -func (mc mockConn) Close() error { return nil } -func (mc mockConn) LocalAddr() net.Addr { return nil } -func (mc mockConn) RemoteAddr() net.Addr { return nil } -func (mc mockConn) SetDeadline(t time.Time) error { return nil } -func (mc mockConn) SetReadDeadline(t time.Time) error { return nil } -func (mc mockConn) SetWriteDeadline(t time.Time) error { return nil } +func (mc mockConn) Close() error { return nil } +func (mc mockConn) LocalAddr() net.Addr { return nil } +func (mc mockConn) RemoteAddr() net.Addr { return nil } +func (mc mockConn) SetDeadline(time.Time) error { return nil } +func (mc mockConn) SetReadDeadline(time.Time) error { return nil } +func (mc mockConn) SetWriteDeadline(time.Time) error { return nil } type mockDockerClient struct { imageInspectWithRaw func() (types.ImageInspect, []byte, error) diff --git a/pkg/document/constants.go b/pkg/document/constants.go index df1d2e187..c12a0e954 100644 --- a/pkg/document/constants.go +++ b/pkg/document/constants.go @@ -1,11 +1,9 @@ package document -// Document labels and annotations const ( // Selectors BaseAirshipSelector = "airshipit.org" EphemeralClusterSelector = BaseAirshipSelector + "/ephemeral in (True, true)" - TargetClusterSelector = BaseAirshipSelector + "/target in (True, true)" // Labels DeployedByLabel = BaseAirshipSelector + "/deployed" diff --git a/pkg/document/repo/repo.go b/pkg/document/repo/repo.go index 6934bdf90..ac24b5b6c 100644 --- a/pkg/document/repo/repo.go +++ b/pkg/document/repo/repo.go @@ -17,18 +17,9 @@ import ( "opendev.org/airship/airshipctl/pkg/log" ) -const ( - SSHAuth = "ssh-key" - SSHPass = "ssh-pass" - HTTPBasic = "http-basic" - - DefaultRemoteName = "origin" -) - var ( - ErrNoOpenRepo = errors.New("no open repository is stored") - ErrRemoteRefNotImplemented = errors.New("remoteref is not yet implemented") - ErrCantParseURL = errors.New("could not get target directory from url") + ErrNoOpenRepo = errors.New("no open repository is stored") + ErrCantParseURL = errors.New("could not get target directory from url") ) type OptionsBuilder interface { diff --git a/pkg/document/repo/repo_test.go b/pkg/document/repo/repo_test.go index 29f9627c4..c5b42383e 100644 --- a/pkg/document/repo/repo_test.go +++ b/pkg/document/repo/repo_test.go @@ -27,13 +27,13 @@ type mockBuilder struct { func (md mockBuilder) ToAuth() (transport.AuthMethod, error) { return md.AuthMethod, md.AuthError } -func (md mockBuilder) ToCloneOptions(auth transport.AuthMethod) *git.CloneOptions { +func (md mockBuilder) ToCloneOptions(transport.AuthMethod) *git.CloneOptions { return md.CloneOptions } -func (md mockBuilder) ToCheckoutOptions(force bool) *git.CheckoutOptions { +func (md mockBuilder) ToCheckoutOptions(bool) *git.CheckoutOptions { return md.CheckoutOptions } -func (md mockBuilder) ToFetchOptions(auth transport.AuthMethod) *git.FetchOptions { +func (md mockBuilder) ToFetchOptions(transport.AuthMethod) *git.FetchOptions { return md.FetchOptions } func (md mockBuilder) URL() string { return md.URLString } diff --git a/pkg/environment/constants.go b/pkg/environment/constants.go index 9b48cea41..449fedbbe 100644 --- a/pkg/environment/constants.go +++ b/pkg/environment/constants.go @@ -3,13 +3,4 @@ package environment // OutputFormat denotes the form with which to display tabulated data type OutputFormat string -// These are valid values for OutputFormat -const ( - Default = "" - JSON = "json" - YAML = "yaml" - NameOnly = "name" - Wide = "wide" -) - const HomeEnvVar = "$HOME" diff --git a/pkg/k8s/kubectl/kubectl_test.go b/pkg/k8s/kubectl/kubectl_test.go index 4356d7bea..8e5b761d5 100644 --- a/pkg/k8s/kubectl/kubectl_test.go +++ b/pkg/k8s/kubectl/kubectl_test.go @@ -28,8 +28,8 @@ type MockFileSystem struct { document.FileSystem } -func (fsys MockFileSystem) RemoveAll(name string) error { return fsys.MockRemoveAll() } -func (fsys MockFileSystem) TempFile(bufferDir string, prefix string) (document.File, error) { +func (fsys MockFileSystem) RemoveAll(string) error { return fsys.MockRemoveAll() } +func (fsys MockFileSystem) TempFile(string, string) (document.File, error) { return fsys.MockTempFile() } diff --git a/pkg/remote/redfish/redfish.go b/pkg/remote/redfish/redfish.go index aaf44e511..0d38cc936 100644 --- a/pkg/remote/redfish/redfish.go +++ b/pkg/remote/redfish/redfish.go @@ -48,7 +48,7 @@ func (cfg RemoteDirect) DoRemoteDirect() error { alog.Debugf("Ephemeral node managerID: '%s'", managerID) /* Get manager's Cd or DVD virtual media ID */ - vMediaID, vMediaType, err := GetVirtualMediaID(cfg.Context, cfg.RedfishAPI, managerID) + vMediaID, vMediaType, err := GetVirtualMediaID() if err != nil { return err } diff --git a/pkg/remote/redfish/utils.go b/pkg/remote/redfish/utils.go index 7f7f4c0b3..0993a1738 100644 --- a/pkg/remote/redfish/utils.go +++ b/pkg/remote/redfish/utils.go @@ -46,10 +46,7 @@ func IsIDInList(idRefList []redfishClient.IdRef, id string) bool { // This function walks through the list of manager's virtual media resources // and gets the ID of virtualmedia which has type "CD" or "DVD" -func GetVirtualMediaID(ctx context.Context, - api redfishApi.RedfishAPI, - managerID string, -) (string, string, error) { +func GetVirtualMediaID() (string, string, error) { // TODO: Sushy emulator has a bug which sends 'virtualMedia.inserted' field as // string instead of a boolean which causes the redfish client to fail // while unmarshalling this field. diff --git a/pkg/remote/remote_direct.go b/pkg/remote/remote_direct.go index cee56536a..160945109 100644 --- a/pkg/remote/remote_direct.go +++ b/pkg/remote/remote_direct.go @@ -15,7 +15,6 @@ import ( const ( AirshipRemoteTypeRedfish string = "redfish" - AirshipRemoteTypeSmash string = "smash" AirshipHostKind string = "BareMetalHost" ) diff --git a/testutil/k8sutils/mock_kubectl_factory.go b/testutil/k8sutils/mock_kubectl_factory.go index 2bb13c8fc..855dd7e24 100644 --- a/testutil/k8sutils/mock_kubectl_factory.go +++ b/testutil/k8sutils/mock_kubectl_factory.go @@ -49,7 +49,7 @@ func (f *MockKubectlFactory) ToDiscoveryClient() (discovery.CachedDiscoveryInter } func (f *MockKubectlFactory) DynamicClient() (dynamic.Interface, error) { return f.MockDynamicClient() } func (f *MockKubectlFactory) OpenAPISchema() (openapi.Resources, error) { return f.MockOpenAPISchema() } -func (f *MockKubectlFactory) Validator(validate bool) (validation.Schema, error) { +func (f *MockKubectlFactory) Validator(bool) (validation.Schema, error) { return f.MockValidator() } func (f *MockKubectlFactory) ToRESTMapper() (meta.RESTMapper, error) { return f.MockToRESTMapper() } diff --git a/testutil/utilities.go b/testutil/utilities.go index d6f5dd3c8..8fdeedf1f 100644 --- a/testutil/utilities.go +++ b/testutil/utilities.go @@ -63,20 +63,6 @@ func RunTest(t *testing.T, test *CmdTest) { } } -// ReadFixtureBytes is a convenience function for opening a test fixture -func ReadFixtureBytes(t *testing.T, filename string) []byte { - t.Helper() - fixtureData, err := ioutil.ReadFile(filename) - require.NoErrorf(t, err, "Unexpected error while reading fixture at %s", filename) - return fixtureData -} - -// ReadFixtureString is a convenience function for opening a test fixture -func ReadFixtureString(t *testing.T, filename string) string { - t.Helper() - return string(ReadFixtureBytes(t, filename)) -} - func updateGolden(t *testing.T, test *CmdTest, actual []byte) { t.Helper() goldenDir := filepath.Join(testdataDir, t.Name()+goldenDirSuffix)