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

Increased gocognit min complex, aligned with linter #20

Merged
merged 1 commit into from
Sep 27, 2023
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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ run:
# modules-download-mode: readonly

linters-settings:
gocognit:
# Minimal code complexity to report.
min-complexity: 35
revive:
rules:
- name: indent-error-flow
Expand Down
11 changes: 6 additions & 5 deletions tests/gitopsztp/gitopsztp_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ var _ = BeforeSuite(func() {
err := gitopsztphelper.InitializeClients()
Expect(err).ToNot(HaveOccurred())

ns := namespace.NewBuilder(gitopsztphelper.HubAPIClient, gitopsztpparams.ZtpTestNamespace)
namespace := namespace.NewBuilder(gitopsztphelper.HubAPIClient, gitopsztpparams.ZtpTestNamespace)

// Delete and re-create the namespace to start with a clean state
if ns.Exists() {
err = ns.DeleteAndWait(gitopsztpparams.DefaultTimeout)
if namespace.Exists() {
err = namespace.DeleteAndWait(gitopsztpparams.DefaultTimeout)
Expect(err).ToNot(HaveOccurred())
}

_, err = ns.Create()
_, err = namespace.Create()
Expect(err).ToNot(HaveOccurred())

// create a privileged pod to run commands on nodes
Expand Down Expand Up @@ -71,7 +71,8 @@ var _ = AfterSuite(func() {

var _ = JustAfterEach(func() {
reporter.ReportIfFailed(
CurrentSpecReport(), GeneralConfig.GetDumpFailedTestReportLocation(currentFile), GeneralConfig.ReportsDirAbsPath, gitopsztphelper.ReporterNamespacesToDump,
CurrentSpecReport(), GeneralConfig.GetDumpFailedTestReportLocation(currentFile),
GeneralConfig.ReportsDirAbsPath, gitopsztphelper.ReporterNamespacesToDump,
gitopsztphelper.ReporterCRDsToDump, clients.SetScheme)
})

Expand Down
16 changes: 11 additions & 5 deletions tests/gitopsztp/internal/gitopsztphelper/gitopsztphelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import (
"github.com/openshift-kni/eco-gosystem/tests/gitopsztp/internal/gitopsztpparams"
)

// ztp related vars.
var (
cnf_test_image = "quay.io/openshift-kni/cnf-tests:4.8"
// test image.
CnfTestImage = "quay.io/openshift-kni/cnf-tests:4.8"
HubAPIClient *clients.Settings
HubName string
SpokeAPIClient *clients.Settings
Expand All @@ -51,7 +53,7 @@ var (
)

// SetGitDetailsInArgocd is used to update the git repo, branch, and path in the Argocd app.
func SetGitDetailsInArcgocd(gitRepo, gitBranch, gitPath, argocdApp string, waitForSync, syncMustBeValid bool) error {
func SetGitDetailsInArgocd(gitRepo, gitBranch, gitPath, argocdApp string, waitForSync, syncMustBeValid bool) error {
app, err := argocd.PullApplication(HubAPIClient, argocdApp, gitopsztpparams.OpenshiftGitops)
if err != nil {
return err
Expand All @@ -66,6 +68,7 @@ func SetGitDetailsInArcgocd(gitRepo, gitBranch, gitPath, argocdApp string, waitF
}

app.WithGitDetails(gitRepo, gitBranch, gitPath)

_, err = app.Update(true)
if err != nil {
return err
Expand All @@ -81,6 +84,7 @@ func SetGitDetailsInArcgocd(gitRepo, gitBranch, gitPath, argocdApp string, waitF
return nil
}

// GetOperatorVersionFromCSV returns operator version from csv.
func GetOperatorVersionFromCSV(client *clients.Settings, operatorName, operatorNamespace string) (string, error) {
// Check if the client is valid
if client == nil {
Expand Down Expand Up @@ -120,6 +124,7 @@ func DefineAPIClient(kubeconfigEnvVar string) (*clients.Settings, error) {
return clients, nil
}

// InitializeClients initializes hub & spoke clients.
func InitializeClients() error {
if os.Getenv(gitopsztpparams.HubKubeEnvKey) != "" {
var err error
Expand Down Expand Up @@ -383,6 +388,7 @@ func GetZtpVersionFromArgocd(client *clients.Settings, name string, namespace st

// The format here will be like vX.Y.Z so we need to remove the v at the start
fmt.Println("ztpVersion = ", ztpVersion)

return ztpVersion[1:], nil
}
}
Expand Down Expand Up @@ -477,7 +483,7 @@ func ResetArgocdGitDetails() error {
// Loop over the apps and restore the git details
for _, app := range gitopsztpparams.ArgocdApps {
// Restore the app's git details
err := SetGitDetailsInArcgocd(
err := SetGitDetailsInArgocd(
ArgocdApps[app].Repo,
ArgocdApps[app].Branch,
ArgocdApps[app].Path,
Expand All @@ -499,17 +505,17 @@ func ResetArgocdGitDetails() error {
// Returns a map with nodeName as key and pod pointer as value, and error if occurred.
func CreatePrivilegedPods(image string) (map[string]*pod.Builder, error) {
if image == "" {
image = cnf_test_image
image = CnfTestImage
}
// Create cnfgotestpriv namespace if not already created
namespace := namespace.NewBuilder(HubAPIClient, gitopsztpparams.PrivPodNamespace)
if !namespace.Exists() {
log.Println("Creating namespace:", gitopsztpparams.PrivPodNamespace)

_, err := namespace.Create()
if err != nil {
return nil, err
}

}
// Launch priv pods on nodes with worker role so it can be successfully scheduled.
workerNodesList, err := nodes.List(HubAPIClient, metav1.ListOptions{
Expand Down
2 changes: 2 additions & 0 deletions tests/gitopsztp/internal/gitopsztpparams/gitopsztpparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package gitopsztpparams

import "time"

// ArgocdGitDetails stores argocd git details.
type ArgocdGitDetails struct {
Repo string
Branch string
Path string
}

// ZTP and Argocd vars.
const (
// Namespaces matching '^ztp*' are special
// Argocd will only let us use such namespaces for policy gen templates on the SNO nodes.
Expand Down
1 change: 1 addition & 0 deletions tests/gitopsztp/internal/gitopsztpparams/talmparameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"
)

// talm related vars.
const (
TalmUpdatedConditionsVersion = "4.12"
OpenshiftOperatorNamespace = "openshift-operators"
Expand Down
2 changes: 1 addition & 1 deletion tests/gitopsztp/tests/gitopsztp_argocd_clusters_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("ZTP Argocd clusters Tests", Ordered, Label("ztp-argocd-cluster
})

By("Reconfigure clusters app to set the ztp directory to the ztp-tests/remove-nmstate dir", func() {
err := gitopsztphelper.SetGitDetailsInArcgocd(
err := gitopsztphelper.SetGitDetailsInArgocd(
gitopsztphelper.ArgocdApps[gitopsztpparams.ArgocdClustersAppName].Repo,
gitopsztphelper.ArgocdApps[gitopsztpparams.ArgocdClustersAppName].Branch,
testGitPath,
Expand Down
6 changes: 3 additions & 3 deletions tests/internal/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ func GetClusterVersion(apiClient *clients.Settings) (string, error) {
return "", fmt.Errorf("provided client was not defined")
}

cv, err := clusterversion.Pull(apiClient)
clusterVersion, err := clusterversion.Pull(apiClient)
if err != nil {
return "", err
}

histories := cv.Object.Status.History
histories := clusterVersion.Object.Status.History
for i := len(histories) - 1; i >= 0; i-- {
history := histories[i]
if history.State == "Completed" {
Expand All @@ -89,5 +89,5 @@ func GetClusterVersion(apiClient *clients.Settings) (string, error) {

log.Println("Warning: No completed version found in clusterversion. Returning desired version")

return cv.Object.Status.Desired.Version, nil
return clusterVersion.Object.Status.Desired.Version, nil
}