Skip to content

Commit

Permalink
Merge pull request #23 from nocturnalastro/fix_linting
Browse files Browse the repository at this point in the history
fix issues from golangci-lint
  • Loading branch information
openshift-merge-bot[bot] authored Jun 12, 2024
2 parents 722af08 + 30bf4ce commit 9723497
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
5 changes: 1 addition & 4 deletions addon-tools/report-creator/report/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ func TestCompareRun(t *testing.T) {
}
func updateCompareOutput(t *testing.T, test Test) {
t.Log("update test input to match current version of compare command")
cmdutil.BehaviorOnFatal(func(str string, code int) {
return
})
cmdutil.BehaviorOnFatal(func(str string, code int) {})

tf := cmdtesting.NewTestFactory()
IOStream, _, out, _ := genericiooptions.NewTestIOStreams()
Expand All @@ -113,7 +111,6 @@ func getGoldenValue(t *testing.T, fileName string, value []byte) {
t.Fatalf("test %s failed reading .golden file: %s", fileName, err)
}
require.Equal(t, string(expected), string(value))
return
}

func removeInconsistentInfo(text []byte) []byte {
Expand Down
14 changes: 7 additions & 7 deletions pkg/compare/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package compare
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
Expand Down Expand Up @@ -41,7 +42,7 @@ var (
The compare command will match each Resource in the cluster configuration to a Resource Template in the reference
configuration. Then, the templated Resource will be injected with the cluster Resource parameters.
For each cluster Resource, a diff between the Resource and its matching injected template will be presented
to the user.
to the user.
The input cluster configuration may be provided as an "offline" set of CRs or can be pulled from a live cluster.
Expand Down Expand Up @@ -95,13 +96,13 @@ const (
ReferenceFileName = "metadata.yaml"
noReffDirectoryWasPassed = "\"Reference directory is required\""
reffDirNotExistsError = "\"Reference directory doesnt exist\""
emptyTypes = "Templates don't contain any types (kind) of resources that are supported by the cluster"
emptyTypes = "templates don't contain any types (kind) of resources that are supported by the cluster"
DiffSeparator = "**********************************"
)

const (
Json string = "json"
Yaml = "yaml"
Yaml string = "yaml"
)

var OutputFormats = []string{Json, Yaml}
Expand Down Expand Up @@ -338,7 +339,7 @@ func (o *Options) setLiveSearchTypes(f kcmdutil.Factory) error {
var notSupportedTypes []string
o.types, notSupportedTypes = findAllRequestedSupportedTypes(SupportedTypes, requestedTypes[0])
if len(o.types) == 0 {
return fmt.Errorf(emptyTypes)
return errors.New(emptyTypes)
}
if len(notSupportedTypes) > 0 {
sort.Strings(notSupportedTypes)
Expand Down Expand Up @@ -372,7 +373,7 @@ func getSupportedResourceTypes(client discovery.CachedDiscoveryInterface) (map[s
func findAllRequestedSupportedTypes(supportedTypesWithGroups map[string][]string, requestedTypes map[string][]*template.Template) ([]string, []string) {
var typesIncludingGroup []string
var notSupportedTypes []string
for kind, _ := range requestedTypes {
for kind := range requestedTypes {
if _, ok := supportedTypesWithGroups[kind]; ok {
for _, group := range supportedTypesWithGroups[kind] {
typesIncludingGroup = append(typesIncludingGroup, strings.Join([]string{kind, group}, "."))
Expand Down Expand Up @@ -430,7 +431,7 @@ func (o *Options) Run() error {
return containOnly(err, []error{MultipleMatches{}, UnknownMatch{}})
})

err := r.Visit(func(info *resource.Info, err error) error {
err := r.Visit(func(info *resource.Info, _ error) error { // ignoring previous errors
clusterCRMapping, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(info.Object)
clusterCR := unstructured.Unstructured{Object: clusterCRMapping}

Expand Down Expand Up @@ -506,7 +507,6 @@ func omitFields(object map[string]any, fields [][]string) {
}
}
}
return
}

func (obj InfoObject) Name() string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/compare/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package compare

import (
"bytes"
"errors"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -461,12 +462,12 @@ func getResources(t *testing.T, resourcesDir string) ([]v1.APIResource, []*unstr
}
buf, err := os.ReadFile(path)
if err != nil {
return err
return fmt.Errorf("failed to load test file %s: %w", path, err)
}
data := make(map[string]any)
err = yaml.Unmarshal(buf, &data)
if err != nil {
return fmt.Errorf("test Input isnt yaml")
return errors.New("test Input isnt yaml")
}
r := unstructured.Unstructured{Object: data}
resources = append(resources, &r)
Expand Down
2 changes: 1 addition & 1 deletion pkg/compare/httpfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func readHttpWithRetries(get httpget, duration time.Duration, u string, attempts
if statusCode == http.StatusOK {
return body, contentLength, nil
}
err := body.Close()
err = body.Close()
if err != nil {
return nil, 0, err
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/compare/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"errors"
"fmt"
"io/fs"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"os"
"path"
"path/filepath"
"sigs.k8s.io/yaml"
"text/template"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)

type Reference struct {
Expand All @@ -30,7 +31,7 @@ type ComponentType string

const (
Required ComponentType = "Required"
Optional = "Optional"
Optional ComponentType = "Optional"
)

type Component struct {
Expand All @@ -54,7 +55,7 @@ func (r *Reference) getTemplates() []string {
func (c *Component) getMissingCRs(matchedTemplates map[string]bool) []string {
var crs []string
for _, temp := range c.RequiredTemplates {
if wasMatched, _ := matchedTemplates[temp]; !wasMatched {
if wasMatched := matchedTemplates[temp]; !wasMatched {
crs = append(crs, temp)
}
}
Expand Down Expand Up @@ -169,6 +170,9 @@ type ManualCorrelation struct {
func parseDiffConfig(filePath string) (UserConfig, error) {
result := UserConfig{}
confPath, err := filepath.Abs(filePath)
if err != nil {
return result, fmt.Errorf("failed to get absolute path for %s: %w", filePath, err)
}
err = parseYaml(os.DirFS("/"), confPath[1:], &result, userConfNotExistsError, userConfigNotInFormat)
return result, err
}
Expand Down

0 comments on commit 9723497

Please sign in to comment.