Skip to content

Commit

Permalink
task: don't ignore linting for the k8s package (#2690)
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn authored Mar 1, 2024
1 parent adfffff commit 505746f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 88 deletions.
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 4 additions & 5 deletions internal/kubernetes/operator/config_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down
3 changes: 1 addition & 2 deletions internal/kubernetes/operator/features/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
53 changes: 20 additions & 33 deletions internal/kubernetes/operator/install_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
82 changes: 43 additions & 39 deletions internal/kubernetes/operator/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes/operator/version/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

const (
operatorRepositoryOrg = "mongodb"
//nolint:gosec

operatorRepository = "mongodb-atlas-kubernetes"
maxMajorVersionsSupported = 3
)
Expand Down
11 changes: 8 additions & 3 deletions internal/store/project_ip_access_lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 505746f

Please sign in to comment.