Skip to content

Commit 6379348

Browse files
CLOUDP-138782: [Atlas CLI] Update cluster labelling when creating clusters via Atlas CLI (#1480)
1 parent e83480b commit 6379348

File tree

7 files changed

+43
-18
lines changed

7 files changed

+43
-18
lines changed

internal/cli/atlas/clusters/clusters.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ import (
2222
"github.com/mongodb/mongodb-atlas-cli/internal/cli/atlas/clusters/indexes"
2323
"github.com/mongodb/mongodb-atlas-cli/internal/cli/atlas/clusters/onlinearchive"
2424
"github.com/mongodb/mongodb-atlas-cli/internal/cli/atlas/search"
25+
"github.com/mongodb/mongodb-atlas-cli/internal/config"
2526
"github.com/spf13/cobra"
2627
atlas "go.mongodb.org/atlas/mongodbatlas"
2728
)
2829

30+
const (
31+
labelKey = "Infrastructure Tool"
32+
atlasCLILabelValue = "Atlas CLI"
33+
mongoCLILabelValue = "mongoCLI"
34+
)
35+
2936
// MongoCLIBuilder is to split "mongocli atlas clusters" and "atlas clusters".
3037
func MongoCLIBuilder() *cobra.Command {
3138
const use = "clusters"
@@ -87,6 +94,18 @@ func Builder() *cobra.Command {
8794
return cmd
8895
}
8996

97+
func NewCLILabel() atlas.Label {
98+
labelValue := atlasCLILabelValue
99+
if config.ToolName == config.MongoCLI {
100+
labelValue = mongoCLILabelValue
101+
}
102+
103+
return atlas.Label{
104+
Key: labelKey,
105+
Value: labelValue,
106+
}
107+
}
108+
90109
func AddLabel(out *atlas.AdvancedCluster, l atlas.Label) {
91110
if LabelExists(out.Labels, l) {
92111
return

internal/cli/atlas/clusters/create.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ const (
3838
atlasM2 = "M2"
3939
atlasM5 = "M5"
4040
zoneName = "Zone 1"
41-
labelKey = "Infrastructure Tool"
42-
labelValue = "mongoCLI"
4341
)
4442

4543
type CreateOpts struct {
@@ -100,10 +98,7 @@ func (opts *CreateOpts) newCluster() (*atlas.AdvancedCluster, error) {
10098
cluster.Name = opts.name
10199
}
102100

103-
AddLabel(cluster, atlas.Label{
104-
Key: labelKey,
105-
Value: labelValue,
106-
})
101+
AddLabel(cluster, NewCLILabel())
107102

108103
cluster.GroupID = opts.ConfigProjectID()
109104
return cluster, nil

internal/cli/atlas/clusters/update.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ func (opts *UpdateOpts) patchOpts(out *atlas.AdvancedCluster) {
9898
if opts.tier != "" {
9999
opts.addTierToAdvancedCluster(out)
100100
}
101-
AddLabel(out, atlas.Label{
102-
Key: labelKey,
103-
Value: labelValue,
104-
})
101+
102+
AddLabel(out, NewCLILabel())
105103
}
106104

107105
func (opts *UpdateOpts) addTierToAdvancedCluster(out *atlas.AdvancedCluster) {

internal/cli/atlas/clusters/upgrade.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ func (opts *UpgradeOpts) patchOpts(out *atlas.Cluster) {
101101
}
102102
}
103103
}
104-
AddLabelSharedCluster(out, atlas.Label{
105-
Key: labelKey,
106-
Value: labelValue,
107-
})
104+
105+
AddLabelSharedCluster(out, NewCLILabel())
108106
}
109107

110108
// mongocli atlas cluster(s) upgrade [clusterName] --projectId projectId [--tier M#] [--diskSizeGB N] [--mdbVersion].

internal/cli/atlas/quickstart/cluster_setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func (opts *Opts) newCluster() *atlas.AdvancedCluster {
103103
Name: opts.ClusterName,
104104
Labels: []atlas.Label{
105105
{
106-
Key: "Infrastructure Tool",
107-
Value: "MongoDB CLI Quickstart",
106+
Key: opts.LabelKey,
107+
Value: opts.LabelValue,
108108
},
109109
},
110110
}

internal/cli/atlas/quickstart/quick_start.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const (
9393
defaultRegionGCP = "US_EAST_4"
9494
defaultRegionAzure = "US_EAST_2"
9595
defaultRegionGov = "US_GOV_EAST_1"
96+
labelKey = "Infrastructure Tool"
97+
atlasCLILabelValue = "Atlas CLI Quickstart"
98+
mongoCLILabelValue = "MongoDB CLI Quickstart"
9699
)
97100

98101
type Opts struct {
@@ -110,6 +113,8 @@ type Opts struct {
110113
DBUsername string
111114
DBUserPassword string
112115
SampleDataJobID string
116+
LabelKey string
117+
LabelValue string
113118
SkipSampleData bool
114119
SkipMongosh bool
115120
defaultValue bool
@@ -143,9 +148,15 @@ func NewQuickstartFlow(qsOpts *Opts) Flow {
143148
}
144149

145150
func NewQuickstartOpts(loginOpts *auth.LoginOpts) *Opts {
151+
labelValue := atlasCLILabelValue
152+
if config.ToolName == config.MongoCLI {
153+
labelValue = mongoCLILabelValue
154+
}
146155
return &Opts{
147-
loginOpts: loginOpts,
148-
login: auth.NewLoginFlow(loginOpts),
156+
loginOpts: loginOpts,
157+
login: auth.NewLoginFlow(loginOpts),
158+
LabelKey: labelKey,
159+
LabelValue: labelValue,
149160
}
150161
}
151162

internal/cli/atlas/setup/setup_cmd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131

3232
const (
3333
withProfileMsg = `Run "atlas auth setup --profile <profile_name>" to create a new Atlas account on a new Atlas CLI profile.`
34+
labelKey = "Infrastructure Tool"
35+
labelValue = "Atlas CLI Setup"
3436
)
3537

3638
var errNeedsOrgAndProject = errors.New("please make sure to select or add an org and project to the profile: %s")
@@ -123,6 +125,8 @@ func (opts *Opts) PreRun(ctx context.Context) error {
123125
func Builder() *cobra.Command {
124126
loginOpts := auth.NewLoginOpts()
125127
qsOpts := quickstart.NewQuickstartOpts(loginOpts)
128+
qsOpts.LabelKey = labelKey
129+
qsOpts.LabelValue = labelValue
126130
opts := &Opts{
127131
register: auth.NewRegisterFlow(loginOpts),
128132
login: auth.NewLoginFlow(loginOpts),

0 commit comments

Comments
 (0)