From 3e9deb761b1fd87f0ca7e8e4e8e199136cbcbb24 Mon Sep 17 00:00:00 2001
From: Gustavo Bazan <gus.bazan@hey.com>
Date: Fri, 1 Mar 2024 11:57:03 +0000
Subject: [PATCH] task: don't ignore linting for the k8s package

---
 .golangci.yml                                 |  5 --
 .../kubernetes/operator/config_exporter.go    |  9 +-
 internal/kubernetes/operator/features/crds.go |  3 +-
 .../kubernetes/operator/install_resources.go  | 53 +++++-------
 .../kubernetes/operator/project/project.go    | 82 ++++++++++---------
 .../kubernetes/operator/version/provider.go   |  2 +-
 internal/store/project_ip_access_lists.go     | 11 ++-
 7 files changed, 77 insertions(+), 88 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
index 78a67d9ce7..9bcf7ed535 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -187,8 +187,3 @@ issues:
     - path: internal/test/fixture # Don't check for magic numbers on fixtures.
       linters:
         - gomnd
-    - path: internal/kubernetes/*
-      linters:
-        - nolintlint
-        - gci
-        - gocyclo
diff --git a/internal/kubernetes/operator/config_exporter.go b/internal/kubernetes/operator/config_exporter.go
index 4043d0214e..877a8c2f7b 100644
--- a/internal/kubernetes/operator/config_exporter.go
+++ b/internal/kubernetes/operator/config_exporter.go
@@ -20,11 +20,6 @@ import (
 	"fmt"
 	"reflect"
 
-	atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
-	"k8s.io/apimachinery/pkg/runtime"
-	"k8s.io/apimachinery/pkg/runtime/serializer/json"
-	"k8s.io/client-go/kubernetes/scheme"
-
 	"github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/datafederation"
 	"github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/dbusers"
 	"github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/deployment"
@@ -33,6 +28,10 @@ import (
 	"github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/resources"
 	"github.com/mongodb/mongodb-atlas-cli/internal/store"
 	"github.com/mongodb/mongodb-atlas-cli/internal/store/atlas"
+	atlasv2 "go.mongodb.org/atlas-sdk/v20231115007/admin"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/runtime/serializer/json"
+	"k8s.io/client-go/kubernetes/scheme"
 )
 
 const (
diff --git a/internal/kubernetes/operator/features/crds.go b/internal/kubernetes/operator/features/crds.go
index 4b7b337aea..98a407291e 100644
--- a/internal/kubernetes/operator/features/crds.go
+++ b/internal/kubernetes/operator/features/crds.go
@@ -20,11 +20,10 @@ import (
 	"strings"
 
 	"github.com/Masterminds/semver/v3"
+	"github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/crds"
 	apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
 	"k8s.io/apimachinery/pkg/api/meta"
 	"k8s.io/apimachinery/pkg/runtime"
-
-	"github.com/mongodb/mongodb-atlas-cli/internal/kubernetes/operator/crds"
 )
 
 const (
diff --git a/internal/kubernetes/operator/install_resources.go b/internal/kubernetes/operator/install_resources.go
index 00fd8561f5..7c82aa754d 100644
--- a/internal/kubernetes/operator/install_resources.go
+++ b/internal/kubernetes/operator/install_resources.go
@@ -122,45 +122,32 @@ func (ir *InstallResources) InstallConfiguration(ctx context.Context, installCon
 	}
 
 	for _, config := range configData {
-		switch config["kind"] {
-		case "ServiceAccount":
-			err = ir.addServiceAccount(ctx, config, installConfig.Namespace)
-			if err != nil {
-				return err
-			}
-		case "Role":
-			err = ir.addRoles(ctx, config, installConfig.Namespace, installConfig.Watch)
-			if err != nil {
-				return err
-			}
-		case "ClusterRole":
-			err = ir.addClusterRole(ctx, config, installConfig.Namespace)
-			if err != nil {
-				return err
-			}
-		case "RoleBinding":
-			err = ir.addRoleBindings(ctx, config, installConfig.Namespace, installConfig.Watch)
-			if err != nil {
-				return err
-			}
-		case "ClusterRoleBinding":
-			err = ir.addClusterRoleBinding(ctx, config, installConfig.Namespace)
-			if err != nil {
-				return err
-			}
-		case "Deployment":
-			err = ir.addDeployment(ctx, config, installConfig)
-			if err != nil {
-				return err
-			}
-		default:
-			continue
+		if err2 := ir.handleKind(ctx, installConfig, config); err2 != nil {
+			return err2
 		}
 	}
 
 	return nil
 }
 
+func (ir *InstallResources) handleKind(ctx context.Context, installConfig *InstallConfig, config map[string]interface{}) error {
+	switch config["kind"] {
+	case "ServiceAccount":
+		return ir.addServiceAccount(ctx, config, installConfig.Namespace)
+	case "Role":
+		return ir.addRoles(ctx, config, installConfig.Namespace, installConfig.Watch)
+	case "ClusterRole":
+		return ir.addClusterRole(ctx, config, installConfig.Namespace)
+	case "RoleBinding":
+		return ir.addRoleBindings(ctx, config, installConfig.Namespace, installConfig.Watch)
+	case "ClusterRoleBinding":
+		return ir.addClusterRoleBinding(ctx, config, installConfig.Namespace)
+	case "Deployment":
+		return ir.addDeployment(ctx, config, installConfig)
+	}
+	return nil
+}
+
 func (ir *InstallResources) InstallCredentials(ctx context.Context, namespace, orgID, publicKey, privateKey string, projectName string) error {
 	name := credentialsGlobalName
 
diff --git a/internal/kubernetes/operator/project/project.go b/internal/kubernetes/operator/project/project.go
index c520328b7b..b3b8430d90 100644
--- a/internal/kubernetes/operator/project/project.go
+++ b/internal/kubernetes/operator/project/project.go
@@ -73,7 +73,7 @@ type AtlasProjectResult struct {
 	Teams   []*akov2.AtlasTeam
 }
 
-func BuildAtlasProject(projectStore atlas.OperatorProjectStore, validator features.FeatureValidator, orgID, projectID, targetNamespace string, includeSecret bool, dictionary map[string]string, version string) (*AtlasProjectResult, error) {
+func BuildAtlasProject(projectStore atlas.OperatorProjectStore, validator features.FeatureValidator, orgID, projectID, targetNamespace string, includeSecret bool, dictionary map[string]string, version string) (*AtlasProjectResult, error) { //nolint:gocyclo
 	data, err := projectStore.Project(projectID)
 	if err != nil {
 		return nil, err
@@ -84,43 +84,7 @@ func BuildAtlasProject(projectStore atlas.OperatorProjectStore, validator featur
 		return nil, ErrAtlasProject
 	}
 
-	projectResult := &akov2.AtlasProject{
-		TypeMeta: v1.TypeMeta{
-			Kind:       "AtlasProject",
-			APIVersion: "atlas.mongodb.com/v1",
-		},
-		ObjectMeta: v1.ObjectMeta{
-			Name:      resources.NormalizeAtlasName(project.Name, dictionary),
-			Namespace: targetNamespace,
-			Labels: map[string]string{
-				features.ResourceVersion: version,
-			},
-		},
-		Spec: akov2.AtlasProjectSpec{
-			Name:                          project.Name,
-			ConnectionSecret:              nil,
-			ProjectIPAccessList:           nil,
-			PrivateEndpoints:              nil,
-			CloudProviderAccessRoles:      nil,
-			AlertConfigurations:           nil,
-			AlertConfigurationSyncEnabled: false,
-			NetworkPeers:                  nil,
-			WithDefaultAlertsSettings:     pointer.GetOrDefault(project.WithDefaultAlertsSettings, false),
-			X509CertRef:                   nil, // not available for import
-			Integrations:                  nil,
-			EncryptionAtRest:              nil,
-			Auditing:                      nil,
-			Settings:                      nil,
-			CustomRoles:                   nil,
-			Teams:                         nil,
-			RegionUsageRestrictions:       atlas.StringOrEmpty(project.RegionUsageRestrictions),
-		},
-		Status: akov2status.AtlasProjectStatus{
-			Common: akov2status.Common{
-				Conditions: []akov2status.Condition{},
-			},
-		},
-	}
+	projectResult := newAtlasProject(project, dictionary, targetNamespace, version)
 
 	result := &AtlasProjectResult{
 		Project: projectResult,
@@ -237,6 +201,46 @@ func BuildAtlasProject(projectStore atlas.OperatorProjectStore, validator featur
 	return result, err
 }
 
+func newAtlasProject(project *atlasv2.Group, dictionary map[string]string, targetNamespace string, version string) *akov2.AtlasProject {
+	return &akov2.AtlasProject{
+		TypeMeta: v1.TypeMeta{
+			Kind:       "AtlasProject",
+			APIVersion: "atlas.mongodb.com/v1",
+		},
+		ObjectMeta: v1.ObjectMeta{
+			Name:      resources.NormalizeAtlasName(project.Name, dictionary),
+			Namespace: targetNamespace,
+			Labels: map[string]string{
+				features.ResourceVersion: version,
+			},
+		},
+		Spec: akov2.AtlasProjectSpec{
+			Name:                          project.Name,
+			ConnectionSecret:              nil,
+			ProjectIPAccessList:           nil,
+			PrivateEndpoints:              nil,
+			CloudProviderAccessRoles:      nil,
+			AlertConfigurations:           nil,
+			AlertConfigurationSyncEnabled: false,
+			NetworkPeers:                  nil,
+			WithDefaultAlertsSettings:     pointer.GetOrDefault(project.WithDefaultAlertsSettings, false),
+			X509CertRef:                   nil, // not available for import
+			Integrations:                  nil,
+			EncryptionAtRest:              nil,
+			Auditing:                      nil,
+			Settings:                      nil,
+			CustomRoles:                   nil,
+			Teams:                         nil,
+			RegionUsageRestrictions:       atlas.StringOrEmpty(project.RegionUsageRestrictions),
+		},
+		Status: akov2status.AtlasProjectStatus{
+			Common: akov2status.Common{
+				Conditions: []akov2status.Condition{},
+			},
+		},
+	}
+}
+
 func BuildProjectConnectionSecret(credsProvider store.CredentialsGetter, name, namespace, orgID string, includeCreds bool, dictionary map[string]string) *corev1.Secret {
 	secret := secrets.NewAtlasSecretBuilder(fmt.Sprintf("%s-credentials", name), namespace, dictionary).
 		WithData(map[string][]byte{
@@ -343,7 +347,7 @@ func buildMaintenanceWindows(mwProvider store.MaintenanceWindowDescriber, projec
 	}, nil
 }
 
-func buildIntegrations(intProvider store.IntegrationLister, projectID, targetNamespace string, includeSecrets bool, dictionary map[string]string) ([]akov2project.Integration, []*corev1.Secret, error) {
+func buildIntegrations(intProvider store.IntegrationLister, projectID, targetNamespace string, includeSecrets bool, dictionary map[string]string) ([]akov2project.Integration, []*corev1.Secret, error) { //nolint:gocyclo
 	integrations, err := intProvider.Integrations(projectID)
 	if err != nil {
 		return nil, nil, err
diff --git a/internal/kubernetes/operator/version/provider.go b/internal/kubernetes/operator/version/provider.go
index 785519b739..244d2c6037 100644
--- a/internal/kubernetes/operator/version/provider.go
+++ b/internal/kubernetes/operator/version/provider.go
@@ -26,7 +26,7 @@ import (
 
 const (
 	operatorRepositoryOrg = "mongodb"
-	//nolint:gosec
+
 	operatorRepository        = "mongodb-atlas-kubernetes"
 	maxMajorVersionsSupported = 3
 )
diff --git a/internal/store/project_ip_access_lists.go b/internal/store/project_ip_access_lists.go
index d254a31e9a..82d9dcb53b 100644
--- a/internal/store/project_ip_access_lists.go
+++ b/internal/store/project_ip_access_lists.go
@@ -74,11 +74,16 @@ func (s *Store) DeleteProjectIPAccessList(projectID, entry string) error {
 func (s *Store) ProjectIPAccessLists(projectID string, opts *atlas.ListOptions) (*atlasv2.PaginatedNetworkAccess, error) {
 	switch s.service {
 	case config.CloudService, config.CloudGovService:
-		res := s.clientv2.ProjectIPAccessListApi.ListProjectIpAccessLists(s.ctx, projectID)
+		params := &atlasv2.ListProjectIpAccessListsApiParams{
+			GroupId: projectID,
+		}
 		if opts != nil {
-			res = res.PageNum(opts.PageNum).ItemsPerPage(opts.ItemsPerPage)
+			params.PageNum = &opts.PageNum
+			params.ItemsPerPage = &opts.ItemsPerPage
 		}
-		result, _, err := res.Execute()
+		result, _, err := s.clientv2.ProjectIPAccessListApi.
+			ListProjectIpAccessListsWithParams(s.ctx, params).
+			Execute()
 		return result, err
 	default:
 		return nil, fmt.Errorf("%w: %s", errUnsupportedService, s.service)