Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linter fixes for go and terraform #2

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package cmd defines command line utilities for ghpc
package cmd

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package cmd defines command line utilities for ghpc
package cmd

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package cmd defines command line utilities for ghpc
package cmd

import (
Expand All @@ -37,6 +38,7 @@ HPC deployments on the Google Cloud Platform.`,
}
)

// Execute the root command
func Execute() error {
return rootCmd.Execute()
}
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package config manages and updates the ghpc input config
package config

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package config manages and updates the ghpc input config
package config

import (
Expand Down
75 changes: 38 additions & 37 deletions pkg/config/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package config manages and updates the ghpc input config
package config

import (
Expand Down Expand Up @@ -217,48 +218,48 @@ func expandSimpleVariable(
errorMessages["varNotFound"], context.varString)
}
return fmt.Sprintf("((var.%s))", varValue), nil
} else { // Resource variable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I removed the else {} block since I return from there and don't do anything after. This is more in line with expected go conventions. More info: https://github.com/golang/go/wiki/CodeReviewComments#indent-error-flow

}

// Verify resource exists
refGrpIndex, ok := resToGrp[varSource]
if !ok {
return "", fmt.Errorf("%s: resource %s was not found",
errorMessages["varNotFound"], varSource)
}
if refGrpIndex != context.groupIndex {
log.Fatalf("Unimplemented: references to other groups are not yet supported")
}
// Resource variable
// Verify resource exists
refGrpIndex, ok := resToGrp[varSource]
if !ok {
return "", fmt.Errorf("%s: resource %s was not found",
errorMessages["varNotFound"], varSource)
}
if refGrpIndex != context.groupIndex {
log.Fatalf("Unimplemented: references to other groups are not yet supported")
}

// Get the resource info
refGrp := context.yamlConfig.ResourceGroups[refGrpIndex]
refResIndex := -1
for i := range refGrp.Resources {
if refGrp.Resources[i].ID == varSource {
refResIndex = i
break
}
}
if refResIndex == -1 {
log.Fatalf("Could not find resource referenced by variable %s",
context.varString)
}
refRes := refGrp.Resources[refResIndex]
resInfo := resreader.Factory(refRes.Kind).GetInfo(refRes.Source)

// Verify output exists in resource
found := false
for _, output := range resInfo.Outputs {
if output.Name == varValue {
found = true
break
}
// Get the resource info
refGrp := context.yamlConfig.ResourceGroups[refGrpIndex]
refResIndex := -1
for i := range refGrp.Resources {
if refGrp.Resources[i].ID == varSource {
refResIndex = i
break
}
if !found {
return "", fmt.Errorf("%s: resource %s did not have output %s",
errorMessages["noOutput"], refRes.ID, varValue)
}
if refResIndex == -1 {
log.Fatalf("Could not find resource referenced by variable %s",
context.varString)
}
refRes := refGrp.Resources[refResIndex]
resInfo := resreader.Factory(refRes.Kind).GetInfo(refRes.Source)

// Verify output exists in resource
found := false
for _, output := range resInfo.Outputs {
if output.Name == varValue {
found = true
break
}
return fmt.Sprintf("((module.%s.%s))", varSource, varValue), nil
}
if !found {
return "", fmt.Errorf("%s: resource %s did not have output %s",
errorMessages["noOutput"], refRes.ID, varValue)
}
return fmt.Sprintf("((module.%s.%s))", varSource, varValue), nil
}

func expandVariable(
Expand Down
1 change: 1 addition & 0 deletions pkg/resreader/hcl_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package resreader extracts necessary information from resources
package resreader

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/resreader/metareader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Package resreader extracts necessary information from resources
package resreader

import (
Expand Down
11 changes: 6 additions & 5 deletions pkg/resreader/packerreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Package resreader extracts necessary information from resources
package resreader

import (
Expand Down Expand Up @@ -42,20 +43,20 @@ func addTfExtension(filename string) {
}

func getHCLFiles(dir string) []string {
all_files, err := ioutil.ReadDir(dir)
allFiles, err := ioutil.ReadDir(dir)
if err != nil {
log.Fatalf("Failed to read packer source directory %s", dir)
}
var hcl_files []string
for _, f := range all_files {
var hclFiles []string
for _, f := range allFiles {
if f.IsDir() {
continue
}
if filepath.Ext(f.Name()) == ".hcl" {
hcl_files = append(hcl_files, path.Join(dir, f.Name()))
hclFiles = append(hclFiles, path.Join(dir, f.Name()))
}
}
return hcl_files
return hclFiles
}

func copyHCLFilesToTmp(dir string) (string, []string) {
Expand Down
1 change: 1 addition & 0 deletions pkg/resreader/resreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Package resreader extracts necessary information from resources
package resreader

import "log"
Expand Down
10 changes: 10 additions & 0 deletions pkg/resreader/resreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package resreader extracts necessary information from resources
package resreader

import (
Expand Down Expand Up @@ -111,19 +112,28 @@ func createTmpResource() {
"Failed to create temp dir for resource in resreader_test, %v", err)
}
mainFile, err := os.Create(path.Join(tmpResourceDir, "main.tf"))
if err != nil {
log.Fatalf("Failed to create main.tf: %v", err)
}
_, err = mainFile.WriteString(testMainTf)
if err != nil {
log.Fatalf("resreader_test: Failed to write main.tf test file. %v", err)
}

varFile, err := os.Create(path.Join(tmpResourceDir, "variables.tf"))
if err != nil {
log.Fatalf("Failed to create variables.tf: %v", err)
}
_, err = varFile.WriteString(testVariablesTf)
if err != nil {
log.Fatalf(
"resreader_test: Failed to write variables.tf test file. %v", err)
}

outFile, err := os.Create(path.Join(tmpResourceDir, "outputs.tf"))
if err != nil {
log.Fatalf("Failed to create outputs.tf: %v", err)
}
_, err = outFile.WriteString(testOutputsTf)
if err != nil {
log.Fatalf("resreader_test: Failed to write outputs.tf test file. %v", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/resreader/tfreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Package resreader extracts necessary information from resources
package resreader

import "log"
Expand Down
1 change: 1 addition & 0 deletions pkg/reswriter/hcl_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package reswriter writes resources to a blueprint directory
package reswriter

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/reswriter/packerwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Package reswriter writes resources to a blueprint directory
package reswriter

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/reswriter/reswriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Package reswriter writes resources to a blueprint directory
package reswriter

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/reswriter/reswriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package reswriter writes resources to a blueprint directory
package reswriter

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/reswriter/tfwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Package reswriter writes resources to a blueprint directory
package reswriter

import (
Expand Down
12 changes: 5 additions & 7 deletions resources/scripts/omnia-install/scripts/create_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import json
import os
import subprocess
from subprocess import PIPE
from jinja2 import Template
import os
import pathlib
import argparse

## Parse Arguments
parser = argparse.ArgumentParser()
Expand All @@ -32,7 +30,8 @@
"--filter", f"labels.ghpc_deployment={args.deployment_name}",
"--format",
"json(name,labels.ghpc_role,networkInterfaces[0].networkIP)"]
gcloud_process = subprocess.run(gcloud_cmd, stdout=PIPE, stderr=PIPE)
gcloud_process = subprocess.run(
gcloud_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
if gcloud_process.returncode != 0:
print(f"Failed to return omnia VM instance list: {gcloud_process.stderr}")
exit(1)
Expand All @@ -52,5 +51,4 @@
template = Template(inventory_tmpl.read())
with open(args.outfile, "w") as inventory_file:
inventory_file.write(
template.render(omnia_manager=omnia_manager, compute_vms=compute_vms)
)
template.render(omnia_manager=omnia_manager, compute_vms=compute_vms))
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
git:
repo: 'https://github.com/dellhpc/omnia.git'
dest: ../omnia
version: release
version: release-1.0
update: false
- name: Copy file with owner and permissions
copy:
Expand Down
1 change: 1 addition & 0 deletions resources/tests/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package restests defines unit tests for terraform resources
package restests

import "testing"
Expand Down
1 change: 1 addition & 0 deletions resources/tests/file-system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package restests defines unit tests for terraform resources
package restests

import "testing"
Expand Down
1 change: 1 addition & 0 deletions resources/tests/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package restests defines unit tests for terraform resources
package restests

import "testing"
Expand Down
1 change: 1 addition & 0 deletions resources/tests/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package restests defines unit tests for terraform resources
package restests

import "testing"
Expand Down
1 change: 1 addition & 0 deletions resources/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package restests defines unit tests for terraform resources
package restests

import (
Expand Down