diff --git a/.golangci.yml b/.golangci.yml index 5617153c..8540e377 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 diff --git a/tests/gitopsztp/gitopsztp_suite_test.go b/tests/gitopsztp/gitopsztp_suite_test.go index ffa4870a..c285ff02 100644 --- a/tests/gitopsztp/gitopsztp_suite_test.go +++ b/tests/gitopsztp/gitopsztp_suite_test.go @@ -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 @@ -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) }) diff --git a/tests/gitopsztp/internal/gitopsztphelper/gitopsztphelper.go b/tests/gitopsztp/internal/gitopsztphelper/gitopsztphelper.go index 690a0cfa..c2aa1df7 100644 --- a/tests/gitopsztp/internal/gitopsztphelper/gitopsztphelper.go +++ b/tests/gitopsztp/internal/gitopsztphelper/gitopsztphelper.go @@ -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 @@ -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 @@ -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 @@ -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 { @@ -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 @@ -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 } } @@ -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, @@ -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{ diff --git a/tests/gitopsztp/internal/gitopsztpparams/gitopsztpparams.go b/tests/gitopsztp/internal/gitopsztpparams/gitopsztpparams.go index fbf64e46..214448a2 100644 --- a/tests/gitopsztp/internal/gitopsztpparams/gitopsztpparams.go +++ b/tests/gitopsztp/internal/gitopsztpparams/gitopsztpparams.go @@ -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. diff --git a/tests/gitopsztp/internal/gitopsztpparams/talmparameters.go b/tests/gitopsztp/internal/gitopsztpparams/talmparameters.go index c8cf1f2b..e7019f33 100644 --- a/tests/gitopsztp/internal/gitopsztpparams/talmparameters.go +++ b/tests/gitopsztp/internal/gitopsztpparams/talmparameters.go @@ -4,6 +4,7 @@ import ( "time" ) +// talm related vars. const ( TalmUpdatedConditionsVersion = "4.12" OpenshiftOperatorNamespace = "openshift-operators" diff --git a/tests/gitopsztp/tests/gitopsztp_argocd_clusters_app.go b/tests/gitopsztp/tests/gitopsztp_argocd_clusters_app.go index faf92706..8bcfb63d 100644 --- a/tests/gitopsztp/tests/gitopsztp_argocd_clusters_app.go +++ b/tests/gitopsztp/tests/gitopsztp_argocd_clusters_app.go @@ -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, diff --git a/tests/internal/cluster/cluster.go b/tests/internal/cluster/cluster.go index 3e869133..22f72c11 100644 --- a/tests/internal/cluster/cluster.go +++ b/tests/internal/cluster/cluster.go @@ -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" { @@ -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 }