Skip to content

Commit c22d9e0

Browse files
nammnfealebenpae
authored andcommitted
CLOUDP-298858 - add isEnterprise prop and detection for om/appdb (#4129)
# Summary - adds detection for opsmanager spec whether the related appdb is using an enterprise image ## Proof of Work - mostly relying on existing code ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you checked for release_note changes?
1 parent 3814f8d commit c22d9e0

File tree

6 files changed

+108
-36
lines changed

6 files changed

+108
-36
lines changed

controllers/operator/construct/appdb_construction.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,12 @@ func getOfficialImage(version string, annotations map[string]string) string {
478478
imageType = string(architectures.ImageTypeUBI8)
479479
}
480480

481-
imageURL := os.Getenv(construct.MongodbImageEnv)
482-
483481
if strings.HasSuffix(repoUrl, "/") {
484482
repoUrl = strings.TrimRight(repoUrl, "/")
485483
}
486484

487485
assumeOldFormat := envvar.ReadBool(util.MdbAppdbAssumeOldFormat)
488-
if strings.HasSuffix(imageURL, util.OfficialServerImageAppdbUrl) && !assumeOldFormat {
486+
if AppDBIsEnterpriseImage() && !assumeOldFormat {
489487
// 5.0.6-ent -> 5.0.6-ubi8
490488
if strings.HasSuffix(version, "-ent") {
491489
version = fmt.Sprintf("%s%s", strings.TrimSuffix(version, "ent"), imageType)
@@ -502,6 +500,7 @@ func getOfficialImage(version string, annotations map[string]string) string {
502500
}
503501

504502
mongoImageName := ContainerImage(construct.MongodbImageEnv, version, func() string {
503+
imageURL := os.Getenv(construct.MongodbImageEnv)
505504
return imageURL
506505
})
507506

@@ -512,6 +511,11 @@ func getOfficialImage(version string, annotations map[string]string) string {
512511
return fmt.Sprintf("%s/%s", repoUrl, mongoImageName)
513512
}
514513

514+
func AppDBIsEnterpriseImage() bool {
515+
imageURL := os.Getenv(construct.MongodbImageEnv)
516+
return strings.HasSuffix(imageURL, util.OfficialEnterpriseServerImageUrl)
517+
}
518+
515519
func containerImageModification(containerName string, image string, args []string) statefulset.Modification {
516520
return func(sts *appsv1.StatefulSet) {
517521
for i, c := range sts.Spec.Template.Spec.Containers {

controllers/operator/construct/database_construction.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"go.uber.org/zap"
1212
"k8s.io/utils/ptr"
1313

14+
"github.com/mongodb/mongodb-kubernetes-operator/controllers/construct"
1415
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/container"
1516
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/persistentvolumeclaim"
1617
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/podtemplatespec"
@@ -1177,3 +1178,13 @@ func ContainerImage(imageURLEnv string, version string, retrieveImageURL func()
11771178

11781179
return fmt.Sprintf("%s:%s", imageURL, version)
11791180
}
1181+
1182+
func DeploymentIsEnterpriseImage(annotations map[string]string) bool {
1183+
imageURL := ""
1184+
if architectures.IsRunningStaticArchitecture(annotations) {
1185+
imageURL = os.Getenv(construct.MongodbImageEnv)
1186+
} else {
1187+
imageURL = os.Getenv(util.NonStaticDatabaseEnterpriseImage)
1188+
}
1189+
return strings.Contains(imageURL, util.OfficialEnterpriseServerImageUrl)
1190+
}

controllers/operator/construct/database_construction_test.go

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func TestGetAppDBImage(t *testing.T) {
310310
want: "quay.io/mongodb/mongodb-enterprise-server:4.2.11-ubi8",
311311
setupEnvs: func(t *testing.T) {
312312
t.Setenv(construct.MongodbRepoUrl, "quay.io/mongodb")
313-
t.Setenv(construct.MongodbImageEnv, util.OfficialServerImageAppdbUrl)
313+
t.Setenv(construct.MongodbImageEnv, util.OfficialEnterpriseServerImageUrl)
314314
},
315315
},
316316
{
@@ -319,7 +319,7 @@ func TestGetAppDBImage(t *testing.T) {
319319
want: "quay.io/mongodb/mongodb-enterprise-server:4.2.11-ubi8",
320320
setupEnvs: func(t *testing.T) {
321321
t.Setenv(construct.MongodbRepoUrl, "quay.io/mongodb")
322-
t.Setenv(construct.MongodbImageEnv, util.OfficialServerImageAppdbUrl)
322+
t.Setenv(construct.MongodbImageEnv, util.OfficialEnterpriseServerImageUrl)
323323
},
324324
},
325325
{
@@ -328,7 +328,7 @@ func TestGetAppDBImage(t *testing.T) {
328328
want: "quay.io/mongodb/mongodb-enterprise-server:4.2.11-something",
329329
setupEnvs: func(t *testing.T) {
330330
t.Setenv(construct.MongodbRepoUrl, "quay.io/mongodb")
331-
t.Setenv(construct.MongodbImageEnv, util.OfficialServerImageAppdbUrl)
331+
t.Setenv(construct.MongodbImageEnv, util.OfficialEnterpriseServerImageUrl)
332332
},
333333
},
334334
{
@@ -337,7 +337,7 @@ func TestGetAppDBImage(t *testing.T) {
337337
want: "quay.io/mongodb/mongodb-enterprise-server:4.2.11-ubi8",
338338
setupEnvs: func(t *testing.T) {
339339
t.Setenv(construct.MongodbRepoUrl, "quay.io/mongodb")
340-
t.Setenv(construct.MongodbImageEnv, util.OfficialServerImageAppdbUrl)
340+
t.Setenv(construct.MongodbImageEnv, util.OfficialEnterpriseServerImageUrl)
341341
},
342342
},
343343
{
@@ -368,7 +368,7 @@ func TestGetAppDBImage(t *testing.T) {
368368
t.Setenv("RELATED_IMAGE_MONGODB_IMAGE_4_2_11_ubi8", "quay.io/mongodb/mongodb-enterprise-server:4.2.11-ubi8")
369369
t.Setenv("RELATED_IMAGE_MONGODB_IMAGE_4_2_11_ent", "quay.io/mongodb/mongodb-enterprise-server:4.2.11-ent")
370370
t.Setenv(construct.MongoDBImageType, "ubi8")
371-
t.Setenv(construct.MongodbImageEnv, util.OfficialServerImageAppdbUrl)
371+
t.Setenv(construct.MongodbImageEnv, util.OfficialEnterpriseServerImageUrl)
372372
t.Setenv(construct.MongodbRepoUrl, construct.OfficialMongodbRepoUrls[1])
373373
},
374374
},
@@ -388,7 +388,7 @@ func TestGetAppDBImage(t *testing.T) {
388388
want: "quay.io/mongodb/mongodb-enterprise-server:4.2.11-ent",
389389
setupEnvs: func(t *testing.T) {
390390
t.Setenv(construct.MongodbRepoUrl, "quay.io/mongodb")
391-
t.Setenv(construct.MongodbImageEnv, util.OfficialServerImageAppdbUrl)
391+
t.Setenv(construct.MongodbImageEnv, util.OfficialEnterpriseServerImageUrl)
392392
t.Setenv(util.MdbAppdbAssumeOldFormat, "true")
393393
},
394394
},
@@ -401,7 +401,7 @@ func TestGetAppDBImage(t *testing.T) {
401401
want: "quay.io/mongodb/mongodb-enterprise-server:4.2.11-ubi9",
402402
setupEnvs: func(t *testing.T) {
403403
t.Setenv(construct.MongodbRepoUrl, "quay.io/mongodb")
404-
t.Setenv(construct.MongodbImageEnv, util.OfficialServerImageAppdbUrl)
404+
t.Setenv(construct.MongodbImageEnv, util.OfficialEnterpriseServerImageUrl)
405405
},
406406
},
407407
{
@@ -413,7 +413,7 @@ func TestGetAppDBImage(t *testing.T) {
413413
want: "quay.io/mongodb/mongodb-enterprise-server:4.2.11-ubi9",
414414
setupEnvs: func(t *testing.T) {
415415
t.Setenv(construct.MongodbRepoUrl, "quay.io/mongodb")
416-
t.Setenv(construct.MongodbImageEnv, util.OfficialServerImageAppdbUrl)
416+
t.Setenv(construct.MongodbImageEnv, util.OfficialEnterpriseServerImageUrl)
417417
},
418418
},
419419
}
@@ -538,3 +538,54 @@ func TestGetAutomationLogEnvVars(t *testing.T) {
538538
assert.Contains(t, envVars, corev1.EnvVar{Name: LogFileAutomationAgentStderrEnv, Value: path.Join(util.PvcMountPathLogs, "automation-agent-stderr.log")})
539539
})
540540
}
541+
542+
func TestDeploymentIsEnterpriseImage(t *testing.T) {
543+
tests := []struct {
544+
name string
545+
isStatic bool // this sets the environment to be static
546+
envVarValue string // if static, we will set the respective environment variable to overwrite the used image
547+
expectedResult bool
548+
}{
549+
{
550+
name: "Static Architecture - Enterprise Image",
551+
envVarValue: "myregistry.com/mongo/mongodb-enterprise-server:latest",
552+
isStatic: true,
553+
expectedResult: true,
554+
},
555+
{
556+
name: "Non-Static Architecture - Enterprise Image",
557+
envVarValue: "myregistry.com/mongo/mongodb-enterprise-server:latest",
558+
isStatic: false,
559+
expectedResult: true,
560+
},
561+
{
562+
name: "Static Architecture - Community Image",
563+
envVarValue: "myregistry.com/mongo/mongodb-community-server:latest",
564+
isStatic: true,
565+
expectedResult: false,
566+
},
567+
{
568+
name: "Non-Static Architecture - Community Image",
569+
envVarValue: "myregistry.com/mongo/mongodb-community-server:latest",
570+
isStatic: false,
571+
expectedResult: false,
572+
},
573+
}
574+
575+
for _, tt := range tests {
576+
t.Run(tt.name, func(t *testing.T) {
577+
if tt.isStatic {
578+
t.Setenv(construct.MongodbImageEnv, tt.envVarValue)
579+
t.Setenv(architectures.DefaultEnvArchitecture, string(architectures.Static))
580+
} else {
581+
t.Setenv(util.NonStaticDatabaseEnterpriseImage, tt.envVarValue)
582+
}
583+
584+
result := DeploymentIsEnterpriseImage(map[string]string{})
585+
586+
if result != tt.expectedResult {
587+
t.Errorf("expected %v, got %v", tt.expectedResult, result)
588+
}
589+
})
590+
}
591+
}

pkg/telemetry/collector.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
mdbv1 "github.com/10gen/ops-manager-kubernetes/api/v1/mdb"
2121
mdbmultiv1 "github.com/10gen/ops-manager-kubernetes/api/v1/mdbmulti"
2222
omv1 "github.com/10gen/ops-manager-kubernetes/api/v1/om"
23+
"github.com/10gen/ops-manager-kubernetes/controllers/operator/construct"
2324
"github.com/10gen/ops-manager-kubernetes/pkg/util"
2425
"github.com/10gen/ops-manager-kubernetes/pkg/util/architectures"
2526
"github.com/10gen/ops-manager-kubernetes/pkg/util/env"
@@ -206,11 +207,12 @@ func getMdbEvents(ctx context.Context, operatorClusterClient kubeclient.Client,
206207
for _, item := range mdbList.Items {
207208
numberOfClustersUsed := getMaxNumberOfClustersSCIsDeployedOn(item)
208209
properties := DeploymentUsageSnapshotProperties{
209-
DeploymentUID: string(item.UID),
210-
OperatorID: operatorUUID,
211-
Architecture: architectures.GetArchitecture(item.Annotations),
212-
IsMultiCluster: item.Spec.IsMultiCluster(),
213-
Type: string(item.Spec.GetResourceType()),
210+
DeploymentUID: string(item.UID),
211+
OperatorID: operatorUUID,
212+
Architecture: architectures.GetArchitecture(item.Annotations),
213+
IsMultiCluster: item.Spec.IsMultiCluster(),
214+
Type: string(item.Spec.GetResourceType()),
215+
IsRunningEnterpriseImage: construct.DeploymentIsEnterpriseImage(item.Annotations),
214216
}
215217

216218
if numberOfClustersUsed > 0 {
@@ -233,12 +235,13 @@ func addMultiEvents(ctx context.Context, operatorClusterClient kubeclient.Client
233235
clusters := len(item.Spec.ClusterSpecList)
234236

235237
properties := DeploymentUsageSnapshotProperties{
236-
DatabaseClusters: ptr.To(clusters), // cannot be null in mdbmulti
237-
DeploymentUID: string(item.UID),
238-
OperatorID: operatorUUID,
239-
Architecture: architectures.GetArchitecture(item.Annotations),
240-
IsMultiCluster: true,
241-
Type: string(item.Spec.GetResourceType()),
238+
DatabaseClusters: ptr.To(clusters), // cannot be null in mdbmulti
239+
DeploymentUID: string(item.UID),
240+
OperatorID: operatorUUID,
241+
Architecture: architectures.GetArchitecture(item.Annotations),
242+
IsMultiCluster: true,
243+
Type: string(item.Spec.GetResourceType()),
244+
IsRunningEnterpriseImage: construct.DeploymentIsEnterpriseImage(item.Annotations),
242245
}
243246
events = append(events, addEvents(properties, events, now, Deployments)...)
244247
}
@@ -254,14 +257,16 @@ func addOmEvents(ctx context.Context, operatorClusterClient kubeclient.Client, o
254257
Logger.Warnf("failed to fetch OMList from Kubernetes: %v", err)
255258
} else {
256259
for _, item := range omList.Items {
260+
// Detect enterprise
257261
omClusters := len(item.Spec.ClusterSpecList)
258262
appDBClusters := len(item.Spec.AppDB.ClusterSpecList)
259263
properties := DeploymentUsageSnapshotProperties{
260-
DeploymentUID: string(item.UID),
261-
OperatorID: operatorUUID,
262-
Architecture: architectures.GetArchitecture(item.Annotations),
263-
IsMultiCluster: item.Spec.IsMultiCluster(),
264-
Type: "OpsManager",
264+
DeploymentUID: string(item.UID),
265+
OperatorID: operatorUUID,
266+
Architecture: architectures.GetArchitecture(item.Annotations),
267+
IsMultiCluster: item.Spec.IsMultiCluster(),
268+
Type: "OpsManager",
269+
IsRunningEnterpriseImage: construct.AppDBIsEnterpriseImage(),
265270
}
266271
if omClusters > 0 {
267272
properties.OmClusters = ptr.To(omClusters)

pkg/telemetry/types.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ type KubernetesClusterUsageSnapshotProperties struct {
2323

2424
// DeploymentUsageSnapshotProperties represents the structure for tracking Deployment events.
2525
type DeploymentUsageSnapshotProperties struct {
26-
DatabaseClusters *int `json:"databaseClusters,omitempty"` // pointers allow us to not send that value if it's not set.
27-
AppDBClusters *int `json:"appDBClusters,omitempty"`
28-
OmClusters *int `json:"OmClusters,omitempty"`
29-
DeploymentUID string `json:"deploymentUID"`
30-
OperatorID string `json:"operatorID"`
31-
Architecture string `json:"architecture"`
32-
IsMultiCluster bool `json:"isMultiCluster"`
33-
Type string `json:"type"` // RS, SC, OM, Single
26+
DatabaseClusters *int `json:"databaseClusters,omitempty"` // pointers allow us to not send that value if it's not set.
27+
AppDBClusters *int `json:"appDBClusters,omitempty"`
28+
OmClusters *int `json:"OmClusters,omitempty"`
29+
DeploymentUID string `json:"deploymentUID"`
30+
OperatorID string `json:"operatorID"`
31+
Architecture string `json:"architecture"`
32+
IsMultiCluster bool `json:"isMultiCluster"`
33+
Type string `json:"type"` // RS, SC, OM, Single
34+
IsRunningEnterpriseImage bool `json:"IsRunningEnterpriseImage"`
3435
}
3536

3637
type Event struct {

pkg/util/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ const (
295295

296296
DeprecatedImageAppdbUbiUrl = "mongodb-enterprise-appdb-database-ubi"
297297

298-
OfficialServerImageAppdbUrl = "mongodb-enterprise-server"
298+
OfficialEnterpriseServerImageUrl = "mongodb-enterprise-server"
299299

300300
MdbAppdbAssumeOldFormat = "MDB_APPDB_ASSUME_OLD_FORMAT"
301301

0 commit comments

Comments
 (0)