From c3d7d65aa166d9f38c290d53ae67afa8a4681bd2 Mon Sep 17 00:00:00 2001 From: Gustavo Bazan Date: Mon, 8 Apr 2024 14:04:19 +0100 Subject: [PATCH] task: validate import alias via importas (#2804) --- .golangci.yml | 49 ++++++++-- internal/kubernetes/operator/crds/provider.go | 8 +- .../operator/datafederation/datafederation.go | 28 +++--- .../datafederation/datafederation_test.go | 28 +++--- .../kubernetes/operator/dbusers/dbusers.go | 6 +- .../operator/dbusers/dbusers_test.go | 10 +- .../operator/deployment/deployment.go | 18 ++-- .../operator/deployment/deployment_test.go | 20 ++-- internal/kubernetes/operator/features/crds.go | 14 +-- .../kubernetes/operator/features/crds_test.go | 96 +++++++++---------- .../kubernetes/operator/features/patcher.go | 12 +-- .../operator/features/patcher_test.go | 16 ++-- .../kubernetes/operator/install_resources.go | 4 +- .../kubernetes/operator/project/project.go | 10 +- .../operator/project/project_test.go | 26 ++--- .../kubernetes/operator/secrets/secrets.go | 6 +- .../e2e/atlas/kubernetes_config_apply_test.go | 8 +- .../atlas/kubernetes_config_generate_test.go | 30 +++--- .../atlas/kubernetes_operator_install_test.go | 4 +- 19 files changed, 212 insertions(+), 181 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9bcf7ed535..4785f229c6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,10 +6,45 @@ linters-settings: min-occurrences: 2 gocyclo: min-complexity: 15 - govet: - check-shadowing: true - maligned: - suggest-new: true + importas: + no-extra-aliases: true + alias: + - pkg: go.mongodb.org/atlas-sdk/v[\d]+/admin + alias: atlasv2 + - pkg: go.mongodb.org/atlas/mongodbatlas + alias: atlas + - pkg: go.mongodb.org/atlas/auth + alias: atlasauth + - pkg: github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1 + alias: akov2 + - pkg: github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/common + alias: akov2common + - pkg: github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/provider + alias: akov2provider + - pkg: github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status + alias: akov2status + - pkg: github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/project + alias: akov2project + - pkg: k8s.io/apimachinery/pkg/apis/meta/v1 + alias: metav1 + - pkg: k8s.io/api/apps/v1 + alias: appsv1 + - pkg: k8s.io/api/core/v1 + alias: corev1 + - pkg: k8s.io/api/rbac/v1 + alias: rbacv1 + - pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1 + alias: apiextensionsv1 + - pkg: k8s.io/apiserver/pkg/storage/names + alias: k8snames + - pkg: github.com/AlecAivazis/survey/v2/core + alias: survey + - pkg: github.com/creack/pty + alias: pseudotty + - pkg: cloud.google.com/go/kms/apiv1 + alias: kmsv1 + - pkg: github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/config + alias: cliconfig misspell: locale: US ignore-words: @@ -59,8 +94,6 @@ linters-settings: sections: - standard - default - section-separators: - - newLine linters: disable-all: true enable: @@ -83,6 +116,7 @@ linters: - gosimple # (megacheck) Linter for Go source code that specializes in simplifying code [fast: false, auto-fix: false] - govet # (vet, vetshadow) Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] - ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] + - importas # Enforces consistent import aliases [fast: false, auto-fix: false] - makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false] - misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true] - nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] @@ -138,7 +172,6 @@ linters: # - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] # - grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false] # - ifshort # [deprecated] Checks that your code uses short syntax for if-statements whenever possible [fast: true, auto-fix: false] - # - importas # Enforces consistent import aliases [fast: false, auto-fix: false] # - interfacebloat # A linter that checks the number of methods inside an interface. [fast: true, auto-fix: false] # - interfacer # [deprecated]: Linter that suggests narrower interface types [fast: false, auto-fix: false] # - ireturn # Accept Interfaces, Return Concrete Types [fast: false, auto-fix: false] @@ -174,8 +207,6 @@ run: - e2e - unit - integration - skip-dirs: - - internal/mocks modules-download-mode: readonly issues: diff --git a/internal/kubernetes/operator/crds/provider.go b/internal/kubernetes/operator/crds/provider.go index 6a915ee61e..d39d908b75 100644 --- a/internal/kubernetes/operator/crds/provider.go +++ b/internal/kubernetes/operator/crds/provider.go @@ -21,7 +21,7 @@ import ( "net/http" "time" - apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "sigs.k8s.io/yaml" ) @@ -32,7 +32,7 @@ const ( //go:generate mockgen -destination=../../../mocks/mock_atlas_operator_crd_provider.go -package=mocks github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/crds AtlasOperatorCRDProvider type AtlasOperatorCRDProvider interface { - GetAtlasOperatorResource(resourceName, version string) (*apiextensions.CustomResourceDefinition, error) + GetAtlasOperatorResource(resourceName, version string) (*apiextensionsv1.CustomResourceDefinition, error) } type GithubAtlasCRDProvider struct { @@ -43,7 +43,7 @@ func NewGithubAtlasCRDProvider() *GithubAtlasCRDProvider { return &GithubAtlasCRDProvider{client: &http.Client{}} } -func (p *GithubAtlasCRDProvider) GetAtlasOperatorResource(resourceName, version string) (*apiextensions.CustomResourceDefinition, error) { +func (p *GithubAtlasCRDProvider) GetAtlasOperatorResource(resourceName, version string) (*apiextensionsv1.CustomResourceDefinition, error) { ctx, cancelF := context.WithTimeout(context.Background(), requestTimeout) defer cancelF() @@ -63,7 +63,7 @@ func (p *GithubAtlasCRDProvider) GetAtlasOperatorResource(resourceName, version return nil, err } - decoded := &apiextensions.CustomResourceDefinition{} + decoded := &apiextensionsv1.CustomResourceDefinition{} err = yaml.Unmarshal(data, decoded) if err != nil { return nil, err diff --git a/internal/kubernetes/operator/datafederation/datafederation.go b/internal/kubernetes/operator/datafederation/datafederation.go index 28de3fae39..4b55b2430b 100644 --- a/internal/kubernetes/operator/datafederation/datafederation.go +++ b/internal/kubernetes/operator/datafederation/datafederation.go @@ -23,8 +23,8 @@ import ( akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1" akov2common "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/common" akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status" - "go.mongodb.org/atlas-sdk/v20231115008/admin" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -41,11 +41,11 @@ func BuildAtlasDataFederation(dataFederationStore store.DataFederationStore, dat return nil, nil } atlasDataFederation := &akov2.AtlasDataFederation{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ APIVersion: "atlas.mongodb.com/v1", Kind: "AtlasDataFederation", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, dataFederation.GetName()), dictionary), Namespace: targetNamespace, Labels: map[string]string{ @@ -62,12 +62,12 @@ func BuildAtlasDataFederation(dataFederationStore store.DataFederationStore, dat return atlasDataFederation, nil } -func isDataFederationExportable(dataFederation *admin.DataLakeTenant) bool { +func isDataFederationExportable(dataFederation *atlasv2.DataLakeTenant) bool { state := dataFederation.GetState() return state != DeletingState && state != DeletedState } -func getDataFederationSpec(dataFederationSpec *admin.DataLakeTenant, targetNamespace, projectName string) akov2.DataFederationSpec { +func getDataFederationSpec(dataFederationSpec *atlasv2.DataLakeTenant, targetNamespace, projectName string) akov2.DataFederationSpec { return akov2.DataFederationSpec{ Project: akov2common.ResourceRefNamespaced{Name: projectName, Namespace: targetNamespace}, Name: dataFederationSpec.GetName(), @@ -77,7 +77,7 @@ func getDataFederationSpec(dataFederationSpec *admin.DataLakeTenant, targetNames } } -func getCloudProviderConfig(cloudProviderConfig *admin.DataLakeCloudProviderConfig) *akov2.CloudProviderConfig { +func getCloudProviderConfig(cloudProviderConfig *atlasv2.DataLakeCloudProviderConfig) *akov2.CloudProviderConfig { if cloudProviderConfig == nil { return &akov2.CloudProviderConfig{} } @@ -89,7 +89,7 @@ func getCloudProviderConfig(cloudProviderConfig *admin.DataLakeCloudProviderConf } } -func getDataProcessRegion(dataProcessRegion *admin.DataLakeDataProcessRegion) *akov2.DataProcessRegion { +func getDataProcessRegion(dataProcessRegion *atlasv2.DataLakeDataProcessRegion) *akov2.DataProcessRegion { if dataProcessRegion == nil { return &akov2.DataProcessRegion{} } @@ -99,7 +99,7 @@ func getDataProcessRegion(dataProcessRegion *admin.DataLakeDataProcessRegion) *a } } -func getStorage(storage *admin.DataLakeStorage) *akov2.Storage { +func getStorage(storage *atlasv2.DataLakeStorage) *akov2.Storage { if storage == nil { return &akov2.Storage{} } @@ -109,7 +109,7 @@ func getStorage(storage *admin.DataLakeStorage) *akov2.Storage { } } -func getDatabases(database []admin.DataLakeDatabaseInstance) []akov2.Database { +func getDatabases(database []atlasv2.DataLakeDatabaseInstance) []akov2.Database { if database == nil { return []akov2.Database{} } @@ -126,7 +126,7 @@ func getDatabases(database []admin.DataLakeDatabaseInstance) []akov2.Database { return result } -func getCollection(collections []admin.DataLakeDatabaseCollection) []akov2.Collection { +func getCollection(collections []atlasv2.DataLakeDatabaseCollection) []akov2.Collection { if collections == nil { return []akov2.Collection{} } @@ -141,7 +141,7 @@ func getCollection(collections []admin.DataLakeDatabaseCollection) []akov2.Colle return result } -func getDataSources(dataSources []admin.DataLakeDatabaseDataSourceSettings) []akov2.DataSource { +func getDataSources(dataSources []atlasv2.DataLakeDatabaseDataSourceSettings) []akov2.DataSource { if dataSources == nil { return []akov2.DataSource{} } @@ -164,7 +164,7 @@ func getDataSources(dataSources []admin.DataLakeDatabaseDataSourceSettings) []ak return result } -func getViews(views []admin.DataLakeApiBase) []akov2.View { +func getViews(views []atlasv2.DataLakeApiBase) []akov2.View { if views == nil { return []akov2.View{} } @@ -180,7 +180,7 @@ func getViews(views []admin.DataLakeApiBase) []akov2.View { return result } -func getStores(stores []admin.DataLakeStoreSettings) []akov2.Store { +func getStores(stores []atlasv2.DataLakeStoreSettings) []akov2.Store { if stores == nil { return []akov2.Store{} } diff --git a/internal/kubernetes/operator/datafederation/datafederation_test.go b/internal/kubernetes/operator/datafederation/datafederation_test.go index 84134996a7..6e283f55f1 100644 --- a/internal/kubernetes/operator/datafederation/datafederation_test.go +++ b/internal/kubernetes/operator/datafederation/datafederation_test.go @@ -29,8 +29,8 @@ import ( akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1" akov2common "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/common" akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status" - "go.mongodb.org/atlas-sdk/v20231115008/admin" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -47,26 +47,26 @@ func Test_BuildAtlasDataFederation(t *testing.T) { dictionary := resources.AtlasNameToKubernetesName() t.Run("Can import Data Federations", func(t *testing.T) { - dataFederation := &admin.DataLakeTenant{ - CloudProviderConfig: &admin.DataLakeCloudProviderConfig{ - Aws: admin.DataLakeAWSCloudProviderConfig{ + dataFederation := &atlasv2.DataLakeTenant{ + CloudProviderConfig: &atlasv2.DataLakeCloudProviderConfig{ + Aws: atlasv2.DataLakeAWSCloudProviderConfig{ RoleId: "TestRoleID", TestS3Bucket: "TestBucket", }, }, - DataProcessRegion: &admin.DataLakeDataProcessRegion{ + DataProcessRegion: &atlasv2.DataLakeDataProcessRegion{ CloudProvider: "TestProvider", Region: "TestRegion", }, Hostnames: &[]string{"TestHostname"}, Name: pointer.Get(dataFederationName), State: pointer.Get("TestState"), - Storage: &admin.DataLakeStorage{ - Databases: &[]admin.DataLakeDatabaseInstance{ + Storage: &atlasv2.DataLakeStorage{ + Databases: &[]atlasv2.DataLakeDatabaseInstance{ { - Collections: &[]admin.DataLakeDatabaseCollection{ + Collections: &[]atlasv2.DataLakeDatabaseCollection{ { - DataSources: &[]admin.DataLakeDatabaseDataSourceSettings{ + DataSources: &[]atlasv2.DataLakeDatabaseDataSourceSettings{ { AllowInsecure: pointer.Get(true), Collection: pointer.Get("TestCollection"), @@ -85,7 +85,7 @@ func Test_BuildAtlasDataFederation(t *testing.T) { }, MaxWildcardCollections: pointer.Get(10), Name: pointer.Get("TestName"), - Views: &[]admin.DataLakeApiBase{ + Views: &[]atlasv2.DataLakeApiBase{ { Name: pointer.Get("TestName"), Pipeline: pointer.Get("TestPipeline"), @@ -94,7 +94,7 @@ func Test_BuildAtlasDataFederation(t *testing.T) { }, }, }, - Stores: &[]admin.DataLakeStoreSettings{ + Stores: &[]atlasv2.DataLakeStoreSettings{ { Name: pointer.Get("TestName"), Provider: "TestProvider", @@ -113,11 +113,11 @@ func Test_BuildAtlasDataFederation(t *testing.T) { dataFederationStore.EXPECT().DataFederation(projectID, dataFederationName).Return(dataFederation, nil) expected := &akov2.AtlasDataFederation{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDataFederation", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, dataFederation.GetName()), dictionary), Namespace: targetNamespace, Labels: map[string]string{ diff --git a/internal/kubernetes/operator/dbusers/dbusers.go b/internal/kubernetes/operator/dbusers/dbusers.go index b2d0fc1f61..5431a2e9de 100644 --- a/internal/kubernetes/operator/dbusers/dbusers.go +++ b/internal/kubernetes/operator/dbusers/dbusers.go @@ -28,7 +28,7 @@ import ( akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status" atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const timeFormatISO8601 = "2006-01-02T15:04:05.999Z" @@ -57,11 +57,11 @@ func BuildDBUsers(provider store.OperatorDBUsersStore, projectID, projectName, t scopes := convertUserScopes(user) mappedUsers[resourceName] = &akov2.AtlasDatabaseUser{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDatabaseUser", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resourceName, Namespace: targetNamespace, Labels: map[string]string{ diff --git a/internal/kubernetes/operator/dbusers/dbusers_test.go b/internal/kubernetes/operator/dbusers/dbusers_test.go index 38ec574772..3f7c360d8b 100644 --- a/internal/kubernetes/operator/dbusers/dbusers_test.go +++ b/internal/kubernetes/operator/dbusers/dbusers_test.go @@ -38,7 +38,7 @@ import ( "github.com/stretchr/testify/assert" atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const resourceVersion = "x.y.z" @@ -103,11 +103,11 @@ func Test_buildUserSecret(t *testing.T) { } expectedSecret := &corev1.Secret{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Secret", APIVersion: "v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: strings.ToLower(fmt.Sprintf("%s-%s", projectName, atlasUser.Username)), Namespace: "TestNamespace", Labels: map[string]string{ @@ -181,11 +181,11 @@ func TestBuildDBUsers(t *testing.T) { } expectedUser := &akov2.AtlasDatabaseUser{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDatabaseUser", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, user.Username), dictionary), Namespace: targetNamespace, Labels: map[string]string{ diff --git a/internal/kubernetes/operator/deployment/deployment.go b/internal/kubernetes/operator/deployment/deployment.go index c050174bfd..3243569009 100644 --- a/internal/kubernetes/operator/deployment/deployment.go +++ b/internal/kubernetes/operator/deployment/deployment.go @@ -27,7 +27,7 @@ import ( akov2provider "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/provider" akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status" atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -110,11 +110,11 @@ func BuildAtlasAdvancedDeployment(deploymentStore store.OperatorClusterStore, va } atlasDeployment := &akov2.AtlasDeployment{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDeployment", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, clusterID), dictionary), Namespace: targetNamespace, Labels: map[string]string{ @@ -296,11 +296,11 @@ func buildBackups(backupsProvider store.ScheduleDescriber, projectName, projectI }) } policies = append(policies, &akov2.AtlasBackupPolicy{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasBackupPolicy", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s-backuppolicy", projectName, clusterName), dictionary), Namespace: targetNamespace, Labels: map[string]string{ @@ -323,11 +323,11 @@ func buildBackups(backupsProvider store.ScheduleDescriber, projectName, projectI } schedule := &akov2.AtlasBackupSchedule{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasBackupSchedule", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s-backupschedule", projectName, clusterName), dictionary), Namespace: targetNamespace, Labels: map[string]string{ @@ -476,11 +476,11 @@ func BuildServerlessDeployments(deploymentStore store.OperatorClusterStore, vali atlasName := fmt.Sprintf("%s-%s", projectName, store.StringOrEmpty(deployment.Name)) atlasDeployment := &akov2.AtlasDeployment{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDeployment", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(atlasName, dictionary), Namespace: targetNamespace, Labels: map[string]string{ diff --git a/internal/kubernetes/operator/deployment/deployment_test.go b/internal/kubernetes/operator/deployment/deployment_test.go index ff26904c74..eaf5933c52 100644 --- a/internal/kubernetes/operator/deployment/deployment_test.go +++ b/internal/kubernetes/operator/deployment/deployment_test.go @@ -35,7 +35,7 @@ import ( akov2provider "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/provider" akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status" atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const resourceVersion = "x.y.z" @@ -142,7 +142,7 @@ func TestBuildAtlasAdvancedDeployment(t *testing.T) { SampleRefreshIntervalBIConnector: pointer.Get(10), } processArgs.OplogSizeMB = pointer.Get(10) - processArgs.OplogMinRetentionHours = pointer.Get(float64(10.1)) + processArgs.OplogMinRetentionHours = pointer.Get[float64](10.1) backupSchedule := &atlasv2.DiskBackupSnapshotSchedule{ ClusterId: pointer.Get("testClusterID"), ClusterName: pointer.Get(clusterName), @@ -206,11 +206,11 @@ func TestBuildAtlasAdvancedDeployment(t *testing.T) { clusterStore.EXPECT().DescribeSchedule(projectName, clusterName).Return(backupSchedule, nil) expectCluster := &akov2.AtlasDeployment{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDeployment", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: strings.ToLower(fmt.Sprintf("%s-%s", projectName, clusterName)), Namespace: targetNamespace, Labels: map[string]string{ @@ -331,11 +331,11 @@ func TestBuildAtlasAdvancedDeployment(t *testing.T) { expectPolicies := []*akov2.AtlasBackupPolicy{ { - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasBackupPolicy", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: strings.ToLower(fmt.Sprintf("%s-%s-backuppolicy", projectName, clusterName)), Namespace: targetNamespace, Labels: map[string]string{ @@ -357,11 +357,11 @@ func TestBuildAtlasAdvancedDeployment(t *testing.T) { } expectSchedule := &akov2.AtlasBackupSchedule{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasBackupSchedule", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: strings.ToLower(fmt.Sprintf("%s-%s-backupschedule", projectName, clusterName)), Namespace: targetNamespace, Labels: map[string]string{ @@ -467,11 +467,11 @@ func TestBuildServerlessDeployments(t *testing.T) { clusterStore.EXPECT().ServerlessPrivateEndpoints(projectName, clusterName).Return(spe, nil) expected := &akov2.AtlasDeployment{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDeployment", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: strings.ToLower(fmt.Sprintf("%s-%s", projectName, clusterName)), Namespace: targetNamespace, Labels: map[string]string{ diff --git a/internal/kubernetes/operator/features/crds.go b/internal/kubernetes/operator/features/crds.go index 11c2d10a79..a62a1a25a5 100644 --- a/internal/kubernetes/operator/features/crds.go +++ b/internal/kubernetes/operator/features/crds.go @@ -21,7 +21,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/crds" - apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" ) @@ -136,7 +136,7 @@ func CRDCompatibleVersion(operatorVersion string) (string, error) { } type AtlasCRDs struct { - resources map[string]*apiextensions.JSONSchemaProps + resources map[string]*apiextensionsv1.JSONSchemaProps patchers map[string]Patcher } @@ -162,7 +162,7 @@ func NewAtlasCRDs(crdProvider crds.AtlasOperatorCRDProvider, version string) (*A } result := &AtlasCRDs{ - resources: map[string]*apiextensions.JSONSchemaProps{}, + resources: map[string]*apiextensionsv1.JSONSchemaProps{}, patchers: map[string]Patcher{}, } @@ -195,14 +195,14 @@ func (a *AtlasCRDs) FeatureExist(resourceName, featurePath string) bool { return false } -func pathExists(path string, data *apiextensions.JSONSchemaProps) bool { +func pathExists(path string, data *apiextensionsv1.JSONSchemaProps) bool { parts := strings.Split(path, ".") if len(parts) == 0 || data == nil { return false } - var lookup func(path []string, data *apiextensions.JSONSchemaProps, depth int) bool - lookup = func(path []string, data *apiextensions.JSONSchemaProps, depth int) bool { + var lookup func(path []string, data *apiextensionsv1.JSONSchemaProps, depth int) bool + lookup = func(path []string, data *apiextensionsv1.JSONSchemaProps, depth int) bool { if len(path) == 0 { return true } @@ -230,7 +230,7 @@ func pathExists(path string, data *apiextensions.JSONSchemaProps) bool { return lookup(parts, data, maxDepth) } -func getCRDRoot(document *apiextensions.CustomResourceDefinition) (*apiextensions.JSONSchemaProps, error) { +func getCRDRoot(document *apiextensionsv1.CustomResourceDefinition) (*apiextensionsv1.JSONSchemaProps, error) { if document == nil { return nil, ErrDocumentIsEmpty } diff --git a/internal/kubernetes/operator/features/crds_test.go b/internal/kubernetes/operator/features/crds_test.go index 6fa9a64705..3c5287aa7f 100644 --- a/internal/kubernetes/operator/features/crds_test.go +++ b/internal/kubernetes/operator/features/crds_test.go @@ -22,36 +22,36 @@ import ( "github.com/Masterminds/semver/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" ) func Test_getCRDRoot(t *testing.T) { - properties := map[string]apiextensions.JSONSchemaProps{ + properties := map[string]apiextensionsv1.JSONSchemaProps{ "spec": { - Items: &apiextensions.JSONSchemaPropsOrArray{}, + Items: &apiextensionsv1.JSONSchemaPropsOrArray{}, }, } specPtr := properties["spec"] type args struct { - document *apiextensions.CustomResourceDefinition + document *apiextensionsv1.CustomResourceDefinition } tests := []struct { name string args args - want *apiextensions.JSONSchemaProps + want *apiextensionsv1.JSONSchemaProps wantErr bool }{ { name: "Can get document Root for a valid CRD", args: args{ - document: &apiextensions.CustomResourceDefinition{ - Spec: apiextensions.CustomResourceDefinitionSpec{ - Versions: []apiextensions.CustomResourceDefinitionVersion{ + document: &apiextensionsv1.CustomResourceDefinition{ + Spec: apiextensionsv1.CustomResourceDefinitionSpec{ + Versions: []apiextensionsv1.CustomResourceDefinitionVersion{ { - Schema: &apiextensions.CustomResourceValidation{ - OpenAPIV3Schema: &apiextensions.JSONSchemaProps{ + Schema: &apiextensionsv1.CustomResourceValidation{ + OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{ Properties: properties, }, }, @@ -74,9 +74,9 @@ func Test_getCRDRoot(t *testing.T) { { name: "Return an error if there are no versions", args: args{ - document: &apiextensions.CustomResourceDefinition{ - Spec: apiextensions.CustomResourceDefinitionSpec{ - Versions: []apiextensions.CustomResourceDefinitionVersion{}, + document: &apiextensionsv1.CustomResourceDefinition{ + Spec: apiextensionsv1.CustomResourceDefinitionSpec{ + Versions: []apiextensionsv1.CustomResourceDefinitionVersion{}, }, }, }, @@ -86,11 +86,11 @@ func Test_getCRDRoot(t *testing.T) { { name: "Return an error if there is no Schema", args: args{ - document: &apiextensions.CustomResourceDefinition{ - Spec: apiextensions.CustomResourceDefinitionSpec{ - Versions: []apiextensions.CustomResourceDefinitionVersion{ + document: &apiextensionsv1.CustomResourceDefinition{ + Spec: apiextensionsv1.CustomResourceDefinitionSpec{ + Versions: []apiextensionsv1.CustomResourceDefinitionVersion{ { - Schema: &apiextensions.CustomResourceValidation{ + Schema: &apiextensionsv1.CustomResourceValidation{ OpenAPIV3Schema: nil, }, }, @@ -104,13 +104,13 @@ func Test_getCRDRoot(t *testing.T) { { name: "Return an error if there is no Spec", args: args{ - document: &apiextensions.CustomResourceDefinition{ - Spec: apiextensions.CustomResourceDefinitionSpec{ - Versions: []apiextensions.CustomResourceDefinitionVersion{ + document: &apiextensionsv1.CustomResourceDefinition{ + Spec: apiextensionsv1.CustomResourceDefinitionSpec{ + Versions: []apiextensionsv1.CustomResourceDefinitionVersion{ { - Schema: &apiextensions.CustomResourceValidation{ - OpenAPIV3Schema: &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{}, + Schema: &apiextensionsv1.CustomResourceValidation{ + OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{}, }, }, }, @@ -139,7 +139,7 @@ func Test_getCRDRoot(t *testing.T) { func Test_pathExists(t *testing.T) { type args struct { path string - data *apiextensions.JSONSchemaProps + data *apiextensionsv1.JSONSchemaProps } tests := []struct { name string @@ -150,10 +150,10 @@ func Test_pathExists(t *testing.T) { name: "Path is valid with Properties", args: args{ path: "level1.level2", - data: &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{ + data: &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level1": { - Properties: map[string]apiextensions.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level2": {}, }, }, @@ -166,10 +166,10 @@ func Test_pathExists(t *testing.T) { name: "Path is NOT valid with Properties", args: args{ path: "level1.level2", - data: &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{ + data: &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level1": { - Properties: map[string]apiextensions.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level3": {}, }, }, @@ -182,14 +182,14 @@ func Test_pathExists(t *testing.T) { name: "Path is valid with Items", args: args{ path: "level1.level2", - data: &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{ + data: &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level1": { - Items: &apiextensions.JSONSchemaPropsOrArray{ + Items: &apiextensionsv1.JSONSchemaPropsOrArray{ Schema: nil, - JSONSchemas: []apiextensions.JSONSchemaProps{ + JSONSchemas: []apiextensionsv1.JSONSchemaProps{ { - Properties: map[string]apiextensions.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level2": {}, }, }, @@ -205,14 +205,14 @@ func Test_pathExists(t *testing.T) { name: "Path is NOT valid with Items", args: args{ path: "level1.level2", - data: &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{ + data: &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level1": { - Items: &apiextensions.JSONSchemaPropsOrArray{ + Items: &apiextensionsv1.JSONSchemaPropsOrArray{ Schema: nil, - JSONSchemas: []apiextensions.JSONSchemaProps{ + JSONSchemas: []apiextensionsv1.JSONSchemaProps{ { - Properties: map[string]apiextensions.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level32": {}, }, }, @@ -228,19 +228,19 @@ func Test_pathExists(t *testing.T) { name: "Path is valid with Items and Props", args: args{ path: "level1.level2.level3", - data: &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{ + data: &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level1": { - Items: &apiextensions.JSONSchemaPropsOrArray{ + Items: &apiextensionsv1.JSONSchemaPropsOrArray{ Schema: nil, - JSONSchemas: []apiextensions.JSONSchemaProps{ + JSONSchemas: []apiextensionsv1.JSONSchemaProps{ { - Properties: map[string]apiextensions.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level2": { - Items: &apiextensions.JSONSchemaPropsOrArray{ + Items: &apiextensionsv1.JSONSchemaPropsOrArray{ JSONSchemas: nil, - Schema: &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{ + Schema: &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "level3": {}, }, }, diff --git a/internal/kubernetes/operator/features/patcher.go b/internal/kubernetes/operator/features/patcher.go index 42df38bb7e..4e0bf037ca 100644 --- a/internal/kubernetes/operator/features/patcher.go +++ b/internal/kubernetes/operator/features/patcher.go @@ -19,25 +19,25 @@ import ( "strings" akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1" - v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/runtime" ) // Patcher is the type that is able to patch Kubernetes objects using a CRD specification. type Patcher interface { - Patch(crdSpec *v1.JSONSchemaProps, obj runtime.Object) error + Patch(crdSpec *apiextensionsv1.JSONSchemaProps, obj runtime.Object) error } // PatcherFunc is a convenience function wrapper around Patcher. -type PatcherFunc func(crdSpec *v1.JSONSchemaProps, obj runtime.Object) error +type PatcherFunc func(crdSpec *apiextensionsv1.JSONSchemaProps, obj runtime.Object) error -func (pf PatcherFunc) Patch(crdSpec *v1.JSONSchemaProps, obj runtime.Object) error { +func (pf PatcherFunc) Patch(crdSpec *apiextensionsv1.JSONSchemaProps, obj runtime.Object) error { return pf(crdSpec, obj) } // NopPatcher does not patch anything. func NopPatcher() Patcher { - return PatcherFunc(func(*v1.JSONSchemaProps, runtime.Object) error { + return PatcherFunc(func(*apiextensionsv1.JSONSchemaProps, runtime.Object) error { return nil }) } @@ -45,7 +45,7 @@ func NopPatcher() Patcher { // UnknownBackupPolicyFrequencyTypesPruner removes backup policy items from a backup policy // with unknown frequency types. // It inspects the CRD definition to determine supported frequency types. -func UnknownBackupPolicyFrequencyTypesPruner(crdSpec *v1.JSONSchemaProps, obj runtime.Object) error { +func UnknownBackupPolicyFrequencyTypesPruner(crdSpec *apiextensionsv1.JSONSchemaProps, obj runtime.Object) error { // we are not defensive here as this function assumes the invariant // of a stable CRD definition for a given version of Kubernetes Atlas Operator. frequencyTypePropsEnum := crdSpec.Properties["items"].Items.Schema.Properties["frequencyType"].Enum diff --git a/internal/kubernetes/operator/features/patcher_test.go b/internal/kubernetes/operator/features/patcher_test.go index 47d5047d42..afee19448f 100644 --- a/internal/kubernetes/operator/features/patcher_test.go +++ b/internal/kubernetes/operator/features/patcher_test.go @@ -18,19 +18,19 @@ import ( "testing" akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1" - apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/equality" ) func TestUnkownBackupPolicyFrequencyTypesPruner(t *testing.T) { - crdSpec := &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{ + crdSpec := &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "items": { - Items: &apiextensions.JSONSchemaPropsOrArray{ - Schema: &apiextensions.JSONSchemaProps{ - Properties: map[string]apiextensions.JSONSchemaProps{ + Items: &apiextensionsv1.JSONSchemaPropsOrArray{ + Schema: &apiextensionsv1.JSONSchemaProps{ + Properties: map[string]apiextensionsv1.JSONSchemaProps{ "frequencyType": { - Enum: []apiextensions.JSON{ + Enum: []apiextensionsv1.JSON{ {Raw: []byte(`"daily"`)}, {Raw: []byte(`"monthly"`)}, }, @@ -44,7 +44,7 @@ func TestUnkownBackupPolicyFrequencyTypesPruner(t *testing.T) { tests := []struct { name string - crdSpec *apiextensions.JSONSchemaProps + crdSpec *apiextensionsv1.JSONSchemaProps atlasBackupPolicy *akov2.AtlasBackupPolicy wantAtlasBackupPolicy *akov2.AtlasBackupPolicy wantErr string diff --git a/internal/kubernetes/operator/install_resources.go b/internal/kubernetes/operator/install_resources.go index 0e9e3d563a..f575e22c80 100644 --- a/internal/kubernetes/operator/install_resources.go +++ b/internal/kubernetes/operator/install_resources.go @@ -29,7 +29,7 @@ import ( corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - apisv1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/scheme" ) @@ -156,7 +156,7 @@ func (ir *InstallResources) InstallCredentials(ctx context.Context, namespace, o } obj := &corev1.Secret{ - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, Labels: map[string]string{ diff --git a/internal/kubernetes/operator/project/project.go b/internal/kubernetes/operator/project/project.go index d79047e6f3..ca3258356f 100644 --- a/internal/kubernetes/operator/project/project.go +++ b/internal/kubernetes/operator/project/project.go @@ -30,7 +30,7 @@ import ( akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status" atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8snames "k8s.io/apiserver/pkg/storage/names" ) @@ -192,11 +192,11 @@ func BuildAtlasProject(projectStore store.OperatorProjectStore, validator featur func newAtlasProject(project *atlasv2.Group, dictionary map[string]string, targetNamespace string, version string) *akov2.AtlasProject { return &akov2.AtlasProject{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasProject", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(project.Name, dictionary), Namespace: targetNamespace, Labels: map[string]string{ @@ -908,11 +908,11 @@ func buildTeams(teamsProvider store.OperatorTeamsStore, orgID, projectID, projec } atlasTeamCRs = append(atlasTeamCRs, &akov2.AtlasTeam{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasTeam", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: crName, Namespace: targetNamespace, Labels: map[string]string{ diff --git a/internal/kubernetes/operator/project/project_test.go b/internal/kubernetes/operator/project/project_test.go index fff2dc2420..f9739622ac 100644 --- a/internal/kubernetes/operator/project/project_test.go +++ b/internal/kubernetes/operator/project/project_test.go @@ -39,7 +39,7 @@ import ( "github.com/stretchr/testify/assert" atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -380,11 +380,11 @@ func TestBuildAtlasProject(t *testing.T) { teamsName := store.StringOrEmpty(teams.Name) expectedTeams := []*akov2.AtlasTeam{ { - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasTeam", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-team-%s", strings.ToLower(p.Name), strings.ToLower(teamsName)), Namespace: targetNamespace, Labels: map[string]string{ @@ -403,11 +403,11 @@ func TestBuildAtlasProject(t *testing.T) { }, } expectedProject := &akov2.AtlasProject{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasProject", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(p.Name, dictionary), Namespace: targetNamespace, Labels: map[string]string{ @@ -585,11 +585,11 @@ func TestBuildProjectConnectionSecret(t *testing.T) { orgID, true, dictionary) expected := &corev1.Secret{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Secret", APIVersion: "v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: strings.ToLower(fmt.Sprintf("%s-credentials", name)), Namespace: namespace, Labels: map[string]string{ @@ -615,11 +615,11 @@ func TestBuildProjectConnectionSecret(t *testing.T) { orgID, false, dictionary) expected := &corev1.Secret{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Secret", APIVersion: "v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: strings.ToLower(fmt.Sprintf("%s-credentials", name)), Namespace: namespace, Labels: map[string]string{ @@ -953,11 +953,11 @@ func Test_buildIntegrations(t *testing.T) { expectedSecrets := []*corev1.Secret{ { - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Secret", APIVersion: "v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-integration-%s", strings.ToLower(projectID), strings.ToLower(ints.GetResults()[0].GetType())), @@ -1018,11 +1018,11 @@ func Test_buildIntegrations(t *testing.T) { expectedSecrets := []*corev1.Secret{ { - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Secret", APIVersion: "v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-integration-%s", strings.ToLower(projectID), strings.ToLower(ints.GetResults()[0].GetType())), diff --git a/internal/kubernetes/operator/secrets/secrets.go b/internal/kubernetes/operator/secrets/secrets.go index ffd030b47a..2905cc29d6 100644 --- a/internal/kubernetes/operator/secrets/secrets.go +++ b/internal/kubernetes/operator/secrets/secrets.go @@ -17,7 +17,7 @@ package secrets import ( "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/kubernetes/operator/resources" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -38,11 +38,11 @@ type AtlasSecretBuilder func() (*corev1.Secret, map[string]string) func NewAtlasSecretBuilder(name, namespace string, dictionary map[string]string) AtlasSecretBuilder { return func() (*corev1.Secret, map[string]string) { secret := &corev1.Secret{ - TypeMeta: v1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Secret", APIVersion: "v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(name, dictionary), Namespace: namespace, Labels: map[string]string{ diff --git a/test/e2e/atlas/kubernetes_config_apply_test.go b/test/e2e/atlas/kubernetes_config_apply_test.go index 0bb57265c3..8873d57f09 100644 --- a/test/e2e/atlas/kubernetes_config_apply_test.go +++ b/test/e2e/atlas/kubernetes_config_apply_test.go @@ -30,7 +30,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" - apisv1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -70,7 +70,7 @@ func TestKubernetesConfigApply(t *testing.T) { }) e2eNamespace := &corev1.Namespace{ - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "e2e-autodetect-parameters", }, } @@ -104,7 +104,7 @@ func TestKubernetesConfigApply(t *testing.T) { }) e2eNamespace := &corev1.Namespace{ - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "e2e-autodetect-operator-version", }, } @@ -138,7 +138,7 @@ func TestKubernetesConfigApply(t *testing.T) { }) e2eNamespace := &corev1.Namespace{ - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "e2e-export-atlas-resource", }, } diff --git a/test/e2e/atlas/kubernetes_config_generate_test.go b/test/e2e/atlas/kubernetes_config_generate_test.go index 4a7550164c..1e8045b2ca 100644 --- a/test/e2e/atlas/kubernetes_config_generate_test.go +++ b/test/e2e/atlas/kubernetes_config_generate_test.go @@ -42,7 +42,7 @@ import ( "github.com/stretchr/testify/require" atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" corev1 "k8s.io/api/core/v1" - apisv1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/kubernetes/scheme" @@ -838,11 +838,11 @@ func referenceTeam(name, namespace string, users []akov2.TeamUser, projectName s dictionary := resources.AtlasNameToKubernetesName() return &akov2.AtlasTeam{ - TypeMeta: apisv1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasTeam", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-team-%s", projectName, name), dictionary), Namespace: namespace, Labels: labels, @@ -899,11 +899,11 @@ func checkProject(t *testing.T, output []runtime.Object, expected *akov2.AtlasPr func referenceProject(name, namespace string, labels map[string]string) *akov2.AtlasProject { dictionary := resources.AtlasNameToKubernetesName() return &akov2.AtlasProject{ - TypeMeta: apisv1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasProject", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(name, dictionary), Namespace: namespace, Labels: labels, @@ -960,11 +960,11 @@ func referenceProject(name, namespace string, labels map[string]string) *akov2.A func referenceAdvancedCluster(name, region, namespace, projectName string, labels map[string]string) *akov2.AtlasDeployment { dictionary := resources.AtlasNameToKubernetesName() return &akov2.AtlasDeployment{ - TypeMeta: apisv1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDeployment", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, name), dictionary), Namespace: namespace, Labels: labels, @@ -1050,11 +1050,11 @@ func referenceAdvancedCluster(name, region, namespace, projectName string, label func referenceServerless(name, region, namespace, projectName string, labels map[string]string) *akov2.AtlasDeployment { dictionary := resources.AtlasNameToKubernetesName() return &akov2.AtlasDeployment{ - TypeMeta: apisv1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDeployment", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, name), dictionary), Namespace: namespace, Labels: labels, @@ -1159,11 +1159,11 @@ func defaultMaintenanceWindowAlertConfigs() []akov2.AlertConfiguration { func referenceBackupSchedule(namespace, projectName, clusterName string, labels map[string]string) *akov2.AtlasBackupSchedule { dictionary := resources.AtlasNameToKubernetesName() return &akov2.AtlasBackupSchedule{ - TypeMeta: apisv1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasBackupSchedule", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s-backupschedule", projectName, clusterName), dictionary), Namespace: namespace, Labels: labels, @@ -1183,11 +1183,11 @@ func referenceBackupSchedule(namespace, projectName, clusterName string, labels func referenceBackupPolicy(namespace, projectName, clusterName string, labels map[string]string) *akov2.AtlasBackupPolicy { dictionary := resources.AtlasNameToKubernetesName() return &akov2.AtlasBackupPolicy{ - TypeMeta: apisv1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasBackupPolicy", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s-backuppolicy", projectName, clusterName), dictionary), Namespace: namespace, Labels: labels, @@ -1567,11 +1567,11 @@ func atlasBackupSchedule(objects []runtime.Object) (*akov2.AtlasBackupSchedule, func referenceDataFederation(name, namespace, projectName string, labels map[string]string) *akov2.AtlasDataFederation { dictionary := resources.AtlasNameToKubernetesName() return &akov2.AtlasDataFederation{ - TypeMeta: apisv1.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "AtlasDataFederation", APIVersion: "atlas.mongodb.com/v1", }, - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, name), dictionary), Namespace: namespace, Labels: labels, diff --git a/test/e2e/atlas/kubernetes_operator_install_test.go b/test/e2e/atlas/kubernetes_operator_install_test.go index 8c86fe6fa1..12b6c47c3c 100644 --- a/test/e2e/atlas/kubernetes_operator_install_test.go +++ b/test/e2e/atlas/kubernetes_operator_install_test.go @@ -32,7 +32,7 @@ import ( atlasv2 "go.mongodb.org/atlas-sdk/v20231115008/admin" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - apisv1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -323,7 +323,7 @@ func setupCluster(t *testing.T, name string, namespaces ...string) *operatorHelp for _, namespace := range namespaces { operatorNamespace := &corev1.Namespace{ - ObjectMeta: apisv1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: namespace, }, }