[#58] Update var names to be golint compliant
This patch resolves complaints from golint such as: cmd/config/set_authinfo_test.go:84:3: don't use leading k in Go names; pkg/remote/redfish/redfish.go:39:2: var systemId should be systemID pkg/remote/redfish/redfish.go:47:2: var managerId should be managerID pkg/remote/redfish/redfish.go:51:2: var vMediaId should be vMediaID pkg/remote/redfish/redfish.go:115:2: var parsedUrl should be parsedURL pkg/remote/redfish/utils.go:29:2: var trimmedUrl should be trimmedURL pkg/remote/redfish/utils.go:39:3: var rId should be rID Relates-To: #58 Change-Id: I758565c84b44aac118d5f1cbf714224ab1ff82c5 Signed-off-by: Alexander Hughes <Alexander.Hughes@pm.me>
This commit is contained in:
parent
f66f94dc80
commit
dd1dba6eb3
@ -172,10 +172,10 @@ func TestModifyCluster(t *testing.T) {
|
|||||||
clusterName.WithType(tname, tctype)
|
clusterName.WithType(tname, tctype)
|
||||||
given.Clusters[tname].ClusterTypes[tctype] = config.NewCluster()
|
given.Clusters[tname].ClusterTypes[tctype] = config.NewCluster()
|
||||||
given.Clusters[tname].ClusterTypes[tctype].NameInKubeconf = clusterName.Name()
|
given.Clusters[tname].ClusterTypes[tctype].NameInKubeconf = clusterName.Name()
|
||||||
kCluster := kubeconfig.NewCluster()
|
cluster := kubeconfig.NewCluster()
|
||||||
kCluster.Server = "https://192.168.0.10"
|
cluster.Server = "https://192.168.0.10"
|
||||||
given.KubeConfig().Clusters[clusterName.Name()] = kCluster
|
given.KubeConfig().Clusters[clusterName.Name()] = cluster
|
||||||
given.Clusters[tname].ClusterTypes[tctype].SetKubeCluster(kCluster)
|
given.Clusters[tname].ClusterTypes[tctype].SetKubeCluster(cluster)
|
||||||
|
|
||||||
expected, cleanupExpected := config.InitConfig(t)
|
expected, cleanupExpected := config.InitConfig(t)
|
||||||
defer cleanupExpected(t)
|
defer cleanupExpected(t)
|
||||||
|
@ -551,13 +551,13 @@ func (c *Config) AddContext(theContext *ContextOptions) *Context {
|
|||||||
nContext := NewContext()
|
nContext := NewContext()
|
||||||
c.Contexts[theContext.Name] = nContext
|
c.Contexts[theContext.Name] = nContext
|
||||||
// Create a new Kubeconfig Context object as well
|
// Create a new Kubeconfig Context object as well
|
||||||
kContext := clientcmdapi.NewContext()
|
context := clientcmdapi.NewContext()
|
||||||
nContext.NameInKubeconf = theContext.Name
|
nContext.NameInKubeconf = theContext.Name
|
||||||
contextName := NewClusterComplexName()
|
contextName := NewClusterComplexName()
|
||||||
contextName.WithType(theContext.Name, theContext.ClusterType)
|
contextName.WithType(theContext.Name, theContext.ClusterType)
|
||||||
|
|
||||||
nContext.SetKubeContext(kContext)
|
nContext.SetKubeContext(context)
|
||||||
c.KubeConfig().Contexts[theContext.Name] = kContext
|
c.KubeConfig().Contexts[theContext.Name] = context
|
||||||
|
|
||||||
// Ok , I have initialized structs for the Context information
|
// Ok , I have initialized structs for the Context information
|
||||||
// We can use Modify to populate the correct information
|
// We can use Modify to populate the correct information
|
||||||
@ -566,21 +566,21 @@ func (c *Config) AddContext(theContext *ContextOptions) *Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) ModifyContext(context *Context, theContext *ContextOptions) {
|
func (c *Config) ModifyContext(context *Context, theContext *ContextOptions) {
|
||||||
kContext := context.KubeContext()
|
kubeContext := context.KubeContext()
|
||||||
if kContext == nil {
|
if kubeContext == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if theContext.Cluster != "" {
|
if theContext.Cluster != "" {
|
||||||
kContext.Cluster = theContext.Cluster
|
kubeContext.Cluster = theContext.Cluster
|
||||||
}
|
}
|
||||||
if theContext.AuthInfo != "" {
|
if theContext.AuthInfo != "" {
|
||||||
kContext.AuthInfo = theContext.AuthInfo
|
kubeContext.AuthInfo = theContext.AuthInfo
|
||||||
}
|
}
|
||||||
if theContext.Manifest != "" {
|
if theContext.Manifest != "" {
|
||||||
context.Manifest = theContext.Manifest
|
context.Manifest = theContext.Manifest
|
||||||
}
|
}
|
||||||
if theContext.Namespace != "" {
|
if theContext.Namespace != "" {
|
||||||
kContext.Namespace = theContext.Namespace
|
kubeContext.Namespace = theContext.Namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -660,33 +660,33 @@ func (c *Config) AddAuthInfo(theAuthInfo *AuthInfoOptions) *AuthInfo {
|
|||||||
nAuthInfo := NewAuthInfo()
|
nAuthInfo := NewAuthInfo()
|
||||||
c.AuthInfos[theAuthInfo.Name] = nAuthInfo
|
c.AuthInfos[theAuthInfo.Name] = nAuthInfo
|
||||||
// Create a new Kubeconfig AuthInfo object as well
|
// Create a new Kubeconfig AuthInfo object as well
|
||||||
kAuthInfo := clientcmdapi.NewAuthInfo()
|
authInfo := clientcmdapi.NewAuthInfo()
|
||||||
nAuthInfo.SetKubeAuthInfo(kAuthInfo)
|
nAuthInfo.SetKubeAuthInfo(authInfo)
|
||||||
c.KubeConfig().AuthInfos[theAuthInfo.Name] = kAuthInfo
|
c.KubeConfig().AuthInfos[theAuthInfo.Name] = authInfo
|
||||||
|
|
||||||
c.ModifyAuthInfo(nAuthInfo, theAuthInfo)
|
c.ModifyAuthInfo(nAuthInfo, theAuthInfo)
|
||||||
return nAuthInfo
|
return nAuthInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) ModifyAuthInfo(authinfo *AuthInfo, theAuthInfo *AuthInfoOptions) {
|
func (c *Config) ModifyAuthInfo(authinfo *AuthInfo, theAuthInfo *AuthInfoOptions) {
|
||||||
kAuthInfo := authinfo.KubeAuthInfo()
|
kubeAuthInfo := authinfo.KubeAuthInfo()
|
||||||
if kAuthInfo == nil {
|
if kubeAuthInfo == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if theAuthInfo.ClientCertificate != "" {
|
if theAuthInfo.ClientCertificate != "" {
|
||||||
kAuthInfo.ClientCertificate = theAuthInfo.ClientCertificate
|
kubeAuthInfo.ClientCertificate = theAuthInfo.ClientCertificate
|
||||||
}
|
}
|
||||||
if theAuthInfo.Token != "" {
|
if theAuthInfo.Token != "" {
|
||||||
kAuthInfo.Token = theAuthInfo.Token
|
kubeAuthInfo.Token = theAuthInfo.Token
|
||||||
}
|
}
|
||||||
if theAuthInfo.Username != "" {
|
if theAuthInfo.Username != "" {
|
||||||
kAuthInfo.Username = theAuthInfo.Username
|
kubeAuthInfo.Username = theAuthInfo.Username
|
||||||
}
|
}
|
||||||
if theAuthInfo.Password != "" {
|
if theAuthInfo.Password != "" {
|
||||||
kAuthInfo.Password = theAuthInfo.Password
|
kubeAuthInfo.Password = theAuthInfo.Password
|
||||||
}
|
}
|
||||||
if theAuthInfo.ClientKey != "" {
|
if theAuthInfo.ClientKey != "" {
|
||||||
kAuthInfo.ClientKey = theAuthInfo.ClientKey
|
kubeAuthInfo.ClientKey = theAuthInfo.ClientKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,9 +242,9 @@ func TestGetId(t *testing.T) {
|
|||||||
cnt := getDockerContainerMock(mockDockerClient{})
|
cnt := getDockerContainerMock(mockDockerClient{})
|
||||||
err := cnt.RunCommand([]string{"testCmd"}, nil, nil, []string{}, false)
|
err := cnt.RunCommand([]string{"testCmd"}, nil, nil, []string{}, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
actualId := cnt.GetId()
|
actualID := cnt.GetId()
|
||||||
|
|
||||||
assert.Equal(t, "testID", actualId)
|
assert.Equal(t, "testID", actualID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunCommand(t *testing.T) {
|
func TestRunCommand(t *testing.T) {
|
||||||
|
@ -28,7 +28,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
ErrNoOpenRepo = errors.New("no open repository is stored")
|
ErrNoOpenRepo = errors.New("no open repository is stored")
|
||||||
ErrRemoteRefNotImplemented = errors.New("remoteref is not yet implemented")
|
ErrRemoteRefNotImplemented = errors.New("remoteref is not yet implemented")
|
||||||
ErrCantParseUrl = errors.New("could not get target directory from url")
|
ErrCantParseURL = errors.New("could not get target directory from url")
|
||||||
)
|
)
|
||||||
|
|
||||||
type OptionsBuilder interface {
|
type OptionsBuilder interface {
|
||||||
@ -52,7 +52,7 @@ type Repository struct {
|
|||||||
func NewRepository(basePath string, builder OptionsBuilder) (*Repository, error) {
|
func NewRepository(basePath string, builder OptionsBuilder) (*Repository, error) {
|
||||||
dirName := nameFromURL(builder.URL())
|
dirName := nameFromURL(builder.URL())
|
||||||
if dirName == "" {
|
if dirName == "" {
|
||||||
return nil, fmt.Errorf("URL: %s, original error: %w", builder.URL(), ErrCantParseUrl)
|
return nil, fmt.Errorf("URL: %s, original error: %w", builder.URL(), ErrCantParseURL)
|
||||||
}
|
}
|
||||||
fs := osfs.New(filepath.Join(basePath, dirName))
|
fs := osfs.New(filepath.Join(basePath, dirName))
|
||||||
|
|
||||||
|
@ -36,39 +36,39 @@ func (cfg RedfishRemoteDirect) DoRemoteDirect() error {
|
|||||||
/* TODO: Add Authentication when redfish library supports it. */
|
/* TODO: Add Authentication when redfish library supports it. */
|
||||||
|
|
||||||
/* Get system details */
|
/* Get system details */
|
||||||
systemId := cfg.EphemeralNodeId
|
systemID := cfg.EphemeralNodeId
|
||||||
system, _, err := cfg.Api.GetSystem(cfg.Context, systemId)
|
system, _, err := cfg.Api.GetSystem(cfg.Context, systemID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NewRedfishClientErrorf("Get System[%s] failed with err: %s", systemId, err.Error())
|
return NewRedfishClientErrorf("Get System[%s] failed with err: %s", systemID, err.Error())
|
||||||
}
|
}
|
||||||
alog.Debugf("Ephemeral Node System ID: '%s'", systemId)
|
alog.Debugf("Ephemeral Node System ID: '%s'", systemID)
|
||||||
|
|
||||||
/* get manager for system */
|
/* get manager for system */
|
||||||
managerId := GetResourceIDFromURL(system.Links.ManagedBy[0].OdataId)
|
managerID := GetResourceIDFromURL(system.Links.ManagedBy[0].OdataId)
|
||||||
alog.Debugf("Ephemeral node managerId: '%s'", managerId)
|
alog.Debugf("Ephemeral node managerID: '%s'", managerID)
|
||||||
|
|
||||||
/* Get manager's Cd or DVD virtual media ID */
|
/* Get manager's Cd or DVD virtual media ID */
|
||||||
vMediaId, vMediaType, err := GetVirtualMediaId(cfg.Context, cfg.Api, managerId)
|
vMediaID, vMediaType, err := GetVirtualMediaId(cfg.Context, cfg.Api, managerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
alog.Debugf("Ephemeral Node Virtual Media Id: '%s'", vMediaId)
|
alog.Debugf("Ephemeral Node Virtual Media Id: '%s'", vMediaID)
|
||||||
|
|
||||||
/* Load ISO in manager's virtual media */
|
/* Load ISO in manager's virtual media */
|
||||||
err = SetVirtualMedia(cfg.Context, cfg.Api, managerId, vMediaId, cfg.IsoPath)
|
err = SetVirtualMedia(cfg.Context, cfg.Api, managerID, vMediaID, cfg.IsoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
alog.Debugf("Successfully loaded virtual media: '%s'", cfg.IsoPath)
|
alog.Debugf("Successfully loaded virtual media: '%s'", cfg.IsoPath)
|
||||||
|
|
||||||
/* Set system's bootsource to selected media */
|
/* Set system's bootsource to selected media */
|
||||||
err = SetSystemBootSourceForMediaType(cfg.Context, cfg.Api, systemId, vMediaType)
|
err = SetSystemBootSourceForMediaType(cfg.Context, cfg.Api, systemID, vMediaType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reboot system */
|
/* Reboot system */
|
||||||
err = RebootSystem(cfg.Context, cfg.Api, systemId)
|
err = RebootSystem(cfg.Context, cfg.Api, systemID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ func NewRedfishRemoteDirectClient(ctx context.Context,
|
|||||||
|
|
||||||
var api redfishApi.RedfishAPI = redfishClient.NewAPIClient(cfg).DefaultApi
|
var api redfishApi.RedfishAPI = redfishClient.NewAPIClient(cfg).DefaultApi
|
||||||
|
|
||||||
parsedUrl, err := url.Parse(remoteURL)
|
parsedURL, err := url.Parse(remoteURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return RedfishRemoteDirect{},
|
return RedfishRemoteDirect{},
|
||||||
ErrRedfishMissingConfig{
|
ErrRedfishMissingConfig{
|
||||||
@ -122,7 +122,7 @@ func NewRedfishRemoteDirectClient(ctx context.Context,
|
|||||||
|
|
||||||
client := RedfishRemoteDirect{
|
client := RedfishRemoteDirect{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
RemoteURL: *parsedUrl,
|
RemoteURL: *parsedURL,
|
||||||
EphemeralNodeId: ephNodeID,
|
EphemeralNodeId: ephNodeID,
|
||||||
IsoPath: isoPath,
|
IsoPath: isoPath,
|
||||||
Api: api,
|
Api: api,
|
||||||
|
@ -26,8 +26,8 @@ func GetResourceIDFromURL(refURL string) string {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
trimmedUrl := strings.TrimSuffix(u.Path, "/")
|
trimmedURL := strings.TrimSuffix(u.Path, "/")
|
||||||
elems := strings.Split(trimmedUrl, "/")
|
elems := strings.Split(trimmedURL, "/")
|
||||||
|
|
||||||
id := elems[len(elems)-1]
|
id := elems[len(elems)-1]
|
||||||
return id
|
return id
|
||||||
@ -36,8 +36,8 @@ func GetResourceIDFromURL(refURL string) string {
|
|||||||
// Checks whether an ID exists in Redfish IDref collection
|
// Checks whether an ID exists in Redfish IDref collection
|
||||||
func IsIDInList(idRefList []redfishClient.IdRef, id string) bool {
|
func IsIDInList(idRefList []redfishClient.IdRef, id string) bool {
|
||||||
for _, r := range idRefList {
|
for _, r := range idRefList {
|
||||||
rId := GetResourceIDFromURL(r.OdataId)
|
rID := GetResourceIDFromURL(r.OdataId)
|
||||||
if rId == id {
|
if rID == id {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user