fix code scan issue

This commit is contained in:
liuwei
2020-09-10 15:01:01 +08:00
parent 27b78f7f48
commit a01b1783be
2 changed files with 6 additions and 4 deletions

View File

@@ -43,7 +43,9 @@ func newRegistrationCommand() *cobra.Command {
Use: "registration",
Short: "Spoke Cluster Registration",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
if err := cmd.Help(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
os.Exit(1)
},
}

View File

@@ -344,7 +344,7 @@ func (o *SpokeAgentOptions) hasValidHubClientConfig() (bool, error) {
}
certPath := path.Join(o.HubKubeconfigDir, hubclientcert.TLSCertFile)
certData, err := ioutil.ReadFile(certPath)
certData, err := ioutil.ReadFile(path.Clean(certPath))
if err != nil {
klog.V(4).Infof("Unable to load TLS cert file %q", certPath)
return false, nil
@@ -368,7 +368,7 @@ func (o *SpokeAgentOptions) getOrGenerateClusterAgentNames() (string, string) {
// and then load the cluster name from the mounted secret
clusterNameFilePath := path.Join(o.HubKubeconfigDir, hubclientcert.ClusterNameFile)
clusterNameBytes, err := ioutil.ReadFile(clusterNameFilePath)
clusterNameBytes, err := ioutil.ReadFile(path.Clean(clusterNameFilePath))
if err != nil {
// generate random cluster name if faild
clusterName = generateClusterName()
@@ -379,7 +379,7 @@ func (o *SpokeAgentOptions) getOrGenerateClusterAgentNames() (string, string) {
// try to load agent name from the mounted secret
agentNameFilePath := path.Join(o.HubKubeconfigDir, hubclientcert.AgentNameFile)
agentNameBytes, err := ioutil.ReadFile(agentNameFilePath)
agentNameBytes, err := ioutil.ReadFile(path.Clean(agentNameFilePath))
var agentName string
if err != nil {
// generate random agent name if faild