Skip to content

Commit 8440213

Browse files
fix(ci): resolve lint issues, update go.mod, and remove plan docs
- Fix gofmt, gosec, staticcheck, unconvert, and errcheck lint issues - Promote gopkg.in/yaml.v3 from indirect to direct dependency - Remove planning documents (development artifacts) Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
1 parent fb19ac0 commit 8440213

File tree

11 files changed

+74
-1407
lines changed

11 files changed

+74
-1407
lines changed

cmd/cli/common/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func GetHostURL(env *v1alpha1.Environment, nodeName string, preferControlPlane b
7575
// Holodeck instances are ephemeral with no pre-established host keys,
7676
// so host key verification is intentionally disabled.
7777
func ConnectSSH(log *logger.FunLogger, keyPath, userName, hostUrl string) (*ssh.Client, error) {
78-
key, err := os.ReadFile(keyPath)
78+
key, err := os.ReadFile(keyPath) //nolint:gosec // keyPath is from trusted env config
7979
if err != nil {
8080
return nil, fmt.Errorf("failed to read key file %s: %v", keyPath, err)
8181
}

cmd/cli/describe/describe.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ type ProviderInfo struct {
6666

6767
// ClusterInfo contains cluster configuration
6868
type ClusterInfo struct {
69-
Region string `json:"region" yaml:"region"`
70-
ControlPlane ControlPlaneInfo `json:"controlPlane" yaml:"controlPlane"`
71-
Workers *WorkersInfo `json:"workers,omitempty" yaml:"workers,omitempty"`
72-
HighAvailability *HAInfo `json:"highAvailability,omitempty" yaml:"highAvailability,omitempty"`
73-
Phase string `json:"phase,omitempty" yaml:"phase,omitempty"`
74-
TotalNodes int32 `json:"totalNodes,omitempty" yaml:"totalNodes,omitempty"`
75-
ReadyNodes int32 `json:"readyNodes,omitempty" yaml:"readyNodes,omitempty"`
76-
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
77-
LoadBalancerDNS string `json:"loadBalancerDNS,omitempty" yaml:"loadBalancerDNS,omitempty"`
78-
Nodes []NodeInfo `json:"nodes,omitempty" yaml:"nodes,omitempty"`
69+
Region string `json:"region" yaml:"region"`
70+
ControlPlane ControlPlaneInfo `json:"controlPlane" yaml:"controlPlane"`
71+
Workers *WorkersInfo `json:"workers,omitempty" yaml:"workers,omitempty"`
72+
HighAvailability *HAInfo `json:"highAvailability,omitempty" yaml:"highAvailability,omitempty"`
73+
Phase string `json:"phase,omitempty" yaml:"phase,omitempty"`
74+
TotalNodes int32 `json:"totalNodes,omitempty" yaml:"totalNodes,omitempty"`
75+
ReadyNodes int32 `json:"readyNodes,omitempty" yaml:"readyNodes,omitempty"`
76+
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
77+
LoadBalancerDNS string `json:"loadBalancerDNS,omitempty" yaml:"loadBalancerDNS,omitempty"`
78+
Nodes []NodeInfo `json:"nodes,omitempty" yaml:"nodes,omitempty"`
7979
}
8080

8181
// ControlPlaneInfo contains control plane configuration
@@ -288,7 +288,7 @@ func (m command) buildDescribeOutput(instance *instances.Instance, env *v1alpha1
288288
if env.Spec.Cluster != nil {
289289
output.Provider.Region = env.Spec.Cluster.Region
290290
} else {
291-
output.Provider.Region = env.Spec.Instance.Region
291+
output.Provider.Region = env.Spec.Region
292292
}
293293

294294
// Cluster info
@@ -318,7 +318,7 @@ func (m command) buildDescribeOutput(instance *instances.Instance, env *v1alpha1
318318
}
319319

320320
if env.Status.Cluster != nil {
321-
output.Cluster.Phase = string(env.Status.Cluster.Phase)
321+
output.Cluster.Phase = env.Status.Cluster.Phase
322322
output.Cluster.TotalNodes = env.Status.Cluster.TotalNodes
323323
output.Cluster.ReadyNodes = env.Status.Cluster.ReadyNodes
324324
output.Cluster.Endpoint = env.Status.Cluster.ControlPlaneEndpoint
@@ -331,7 +331,7 @@ func (m command) buildDescribeOutput(instance *instances.Instance, env *v1alpha1
331331
InstanceID: node.InstanceID,
332332
PublicIP: node.PublicIP,
333333
PrivateIP: node.PrivateIP,
334-
Phase: string(node.Phase),
334+
Phase: node.Phase,
335335
})
336336
}
337337
}
@@ -396,10 +396,10 @@ func (m command) buildDescribeOutput(instance *instances.Instance, env *v1alpha1
396396
// AWS Resources (for single-node AWS)
397397
if env.Spec.Provider == v1alpha1.ProviderAWS && env.Spec.Cluster == nil {
398398
awsRes := &AWSResourcesInfo{
399-
InstanceType: env.Spec.Instance.Type,
399+
InstanceType: env.Spec.Type,
400400
}
401-
if env.Spec.Instance.Image.ImageId != nil {
402-
awsRes.AMI = *env.Spec.Instance.Image.ImageId
401+
if env.Spec.Image.ImageId != nil {
402+
awsRes.AMI = *env.Spec.Image.ImageId
403403
}
404404
for _, p := range env.Status.Properties {
405405
switch p.Name {
@@ -425,6 +425,7 @@ func (m command) buildDescribeOutput(instance *instances.Instance, env *v1alpha1
425425
return output
426426
}
427427

428+
//nolint:errcheck // stdout writes
428429
func (m command) printTableFormat(d *DescribeOutput) error {
429430
// Instance Information
430431
fmt.Println("=== Instance Information ===")
@@ -515,7 +516,7 @@ func (m command) printTableFormat(d *DescribeOutput) error {
515516
if d.Components.ContainerToolkit != nil {
516517
version := d.Components.ContainerToolkit.Version
517518
if version == "" {
518-
version = string(d.Components.ContainerToolkit.Source)
519+
version = d.Components.ContainerToolkit.Source
519520
}
520521
if version == "" {
521522
version = "latest"

cmd/cli/get/get.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (m command) runKubeconfig(instanceID string) error {
174174
return fmt.Errorf("failed to get home directory: %v", err)
175175
}
176176
kubeDir := filepath.Join(homeDir, ".kube")
177-
if err := os.MkdirAll(kubeDir, 0755); err != nil {
177+
if err := os.MkdirAll(kubeDir, 0750); err != nil {
178178
return fmt.Errorf("failed to create .kube directory: %v", err)
179179
}
180180
outputPath = filepath.Join(kubeDir, fmt.Sprintf("config-%s", instanceID))
@@ -191,6 +191,7 @@ func (m command) runKubeconfig(instanceID string) error {
191191
return nil
192192
}
193193

194+
//nolint:errcheck // stdout writes for SSH config output
194195
func (m command) runSSHConfig(instanceID string) error {
195196
// Get instance details
196197
manager := instances.NewManager(m.log, m.cachePath)
@@ -234,6 +235,7 @@ func (m command) runSSHConfig(instanceID string) error {
234235
return nil
235236
}
236237

238+
//nolint:errcheck // stdout writes for SSH config output
237239
func (m command) generateClusterSSHConfig(instanceID string, env *v1alpha1.Environment, userName, keyPath string) error {
238240
fmt.Printf("# Holodeck cluster: %s\n", instanceID)
239241

@@ -254,4 +256,3 @@ func (m command) generateClusterSSHConfig(instanceID string, env *v1alpha1.Envir
254256

255257
return nil
256258
}
257-

cmd/cli/scp/scp.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ func (m command) run(src, dst string) error {
177177
if err != nil {
178178
return fmt.Errorf("failed to connect: %v", err)
179179
}
180-
defer sshClient.Close()
180+
defer sshClient.Close() //nolint:errcheck
181181

182182
sftpClient, err := sftp.NewClient(sshClient)
183183
if err != nil {
184184
return fmt.Errorf("failed to create SFTP client: %v", err)
185185
}
186-
defer sftpClient.Close()
186+
defer sftpClient.Close() //nolint:errcheck
187187

188188
// Perform the copy
189189
if srcSpec.isRemote {
@@ -210,24 +210,22 @@ func (m command) copyToRemote(client *sftp.Client, localPath, remotePath string)
210210

211211
func (m command) copyFileToRemote(client *sftp.Client, localPath, remotePath string) error {
212212
// Open local file
213-
localFile, err := os.Open(localPath)
213+
localFile, err := os.Open(localPath) //nolint:gosec // localPath is user-provided CLI arg
214214
if err != nil {
215215
return fmt.Errorf("failed to open local file: %v", err)
216216
}
217-
defer localFile.Close()
217+
defer localFile.Close() //nolint:errcheck
218218

219219
// Ensure remote directory exists (use path, not filepath, for POSIX remote paths)
220220
remoteDir := path.Dir(remotePath)
221-
if err := client.MkdirAll(remoteDir); err != nil {
222-
// Ignore error, directory might already exist
223-
}
221+
_ = client.MkdirAll(remoteDir) // best-effort, directory may already exist
224222

225223
// Create remote file
226224
remoteFile, err := client.Create(remotePath)
227225
if err != nil {
228226
return fmt.Errorf("failed to create remote file: %v", err)
229227
}
230-
defer remoteFile.Close()
228+
defer remoteFile.Close() //nolint:errcheck
231229

232230
// Copy content
233231
bytes, err := io.Copy(remoteFile, localFile)
@@ -283,20 +281,20 @@ func (m command) copyFileFromRemote(client *sftp.Client, remotePath, localPath s
283281
if err != nil {
284282
return fmt.Errorf("failed to open remote file: %v", err)
285283
}
286-
defer remoteFile.Close()
284+
defer remoteFile.Close() //nolint:errcheck
287285

288286
// Ensure local directory exists
289287
localDir := filepath.Dir(localPath)
290-
if err := os.MkdirAll(localDir, 0755); err != nil {
288+
if err := os.MkdirAll(localDir, 0750); err != nil {
291289
return fmt.Errorf("failed to create local directory: %v", err)
292290
}
293291

294292
// Create local file
295-
localFile, err := os.Create(localPath)
293+
localFile, err := os.Create(localPath) //nolint:gosec // localPath is user-provided CLI arg
296294
if err != nil {
297295
return fmt.Errorf("failed to create local file: %v", err)
298296
}
299-
defer localFile.Close()
297+
defer localFile.Close() //nolint:errcheck
300298

301299
// Copy content
302300
bytes, err := io.Copy(localFile, remoteFile)
@@ -324,7 +322,7 @@ func (m command) copyDirFromRemote(client *sftp.Client, remotePath, localPath st
324322
localTarget := filepath.Join(localPath, relPath)
325323

326324
if walker.Stat().IsDir() {
327-
if err := os.MkdirAll(localTarget, 0755); err != nil {
325+
if err := os.MkdirAll(localTarget, 0750); err != nil {
328326
return err
329327
}
330328
continue

cmd/cli/ssh/ssh.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ import (
2222
"os/exec"
2323
"strings"
2424

25+
cli "github.com/urfave/cli/v2"
2526
"golang.org/x/crypto/ssh"
2627

28+
"github.com/NVIDIA/holodeck/api/holodeck/v1alpha1"
2729
"github.com/NVIDIA/holodeck/cmd/cli/common"
2830
"github.com/NVIDIA/holodeck/internal/instances"
2931
"github.com/NVIDIA/holodeck/internal/logger"
3032
"github.com/NVIDIA/holodeck/pkg/jyaml"
31-
32-
"github.com/NVIDIA/holodeck/api/holodeck/v1alpha1"
33-
cli "github.com/urfave/cli/v2"
3433
)
3534

3635
type command struct {
@@ -141,7 +140,7 @@ func (m command) run(instanceID string, remoteCmd []string) error {
141140
if err != nil {
142141
return fmt.Errorf("failed to connect: %v", err)
143142
}
144-
defer client.Close()
143+
defer client.Close() //nolint:errcheck
145144

146145
return m.runCommand(client, remoteCmd)
147146
}
@@ -151,7 +150,7 @@ func (m command) runCommand(client *ssh.Client, cmd []string) error {
151150
if err != nil {
152151
return fmt.Errorf("failed to create session: %v", err)
153152
}
154-
defer session.Close()
153+
defer session.Close() //nolint:errcheck
155154

156155
// Connect stdout and stderr
157156
session.Stdout = os.Stdout
@@ -176,7 +175,7 @@ func (m command) runInteractiveSystemSSH(keyPath, userName, hostUrl string) erro
176175
fmt.Sprintf("%s@%s", userName, hostUrl),
177176
}
178177

179-
cmd := exec.Command("ssh", args...)
178+
cmd := exec.Command("ssh", args...) //nolint:gosec // args are constructed from trusted env config
180179
cmd.Stdin = os.Stdin
181180
cmd.Stdout = os.Stdout
182181
cmd.Stderr = os.Stderr

cmd/cli/status/status.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,31 @@ type command struct {
4040

4141
// StatusOutput represents the instance status for JSON/YAML output
4242
type StatusOutput struct {
43-
InstanceID string `json:"instanceId" yaml:"instanceId"`
44-
Name string `json:"name" yaml:"name"`
45-
Provider string `json:"provider" yaml:"provider"`
46-
Status string `json:"status" yaml:"status"`
47-
CreatedAt time.Time `json:"createdAt" yaml:"createdAt"`
48-
Age string `json:"age" yaml:"age"`
49-
CacheFile string `json:"cacheFile" yaml:"cacheFile"`
50-
Cluster *ClusterStatusOutput `json:"cluster,omitempty" yaml:"cluster,omitempty"`
51-
LiveHealth *LiveHealthOutput `json:"liveHealth,omitempty" yaml:"liveHealth,omitempty"`
43+
InstanceID string `json:"instanceId" yaml:"instanceId"`
44+
Name string `json:"name" yaml:"name"`
45+
Provider string `json:"provider" yaml:"provider"`
46+
Status string `json:"status" yaml:"status"`
47+
CreatedAt time.Time `json:"createdAt" yaml:"createdAt"`
48+
Age string `json:"age" yaml:"age"`
49+
CacheFile string `json:"cacheFile" yaml:"cacheFile"`
50+
Cluster *ClusterStatusOutput `json:"cluster,omitempty" yaml:"cluster,omitempty"`
51+
LiveHealth *LiveHealthOutput `json:"liveHealth,omitempty" yaml:"liveHealth,omitempty"`
5252
}
5353

5454
// ClusterStatusOutput represents cluster configuration and status
5555
type ClusterStatusOutput struct {
56-
Region string `json:"region" yaml:"region"`
57-
ControlPlaneCount int32 `json:"controlPlaneCount" yaml:"controlPlaneCount"`
58-
ControlPlaneType string `json:"controlPlaneType" yaml:"controlPlaneType"`
59-
ControlPlaneMode string `json:"controlPlaneMode" yaml:"controlPlaneMode"`
60-
WorkerCount int32 `json:"workerCount,omitempty" yaml:"workerCount,omitempty"`
61-
WorkerType string `json:"workerType,omitempty" yaml:"workerType,omitempty"`
62-
HighAvailability *HAOutput `json:"highAvailability,omitempty" yaml:"highAvailability,omitempty"`
63-
Phase string `json:"phase,omitempty" yaml:"phase,omitempty"`
64-
TotalNodes int32 `json:"totalNodes,omitempty" yaml:"totalNodes,omitempty"`
65-
ReadyNodes int32 `json:"readyNodes,omitempty" yaml:"readyNodes,omitempty"`
66-
ControlPlaneEndpoint string `json:"controlPlaneEndpoint,omitempty" yaml:"controlPlaneEndpoint,omitempty"`
67-
LoadBalancerDNS string `json:"loadBalancerDNS,omitempty" yaml:"loadBalancerDNS,omitempty"`
56+
Region string `json:"region" yaml:"region"`
57+
ControlPlaneCount int32 `json:"controlPlaneCount" yaml:"controlPlaneCount"`
58+
ControlPlaneType string `json:"controlPlaneType" yaml:"controlPlaneType"`
59+
ControlPlaneMode string `json:"controlPlaneMode" yaml:"controlPlaneMode"`
60+
WorkerCount int32 `json:"workerCount,omitempty" yaml:"workerCount,omitempty"`
61+
WorkerType string `json:"workerType,omitempty" yaml:"workerType,omitempty"`
62+
HighAvailability *HAOutput `json:"highAvailability,omitempty" yaml:"highAvailability,omitempty"`
63+
Phase string `json:"phase,omitempty" yaml:"phase,omitempty"`
64+
TotalNodes int32 `json:"totalNodes,omitempty" yaml:"totalNodes,omitempty"`
65+
ReadyNodes int32 `json:"readyNodes,omitempty" yaml:"readyNodes,omitempty"`
66+
ControlPlaneEndpoint string `json:"controlPlaneEndpoint,omitempty" yaml:"controlPlaneEndpoint,omitempty"`
67+
LoadBalancerDNS string `json:"loadBalancerDNS,omitempty" yaml:"loadBalancerDNS,omitempty"`
6868
Nodes []NodeStatusOutput `json:"nodes,omitempty" yaml:"nodes,omitempty"`
6969
}
7070

@@ -207,7 +207,7 @@ func (m command) run(c *cli.Context, instanceID string) error {
207207

208208
// Add cluster status from cache
209209
if env.Status.Cluster != nil {
210-
statusOutput.Cluster.Phase = string(env.Status.Cluster.Phase)
210+
statusOutput.Cluster.Phase = env.Status.Cluster.Phase
211211
statusOutput.Cluster.TotalNodes = env.Status.Cluster.TotalNodes
212212
statusOutput.Cluster.ReadyNodes = env.Status.Cluster.ReadyNodes
213213
statusOutput.Cluster.ControlPlaneEndpoint = env.Status.Cluster.ControlPlaneEndpoint
@@ -222,7 +222,7 @@ func (m command) run(c *cli.Context, instanceID string) error {
222222
InstanceID: node.InstanceID,
223223
PublicIP: node.PublicIP,
224224
PrivateIP: node.PrivateIP,
225-
Phase: string(node.Phase),
225+
Phase: node.Phase,
226226
})
227227
}
228228
}
@@ -273,6 +273,8 @@ func (m command) run(c *cli.Context, instanceID string) error {
273273
}
274274

275275
// printTableFormat outputs status in the original human-readable format
276+
//
277+
//nolint:errcheck // stdout writes
276278
func (m command) printTableFormat(s *StatusOutput) error {
277279
fmt.Printf("Instance ID: %s\n", s.InstanceID)
278280
fmt.Printf("Name: %s\n", s.Name)

cmd/cli/update/update.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ type command struct {
4040
driverVersion string
4141
driverBranch string
4242

43-
addRuntime bool
44-
runtimeName string
45-
runtimeVer string
43+
addRuntime bool
44+
runtimeName string
45+
runtimeVer string
4646

47-
addToolkit bool
48-
toolkitVer string
49-
enableCDI bool
47+
addToolkit bool
48+
toolkitVer string
49+
enableCDI bool
5050

5151
addKubernetes bool
5252
k8sInstaller string
@@ -376,7 +376,7 @@ func (m *command) runProvision(env *v1alpha1.Environment) error {
376376
if err != nil {
377377
return fmt.Errorf("failed to create provisioner: %v", err)
378378
}
379-
defer p.Client.Close()
379+
defer p.Client.Close() //nolint:errcheck
380380

381381
return p.Run(*env)
382382
}

0 commit comments

Comments
 (0)