Skip to content

Commit 271d8a2

Browse files
authored
sync apply command with latest generate options (#54)
1 parent 608631b commit 271d8a2

File tree

9 files changed

+285
-177
lines changed

9 files changed

+285
-177
lines changed

docs/command/atlas-kubernetes-config-apply.txt

+8
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ Options
4141
- strings
4242
- false
4343
- One or more comma separated cluster names to import
44+
* - --dataFederationName
45+
- strings
46+
- false
47+
- One or more comma separated data federation names to import
4448
* - -h, --help
4549
-
4650
- false
4751
- help for apply
52+
* - --independentResources
53+
-
54+
- false
55+
- Flag that makes the generated resources that support independent usage, to use external IDs rather than Kubernetes references.
4856
* - --kubeContext
4957
- string
5058
- false

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
go.mongodb.org/atlas v0.37.0
2626
go.mongodb.org/atlas-sdk/v20240530005 v20240530005.0.0
2727
go.mongodb.org/atlas-sdk/v20241113004 v20241113004.0.0
28+
go.mongodb.org/atlas-sdk/v20250219001 v20250219001.1.0
2829
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
2930
gopkg.in/yaml.v3 v3.0.1
3031
k8s.io/api v0.32.3

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ go.mongodb.org/atlas-sdk/v20241113001 v20241113001.0.0 h1:G3UZcWwWziGUuaILWp/Gc+
259259
go.mongodb.org/atlas-sdk/v20241113001 v20241113001.0.0/go.mod h1:fMiUyCacIAm+XwFkJ4j+rJtYLRsGU7hButtgGv+SBU4=
260260
go.mongodb.org/atlas-sdk/v20241113004 v20241113004.0.0 h1:dmIp82dS4foajdKgcKRfr26g0cWE52jQAf+nbgFXr10=
261261
go.mongodb.org/atlas-sdk/v20241113004 v20241113004.0.0/go.mod h1:z6m7PcfItkgV3+mnLuStlTkdTbfUBQJpRyES8tuHNCk=
262+
go.mongodb.org/atlas-sdk/v20250219001 v20250219001.1.0 h1:tm7d3xvbNFIpuvFcppXc1zdpM/dO7HwivpA+Y4np3uQ=
263+
go.mongodb.org/atlas-sdk/v20250219001 v20250219001.1.0/go.mod h1:huR1gWJhExa60NIRhsLDdc7RmmqKJJwnbdlA1UUh8V4=
262264
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
263265
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
264266
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s=

internal/cli/kubernetes/config/apply.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ func (opts *ApplyOpts) Run() error {
105105
WithTargetOperatorVersion(opts.operatorVersion).
106106
WithSecretsData(true).
107107
WithFeatureValidator(atlasCRDs).
108-
WithPatcher(atlasCRDs)
108+
WithPatcher(atlasCRDs).
109+
WithDataFederationNames(opts.dataFederationName).
110+
WithIndependentResources(opts.independentResources)
109111
err = operator.NewConfigApply(
110112
operator.NewConfigApplyParams{
111113
OrgID: opts.OrgID,
@@ -169,6 +171,8 @@ func ApplyBuilder() *cobra.Command {
169171
flags.StringVar(&opts.operatorVersion, flag.OperatorVersion, "", usage.OperatorVersion)
170172
flags.StringVar(&opts.KubeConfig, flag.KubernetesClusterConfig, "", usage.KubernetesClusterConfig)
171173
flags.StringVar(&opts.KubeContext, flag.KubernetesClusterContext, "", usage.KubernetesClusterContext)
174+
flags.StringSliceVar(&opts.dataFederationName, flag.DataFederationName, []string{}, usage.ExporterDataFederationName)
175+
flags.BoolVar(&opts.independentResources, flag.IndependentResources, false, usage.IndependentResources)
172176

173177
return cmd
174178
}

internal/kubernetes/operator/config_apply.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ func (apply *ConfigApply) Run() error {
8484
return err
8585
}
8686

87-
sortedResources := sortResources(ProjectResources, DeploymentResources, streamsResources, apply.Version)
87+
dataFederationResources, err := apply.exporter.exportDataFederation(projectName)
88+
if err != nil {
89+
return err
90+
}
91+
92+
sortedResources := sortResources(ProjectResources, DeploymentResources, streamsResources, dataFederationResources, apply.Version)
8893

8994
for _, objects := range sortedResources {
9095
for _, object := range objects {
@@ -111,7 +116,7 @@ func (apply *ConfigApply) Run() error {
111116
}
112117

113118
func sortResources(
114-
projectResources, deploymentResources, streamsResources []runtime.Object,
119+
projectResources, deploymentResources, streamsResources, dataFederationResources []runtime.Object,
115120
version string,
116121
) [][]runtime.Object {
117122
resources, versionFound := features.GetResourcesForVersion(version)
@@ -167,5 +172,7 @@ func sortResources(
167172
}
168173
}
169174

175+
sortedResources[9] = append(sortedResources[9], dataFederationResources...)
176+
170177
return sortedResources
171178
}

scripts/atlas-binary.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set -Eeou pipefail
1818

1919
OS=$(uname -s)
2020
ARCH=$(uname -m)
21+
CLI_VERSION="1.41.0"
2122

2223
echo "==> Fetching AtlasCLI binary..."
2324
if ls ./test/bin/atlas* 1> /dev/null 2>&1; then
@@ -30,21 +31,21 @@ mkdir -p ./test/bin
3031

3132
if [ "$OS" = "Darwin" ]; then
3233
if [ "$ARCH" = "arm64" ]; then
33-
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_1.36.0_macos_arm64.zip -o ./test/bin/mongodb-atlas-cli.zip
34+
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_${CLI_VERSION}_macos_arm64.zip -o ./test/bin/mongodb-atlas-cli.zip
3435
elif [ "$ARCH" = "x86_64" ]; then
35-
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_1.36.0_macos_x86_64.zip -o ./test/bin/mongodb-atlas-cli.zip
36+
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_${CLI_VERSION}_macos_x86_64.zip -o ./test/bin/mongodb-atlas-cli.zip
3637
fi
3738
unzip -q ./test/bin/mongodb-atlas-cli.zip -d ./test/bin/tmp
3839
elif [ "$OS" = "Linux" ]; then
3940
if [ "$ARCH" = "x86_64" ]; then
40-
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_1.36.0_linux_x86_64.tar.gz -o ./test/bin/mongodb-atlas-cli.tar.gz
41+
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_${CLI_VERSION}_linux_x86_64.tar.gz -o ./test/bin/mongodb-atlas-cli.tar.gz
4142
elif [ "$ARCH" = "aarch64" ]; then
42-
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_1.36.0_linux_arm64.tar.gz -o ./test/bin/mongodb-atlas-cli.tar.gz
43+
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_${CLI_VERSION}_linux_arm64.tar.gz -o ./test/bin/mongodb-atlas-cli.tar.gz
4344
fi
4445
mkdir -p ./test/bin/tmp
4546
tar --strip-components=1 -xf ./test/bin/mongodb-atlas-cli.tar.gz -C ./test/bin/tmp
4647
elif [[ "$OS" =~ "MINGW" ]] || [[ "$OS" =~ "MSYS_NT" ]] || [[ "$OS" =~ "CYGWIN_NT" ]]; then
47-
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_1.36.0_windows_x86_64.zip -o ./test/bin/mongodb-atlas-cli.zip
48+
curl -L https://fastdl.mongodb.org/mongocli/mongodb-atlas-cli_${CLI_VERSION}_windows_x86_64.zip -o ./test/bin/mongodb-atlas-cli.zip
4849
unzip -q ./test/bin/mongodb-atlas-cli.zip -d ./test/bin/tmp
4950
else
5051
echo "Unsupported OS or architecture"

test/e2e/helper_test.go

+43-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ import (
3030
"github.com/mongodb/atlas-cli-plugin-kubernetes/internal/kubernetes/operator/resources"
3131
"github.com/mongodb/atlas-cli-plugin-kubernetes/internal/version"
3232
"github.com/mongodb/atlas-cli-plugin-kubernetes/test"
33+
akoapi "github.com/mongodb/mongodb-atlas-kubernetes/v2/api"
34+
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1"
35+
akov2common "github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/common"
36+
akov2status "github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/status"
3337
"github.com/stretchr/testify/assert"
3438
"github.com/stretchr/testify/require"
3539
atlasv2 "go.mongodb.org/atlas-sdk/v20241113004/admin"
40+
atlasv20250219001 "go.mongodb.org/atlas-sdk/v20250219001/admin"
3641
"go.mongodb.org/atlas/mongodbatlas"
42+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3743
)
3844

3945
const (
@@ -342,9 +348,6 @@ func RandProjectName() (string, error) {
342348
if err != nil {
343349
return "", err
344350
}
345-
if revision, ok := os.LookupEnv("revision"); ok {
346-
return fmt.Sprintf("%v-%s", n, revision), nil
347-
}
348351
return fmt.Sprintf("e2e-%v", n), nil
349352
}
350353

@@ -410,7 +413,7 @@ func getFirstOrgUser() (string, error) {
410413
return "", fmt.Errorf("%s (%w)", string(resp), err)
411414
}
412415

413-
var users atlasv2.PaginatedAppUser
416+
var users atlasv20250219001.PaginatedOrgUser
414417
if err := json.Unmarshal(resp, &users); err != nil {
415418
return "", fmt.Errorf("%w: %s", err, string(resp))
416419
}
@@ -827,3 +830,39 @@ func randomString(t *testing.T) string {
827830
}
828831
return fmt.Sprintf("%x", n)
829832
}
833+
834+
func referenceDataFederation(name, namespace, projectName string, labels map[string]string) *akov2.AtlasDataFederation {
835+
dictionary := resources.AtlasNameToKubernetesName()
836+
return &akov2.AtlasDataFederation{
837+
TypeMeta: metav1.TypeMeta{
838+
Kind: "AtlasDataFederation",
839+
APIVersion: "atlas.mongodb.com/v1",
840+
},
841+
ObjectMeta: metav1.ObjectMeta{
842+
Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-%s", projectName, name), dictionary),
843+
Namespace: namespace,
844+
Labels: labels,
845+
},
846+
Spec: akov2.DataFederationSpec{
847+
Project: akov2common.ResourceRefNamespaced{
848+
Name: resources.NormalizeAtlasName(projectName, dictionary),
849+
Namespace: namespace,
850+
},
851+
Name: name,
852+
CloudProviderConfig: &akov2.CloudProviderConfig{},
853+
DataProcessRegion: &akov2.DataProcessRegion{
854+
CloudProvider: "AWS",
855+
Region: "DUBLIN_IRL",
856+
},
857+
Storage: &akov2.Storage{
858+
Databases: nil,
859+
Stores: nil,
860+
},
861+
},
862+
Status: akov2status.DataFederationStatus{
863+
Common: akoapi.Common{
864+
Conditions: []akoapi.Condition{},
865+
},
866+
},
867+
}
868+
}

0 commit comments

Comments
 (0)